New code should be formatted using a linter #4055
Locked
DrPaulSharp
announced in
ADR
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Code Linting and Formatting using Ruff
Preamble
To ensure a consistent style of code throughout the SasView organization, we propose the use of a code linting tool to automatically run during the commit and pull request phases of development. Developers are further encouraged to make use of linting and formatting tools to identify and apply further fixes to aid code consistency.
Proposal
As part of the continuous integration process, an automated system should check the committed code and automatically make code edits based on a fixed set of rules. The rule set should be some subset of the PEP style guide and other such rulesets where automatic fixes are available. In addition, users should have access to a tool that they can use to check their code for violations of the rulesets that they can address locally. The suggested tools for this process are ruff and pre-commit.
Implementation on Github
pre-commithook that gates CI if any automatically fixable linting issues are found in new code, corrects and commits necessary changes, and restarts the CI post-commit.pre-commithook that will activate on a developers system, assuming the developer system is set up properly. This hook will prevent a local commit if any automatically fixable linting errors are found.rufftool for making changes, using a pre-defined set of rules.pyproject.toml.Implementation on developer system
ruffandpre-commitmust be added to therequirement-dev.txtfile to ensure developers' systems have the appropriate tools for use.python -m uv pip install -r requirement.txt -r requirements-dev.txt --updatepre-commithook should set it up usingpre-commit install. This only needs to be done once.Preferred usage
Implementation on developer system.python -m ruff check --fixandpython -m ruff formaton any files modified. Any warnings that cannot be automatically fixed should be manually corrected by the developer.ruff.python -m ruff formaton the set of files under consideration.Linting Ruleset
The full set of rules that could be applied are outlined in https://docs.astral.sh/ruff/rules/
Initially Enforced
key in dictinstead ofkey in dict.keys(): https://docs.astral.sh/ruff/rules/in-dict-keys/Initially Ignored
super()instead ofsuper(__class__, self)f"{value}"instead of"%s" % valueRevision Acceptance Date: 14th July 2026
Revision Number: 1
Original Suggestion: https://github.com/orgs/SasView/discussions/3171
All reactions