Skip to content

Commit 479a197

Browse files
author
Felix Exner (fexner)
authored
Use pre-commit for clang-format (#175)
It has bothered be for quite a while that we have so many "code formatting" commit inside our PRs. Using pre-commit enables us to check formatting **before** we actually push something.
1 parent e2bebd6 commit 479a197

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

.github/workflows/industrial-ci.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ name: ROS industrial ci
22
on: [push, pull_request]
33

44
jobs:
5-
format_check:
6-
runs-on: ubuntu-latest
7-
8-
steps:
9-
- uses: actions/checkout@v2
10-
- uses: 'ros-industrial/industrial_ci@master'
11-
env:
12-
ROS_DISTRO: melodic
13-
CLANG_FORMAT_CHECK: file
14-
CLANG_FORMAT_VERSION: "9"
15-
165
build:
176
runs-on: ubuntu-latest
187
strategy:

.github/workflows/pre-commit.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This is a format job. Pre-commit has a first-party GitHub action, so we use
2+
# that: https://github.com/pre-commit/action
3+
4+
name: pre-commit
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
push:
10+
branches:
11+
- main
12+
13+
jobs:
14+
pre-commit:
15+
name: pre-commit
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version: 3.10.4
22+
- name: Install system hooks
23+
run: sudo apt-get install clang-format-14 cppcheck
24+
- uses: pre-commit/[email protected]
25+
with:
26+
extra_args: --all-files --hook-stage manual
27+

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: 'v14.0.6'
4+
hooks:
5+
- id: clang-format

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ int main(int argc, char* argv[])
381381
}
382382
```
383383
384+
## Contributor Guidelines
385+
* This repo supports [pre-commit](https://pre-commit.com/) e.g. for automatic code formatting. TLDR:
386+
This will prevent you from committing falsely formatted code:
387+
```
388+
pipx install pre-commit
389+
pre-commit install
390+
```
391+
* Succeeding pipelines are a must on Pull Requests (unless there is a reason, e.g. when there have
392+
been upstream changes).
393+
* We try to increase and keep our code coverage high, so PRs with new
394+
features should also have tests covering them.
395+
* Parameters of public methods must all be documented.
396+
384397
## Acknowledgment
385398
Many parts of this library are forked from the [ur_modern_driver](https://github.com/ros-industrial/ur_modern_driver).
386399

0 commit comments

Comments
 (0)