Skip to content

Large code refactor to enable a bunch of additional ruff rulesets #1421

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

Merged
merged 79 commits into from
May 24, 2025

Conversation

tleonhardt
Copy link
Member

@tleonhardt tleonhardt commented May 23, 2025

Summary

I enabled a bunch of additional ruff rulesets for our automated linting checks.

In the process, I also ignored certain specific rules overall and other rules in certain files or directories.

The intent is to leave code a little bit cleaner and a little bit more modern and idiomatic as well as to make it easy for new contributors to comply with good best practices. The majority of the changes outside of pyproject.toml and Makefile were automated refactoring done by ruff.

Details

Ruff Rules are documented here.

Previously enabled and still enabled rulesets (untouched)

Enabled ruff rulesets (compared to before this PR)

Disabled by this PR because they are for frameworks cmd2 doesn't use

  • AIR - Airflow
  • DJ - Django
  • FAST - FastAPI
  • NPY - NumPy
  • PD - Pandas

Still disabled ruff rulesets

Rules that would probably be good to eventually enable

  • ANN - flake8-annotations
  • ARG - flake8-unused-arguments
  • D - pydocstyle (very low priority)
  • PTH - flake8-use-pathlib (low priority)
  • RUF - Ruff-specific rules
  • SIM- flake8-simplify
  • SLF - flake8-self
  • TRY - tryceratops (low priority)

Rules we might want to enable once they are out of preview

  • DOC - pydoclint (ruff preview not fully released)

Rules we probably never want to enable

  • B - flake8-bugbear (too many false positives)
  • CPY - flake8-copyright (no need to force a copyright message at top of every file)
  • EM - flake8-errmsg (no need to force setting local variable before throwing exception)
  • FBT - flake8-boolean-trap (forces all boolean parameters to be passed by keyword and not position)
  • PLR - Pylint Refactor (too many false positives)
  • T20 - flake8-print (cmd2 uses print directly under the hood)

tleonhardt added 21 commits May 22, 2025 18:47
@tleonhardt tleonhardt self-assigned this May 23, 2025
@tleonhardt tleonhardt added this to the 2.6.0 milestone May 23, 2025
… list

This rule forced every use of typing inside a cast to be quoted. In reality, it is only forward reference types which needed this.
tleonhardt added 26 commits May 24, 2025 02:06
Strategically disabled on various lines in cmd2 code where we are using subprocess.Popen() in a way it doesn't like as well as when we are using asserts intentionally like in transcript testing.
…e it clear they are intended for internal use only
@tleonhardt
Copy link
Member Author

I'm going to merge this in and start working on doing the merge to the 3.0.0 branch.

@tleonhardt tleonhardt merged commit 3eccbec into master May 24, 2025
47 checks passed
@tleonhardt tleonhardt deleted the ruff-refactoring branch May 24, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant