This repo contains a (C++, python) linter and auto formatter package that can be conveniently installed into your repositories using git hooks. It provides the following git hooks:
-
General
- Prevent commits to master.
-
C++ files:
-
- clang-format Formats your code based on your
.clang-format
preferences. - cpplint Checks your C++ code for style errors and warnings.
- clang-format Formats your code based on your
-
Python files:
- yapf Formats your python code.
- pylint Checks your Python code for style errors and warnings.
- pylint
- macOS:
pip install pylint
- macOS:
- yapf
- Ubuntu / macOS:
pip install yapf
- Ubuntu / macOS:
- clang-format
- Compatible with
clang-format-3.8 - 6.0
- Ubuntu:
sudo apt install clang-format-${VERSION}
- macOS:
brew install clang-format ln -s /usr/local/share/clang/clang-format-diff.py /usr/local/bin/clang-format-diff
- Compatible with
- requests
- Ubuntu:
pip install requests
- Ubuntu:
git clone git@github.com:ethz-asl/linter.git
cd linter
echo ". $(realpath setup_linter.sh)" >> ~/.bashrc # Or the matching file for
# your shell.
bash
Then you can install the linter in your repository:
cd $YOUR_REPO
init_linter_git_hooks
To remove the linter from your git repository again, run the following:
cd $YOUR_REPO
init_linter_git_hooks --remove
General
To configure the linter, add a file named .linterconfig.yaml
in your repository root. An example file is given under linterconfig.yaml_example
.
C++
clang-format can be configured by defining a project-specific C++ format by adding a file .clang-format
to your projects root folder. Example file:
---
Language: Cpp
BasedOnStyle: Google
DerivePointerAlignment: false
PointerAlignment: Left
ColumnLimit: 80
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlignAfterOpenBracket: AlwaysBreak
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '.*'
Priority: 2
...
Python
Currently there it is not possible to configure the python formatter on a per-repository basis. The linter can be configured on a per-repository bais by adding a .pylintrc
file to your repositorie's root folder.
-
C++ Linter (
cpplint
):void your_awful_function(int & result) // NOLINT
-
C++ Formatting (
clang-format
):// clang-format off ... // clang-format on
-
Python Linter (
pylint
)For whole file:
#!/usr/bin/env python # pylint: disable=C0103,E1101 ...
For a line:
your_awful_function('-legal/copyright,-build/c++11') # pylint: disable=W0212
The full list of pylint warnings and errors can be found here
-
Python Formatting (
yapf
)# yapf: disable ... # yapf: enable
-
Checking an entire repository
Type
linter_check_all
to run the linters and formatters on all files within the current repository.