Skip to content

Introduce more Ruff linter rules (Python) - #3910

Merged
nycrat merged 7 commits into
UBC-Thunderbots:masterfrom
nycrat:avah/more_ruff_linting
Sep 5, 2026
Merged

Introduce more Ruff linter rules (Python)#3910
nycrat merged 7 commits into
UBC-Thunderbots:masterfrom
nycrat:avah/more_ruff_linting

Conversation

@nycrat

@nycrat nycrat commented Sep 1, 2026

Copy link
Copy Markdown
Member

Description

This PR enables actually checking for the default linter rules defined by ruff: https://docs.astral.sh/ruff/default-rules/. In addition, a pyproject.toml is added to configure this linter. Currently, the only extra rules are added for checking wildcard imports, and sorting imports automatically. In the future, we may want to extend more rules to enforce a more strict code style.

Note

The D rules regarding documentation style have now been turned off. Originally lint_and_format would lint but not return any errors even if our code did not fit the style. As a result, we have accumulated exactly 2586 lint errors when applying the D rules. Cleaning up our current docs should be done in another PR in my opinion.

Testing Done

Ran test suite and all tests still pass. Thunderscope also behaves the same.

Resolved Issues

resolves #3894, resolves #3681

Length Justification and Key Files to Review

Look at lint_and_format.sh and pyproject.toml for my manual changes. Most of the other changes are automatically applied by the linter.

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

@nycrat
nycrat force-pushed the avah/more_ruff_linting branch from 1e00074 to 001edbe Compare September 1, 2026 05:01
@GrayHoang

Copy link
Copy Markdown
Contributor

is there a way to separate what got changed by linter and what you changed in settings?

@nycrat
nycrat force-pushed the avah/more_ruff_linting branch 4 times, most recently from 6959b86 to d75df62 Compare September 1, 2026 05:49
@nycrat

nycrat commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

is there a way to separate what got changed by linter and what you changed in settings?

There's the auto linter fixes and manual fixes cause some rules don't have auto fixes. But settings changes are all in pyproject.toml

@nycrat

nycrat commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

I might reduce the scope of this PR actually. There would be way too many merge conflicts and too difficult to review this PR if we actually try to turn on all the linter rules all at once.

@nycrat
nycrat force-pushed the avah/more_ruff_linting branch from 6f35a7b to cb3cc83 Compare September 1, 2026 15:49
@nycrat
nycrat marked this pull request as ready for review September 1, 2026 16:08

@StarrryNight StarrryNight left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a small comment. Other changes lGTM

resource = creator()
except tbots_cpp.TbotsNetworkException as error:
logger.error(f"Error setting up robot status interface:\n{error}")
is_setup_successfully = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this deleted?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completely unused variable 😆

@nycrat
nycrat requested a review from StarrryNight September 3, 2026 01:31
@nycrat
nycrat merged commit 83fe79a into UBC-Thunderbots:master Sep 5, 2026
9 checks passed
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.

Implement Ruff Linting Rules Automatically organize Python imports in lint_and_format.sh

4 participants