Read-only mirror of https://github.com/ethz-asl/linter — ETHZ ASL. Issues & pull requests at the source.
  • Python 99.9%
  • Shell 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
lbern cb070ec305
Merge pull request #40 from ethz-asl/hotfix/readme
Add Missing Dependency To ReadMe
2022-07-06 09:26:15 -04:00
bin more ports to py3 2022-07-05 17:44:54 +02:00
default Reverse docstring related changes for PR to upstream 2019-06-01 13:33:29 -04:00
.gitignore ignore pyc files 2017-04-28 20:04:08 +02:00
ascii_art.py Update ascii_art.py 2019-12-19 15:06:40 +01:00
git_hooks.py more ports to py3 2022-07-05 17:44:54 +02:00
LICENSE Add LICENSE 2017-08-03 13:44:44 +02:00
linter.py more ports to py3 2022-07-05 17:44:54 +02:00
linterconfig.yaml_example Addressed comments by @mfehr 2019-06-05 11:16:34 -04:00
README.md added requests install to readme 2022-07-06 14:25:48 +02:00
setup_linter.sh Fix linter path for bash 2018-05-30 13:57:06 +02:00

linter

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.
  • Python files:

    • yapf Formats your python code.
    • pylint Checks your Python code for style errors and warnings.

Dependencies

  • pylint
    • macOS:
      pip install pylint
      
  • yapf
    • Ubuntu / macOS: pip install yapf
  • 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
      
  • requests
    • Ubuntu:
      pip install requests
      

Installation

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

Uninstallation

To remove the linter from your git repository again, run the following:

cd $YOUR_REPO
init_linter_git_hooks --remove

Linter configuration

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.

Disable Linter Functionalities for a Specific Line

  • 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
    

Tools

  • Checking an entire repository

    Type linter_check_all to run the linters and formatters on all files within the current repository.

ASCII-Art Sources