-
Notifications
You must be signed in to change notification settings - Fork 12
Add pre-commit for better linting #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Greptile OverviewGreptile SummaryThis PR adds a comprehensive pre-commit configuration that automates code quality checks, formatting, and validation across the codebase. The configuration includes Python formatting (autopep8/flake8), C++ formatting (uncrustify), shell script formatting (shfmt), copyright checks, YAML validation, and sign-off verification. Major changes:
Issues identified:
Previous issues resolved:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Git as Git Commit
participant PreCommit as Pre-commit Hooks
participant CI as GitHub Actions
participant Build as Build System
Dev->>Git: git commit -s -m "message"
Git->>PreCommit: Trigger pre-commit hooks
PreCommit->>PreCommit: Run check-yaml
PreCommit->>PreCommit: Run end-of-file-fixer
PreCommit->>PreCommit: Run trailing-whitespace
PreCommit->>PreCommit: Run autopep8 (Python formatting)
PreCommit->>PreCommit: Run flake8 (Python linting)
PreCommit->>PreCommit: Run shfmt (Shell formatting)
PreCommit->>PreCommit: Run uncrustify (C++ formatting)
PreCommit->>PreCommit: Run copyright-required
PreCommit->>PreCommit: Run codespell
PreCommit->>PreCommit: Check signed-off-by in commit msg
alt Hooks Pass
PreCommit-->>Git: Success
Git-->>Dev: Commit created
Dev->>CI: Push to GitHub
CI->>PreCommit: Run pre-commit --all-files
CI->>Build: Build and test packages
Build-->>CI: Tests pass
else Hooks Fail
PreCommit-->>Git: Failure (auto-fix applied)
Git-->>Dev: Changes staged, retry commit
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
23 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
23 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
23 files reviewed, 4 comments
| should_redraw = ( | ||
| key != - | ||
| 1) or ( | ||
| current_time - | ||
| last_redraw >= redraw_interval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Autopep8 broke this expression by splitting -1 across lines. key != - on one line and 1) on the next is incorrect formatting.
| should_redraw = ( | |
| key != - | |
| 1) or ( | |
| current_time - | |
| last_redraw >= redraw_interval) | |
| should_redraw = (key != -1) or (current_time - last_redraw >= redraw_interval) |
| header = ( | ||
| f'{ | ||
| "Topic Name":<{MAX_NAME_WIDTH}} { | ||
| "Status":<{STATUS_WIDTH}} ' f'{ | ||
| "Pub Rate (Hz)":<{FRAME_RATE_WIDTH}} ' f'{ | ||
| "Latency (ms)":<{REALTIME_DELAY_WIDTH}} { | ||
| "Expected Hz":<12}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: F-string formatting is broken. Line breaks inside the f-string placeholders create invalid syntax.
| header = ( | |
| f'{ | |
| "Topic Name":<{MAX_NAME_WIDTH}} { | |
| "Status":<{STATUS_WIDTH}} ' f'{ | |
| "Pub Rate (Hz)":<{FRAME_RATE_WIDTH}} ' f'{ | |
| "Latency (ms)":<{REALTIME_DELAY_WIDTH}} { | |
| "Expected Hz":<12}') | |
| header = (f'{"Topic Name":<{MAX_NAME_WIDTH}} {"Status":<{STATUS_WIDTH}} ' | |
| f'{"Pub Rate (Hz)":<{FRAME_RATE_WIDTH}} ' | |
| f'{"Latency (ms)":<{REALTIME_DELAY_WIDTH}} {"Expected Hz":<12}') |
| topic_set = { | ||
| topic_name for topic_name, | ||
| topic_type in topic_names_and_types} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Set comprehension incorrectly split. The comma between topic_name and topic_type should be on the same line.
| topic_set = { | |
| topic_name for topic_name, | |
| topic_type in topic_names_and_types} | |
| topic_set = {topic_name for topic_name, topic_type in topic_names_and_types} |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
.pre-commit-config.yaml
Outdated
| - id: autopep8 | ||
| args: [-i, -a, -a] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The -a -a flags make autopep8 very aggressive, causing the broken formatting in ncurses_frontend.py. Consider using just -i or single -a to avoid overly aggressive line breaking.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
8b43cc2 to
ac97d27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
993b9ef to
a016e5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
Signed-off-by: Blake McHale <bmchale@nvidia.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 3 comments
| - name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.) | ||
| run: | | ||
| apt update && apt install -y pipx git | ||
| pipx install pre-commit | ||
| pipx ensurepath | ||
| source ~/.bashrc | ||
| pre-commit run --all-files --show-diff-on-failure | ||
| shell: bash | ||
| working-directory: greenwave_monitor | ||
| env: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-commit runs in wrong directory. Code is checked out to greenwave_monitor/ subdirectory (line 56) but this step doesn't cd into it before running pre-commit.
| - name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.) | |
| run: | | |
| apt update && apt install -y pipx git | |
| pipx install pre-commit | |
| pipx ensurepath | |
| source ~/.bashrc | |
| pre-commit run --all-files --show-diff-on-failure | |
| shell: bash | |
| working-directory: greenwave_monitor | |
| env: | |
| - name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.) | |
| run: | | |
| cd greenwave_monitor | |
| apt update && apt install -y pipx git | |
| pipx install pre-commit | |
| pipx ensurepath | |
| source ~/.bashrc | |
| pre-commit run --all-files --show-diff-on-failure | |
| shell: bash | |
| env: | |
| DEBIAN_FRONTEND: noninteractive |
| pre-commit run --all-files # try it out, this will run every commit now | ||
| ``` | ||
|
|
||
| Every commit now a series of checks will be run to ensure the changes are meeting this repositories requirements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar: missing verb. Should be "Every commit now, a series" or "On every commit now a series"
| Every commit now a series of checks will be run to ensure the changes are meeting this repositories requirements. | |
| On every commit now a series of checks will be run to ensure the changes are meeting this repositories requirements. |
|
|
||
| - name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.) | ||
| run: | | ||
| apt update && apt install -y pipx git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uncrustify dependency missing. Pre-commit config uses uncrustify (line 46 of .pre-commit-config.yaml) but it's not installed here. Contributing.md also mentions it's required.
| apt update && apt install -y pipx git | |
| apt update && apt install -y pipx git uncrustify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 2 comments
|
|
||
| - name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.) | ||
| run: | | ||
| apt update && apt install -y pipx git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uncrustify is required by the pre-commit config (line 46 of .pre-commit-config.yaml) but isn't installed here. Add it to the apt install command.
| apt update && apt install -y pipx git | |
| apt update && apt install -y pipx git uncrustify |
| pre-commit run --all-files # try it out, this will run every commit now | ||
| ``` | ||
|
|
||
| Every commit now a series of checks will be run to ensure the changes are meeting this repositories requirements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar issue: missing verb or incorrect structure. Should be "On every commit now, a series" or "Every commit now runs a series"
| Every commit now a series of checks will be run to ensure the changes are meeting this repositories requirements. | |
| On every commit now a series of checks will be run to ensure the changes are meeting this repositories requirements. |
Adds a pre-commit config that uses uncrustify and flake8 just like ament. ament isn't used directly since I wanted formatting to occur outside of a ROS environment when making small fixes. Also has other tools like whitespace, newline, copyright, yaml checks, code spelling, and shell script formatting.
Useful for fixing most issues with linting before it is pushed. Automatically reformats your commits, fixes copyright year issues, etc.
To run: