Replace flake8 with ruff for linting#203
Conversation
Co-authored-by: beniroquai <4345528+beniroquai@users.noreply.github.com>
Co-authored-by: beniroquai <4345528+beniroquai@users.noreply.github.com>
Co-authored-by: beniroquai <4345528+beniroquai@users.noreply.github.com>
Co-authored-by: beniroquai <4345528+beniroquai@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates the project's linting infrastructure from flake8 to ruff, modernizing the tooling while maintaining equivalent rule coverage. The migration includes configuration transfer, CI workflow updates, and cleanup of deprecated files.
Key Changes:
- Migrated all flake8 configuration settings to ruff in
pyproject.toml(line length, complexity, exclusions, per-file ignores) - Updated GitHub Actions workflow to use ruff instead of flake8 for linting checks
- Removed the
.flake8configuration file as it's no longer needed
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pyproject.toml | Added [tool.ruff] configuration with equivalent settings from .flake8 including exclusions, line length (100), complexity (10), and rule selection |
| .github/workflows/imswitch-test.yml | Updated CI workflow to install and run ruff with critical error checks and full linting with warnings |
| .flake8 | Removed deprecated flake8 configuration file |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| per-file-ignores = {"__init__.py" = ["F401"]} | ||
|
|
There was a problem hiding this comment.
The per-file-ignores syntax is incorrect for TOML. The current syntax uses {"__init__.py" = ["F401"]} which is not valid TOML. The correct syntax should be "__init__.py" = ["F401"] (without the curly braces) or use the inline table syntax with commas. Ruff expects this to be a table/mapping, not a dict-within-a-dict.
| per-file-ignores = {"__init__.py" = ["F401"]} | |
| [tool.ruff.lint.per-file-ignores] | |
| "__init__.py" = ["F401"] |
| # F821-F823: Undefined names (most critical Pyflakes errors) | ||
| ruff check . --select=E9,F821,F822,F823 --output-format=full |
There was a problem hiding this comment.
The rule selection may be too narrow. The original flake8 command used --select=E9,F63,F7,F82 which selected all codes starting with those prefixes (e.g., F63 includes F630-F639, F7 includes F700-F799, F82 includes F820-F829). The new command only selects F821,F822,F823, potentially missing other critical errors like F631 (assert tuple), F701 (break outside loop), F702 (continue outside loop), F704 (yield outside function), and others. Consider using a broader selection like --select=E9,F63,F7,F82 which ruff also supports, or explicitly add the important F6xx and F7xx codes.
| # F821-F823: Undefined names (most critical Pyflakes errors) | |
| ruff check . --select=E9,F821,F822,F823 --output-format=full | |
| # F63, F7, F82: Critical Pyflakes errors (e.g., assert tuple, break/continue/yield outside loop/function, etc.) | |
| ruff check . --select=E9,F63,F7,F82 --output-format=full |
Migrates code linting from flake8 to ruff as requested.
Changes
[tool.ruff]section topyproject.tomlwith equivalent settings from.flake8(line length 100, complexity 10, excluded directories, per-file ignores)imswitch-test.ymlto install and run ruff instead of flake8ruff check . --select=E9,F821,F822,F823(syntax errors and undefined names, fails build)ruff check . --exit-zero(all configured rules as warnings).flake8configuration fileRule Selection
The original flake8 command used
--select=E9,F63,F7,F82which are flake8-specific prefixes. Ruff uses explicit codes:E9: Syntax errors (E902-E999)F821-F823: Undefined names, unassigned local variablesThe second ruff check runs all configured rules (E, F, W, C90) with
--exit-zeroto catch remaining issues as warnings.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.