Skip to content

Conversation

@bmchalenv
Copy link
Contributor

@bmchalenv bmchalenv commented Jan 14, 2026

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:

sudo apt install uncrustify pipx
pipx install pre-commit
pre-commit run --all-files  # will also run on every commit now

@greptile-apps
Copy link

greptile-apps bot commented Jan 14, 2026

Greptile Overview

Greptile Summary

This 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:

  • Added .pre-commit-config.yaml with 9 hooks for linting and formatting
  • Integrated pre-commit checks into CI workflow (.github/workflows/ros-tests.yml)
  • Updated Contributing.md with pre-commit installation instructions
  • Applied automated formatting to all files (copyright years updated to 2025-2026, whitespace fixes, shell scripts reformatted with tabs)

Issues identified:

  • CI workflow is missing uncrustify installation, which will cause pre-commit to fail in GitHub Actions
  • Minor grammar issue in Contributing.md documentation

Previous issues resolved:

  • Fixed: package.xml no longer has duplicate XML declarations
  • Fixed: Python formatting issues from aggressive autopep8 have been corrected (changed from -a -a to -i)
  • Fixed: Pre-commit now runs in correct working directory

Confidence Score: 3/5

  • Mostly safe to merge, but CI will fail without uncrustify installation fix
  • The pre-commit configuration itself is well-structured and addresses code quality concerns. Most formatting issues from previous review rounds have been fixed. However, the missing uncrustify dependency in the CI workflow will cause GitHub Actions to fail, making this a blocking issue that must be resolved before merge.
  • .github/workflows/ros-tests.yml requires uncrustify to be added to apt install command on line 60

Important Files Changed

Filename Overview
.pre-commit-config.yaml Adds comprehensive pre-commit configuration with linting, formatting, and validation hooks
.github/workflows/ros-tests.yml Integrates pre-commit checks into CI workflow, missing uncrustify installation
Contributing.md Adds pre-commit setup instructions with grammar issue in last sentence

Sequence Diagram

sequenceDiagram
    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
Loading

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Comment on lines 179 to 183
should_redraw = (
key != -
1) or (
current_time -
last_redraw >= redraw_interval)
Copy link

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.

Suggested change
should_redraw = (
key != -
1) or (
current_time -
last_redraw >= redraw_interval)
should_redraw = (key != -1) or (current_time - last_redraw >= redraw_interval)

Comment on lines 211 to 217
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}')
Copy link

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.

Suggested change
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}')

Comment on lines 87 to 89
topic_set = {
topic_name for topic_name,
topic_type in topic_names_and_types}
Copy link

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.

Suggested change
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!

Comment on lines 26 to 27
- id: autopep8
args: [-i, -a, -a]
Copy link

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>
Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

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>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Comment on lines 58 to 67
- 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:
Copy link

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.

Suggested change
- 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.
Copy link

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"

Suggested change
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
Copy link

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.

Suggested change
apt update && apt install -y pipx git
apt update && apt install -y pipx git uncrustify

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Signed-off-by: Blake McHale <bmchale@nvidia.com>
Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile


- name: Run pre-commit hooks (linting, sign-off check, copyright check, etc.)
run: |
apt update && apt install -y pipx git
Copy link

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.

Suggested change
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.
Copy link

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"

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant