-
Notifications
You must be signed in to change notification settings - Fork 9
fix(lint-configs): Add /**/ to ruff.lint.per-file-ignores pattern to allow it to be extended (fixes #97); Consolidate ruff configuration by extending the shared config.
#98
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
Conversation
… to allow it to be extended (fixes y-scope#97); Consolidate ruff configuration by extending the shared config.
WalkthroughUpdates Python linting configuration to support extended configs across projects. Modifies the Ruff per-file-ignores pattern to match test directories at any depth, documents integration methods in README, and consolidates ystdlib-py's Ruff config to extend the shared configuration file. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
exports/lint-configs/python/README.md(1 hunks)exports/lint-configs/python/ruff.toml(1 hunks)exports/ystdlib-py/pyproject.toml(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-06-08T16:54:50.714Z
Learnt from: davidlion
Repo: y-scope/yscope-dev-utils PR: 60
File: exports/lint-configs/python/ruff.toml:23-23
Timestamp: 2025-06-08T16:54:50.714Z
Learning: Ruff uses hyphens (not underscores) for isort configuration keys. For example, `isort.order-by-type` is correct, not `isort.order_by_type`. Always verify against the official Ruff documentation at https://docs.astral.sh/ruff/settings/
Applied to files:
exports/lint-configs/python/ruff.tomlexports/ystdlib-py/pyproject.toml
📚 Learning: 2025-06-08T16:54:50.714Z
Learnt from: davidlion
Repo: y-scope/yscope-dev-utils PR: 60
File: exports/lint-configs/python/ruff.toml:23-23
Timestamp: 2025-06-08T16:54:50.714Z
Learning: Ruff configuration uses hyphens for isort settings keys (e.g., `isort.order-by-type`), not underscores (e.g., `isort.order_by_type`). Always verify against the official Ruff documentation at https://docs.astral.sh/ruff/settings/
Applied to files:
exports/lint-configs/python/ruff.tomlexports/ystdlib-py/pyproject.toml
📚 Learning: 2025-06-08T17:04:50.095Z
Learnt from: davidlion
Repo: y-scope/yscope-dev-utils PR: 60
File: taskfiles/lint/python.yaml:15-20
Timestamp: 2025-06-08T17:04:50.095Z
Learning: In Ruff, the `--fix` flag is used specifically with `ruff check` to automatically fix linting violations. The `ruff format` command formats code by default and does not require a `--fix` flag. When configuring taskfiles, `RUFF_CHECK_FLAGS: "--fix"` is the correct way to enable auto-fixing for linting issues.
Applied to files:
exports/ystdlib-py/pyproject.toml
📚 Learning: 2025-06-08T17:04:50.095Z
Learnt from: davidlion
Repo: y-scope/yscope-dev-utils PR: 60
File: taskfiles/lint/python.yaml:15-20
Timestamp: 2025-06-08T17:04:50.095Z
Learning: The `--fix` flag is used with `ruff check` to automatically fix linting issues, while `ruff format` formats files by default without needing a `--fix` flag. In the context of taskfiles, `RUFF_CHECK_FLAGS: "--fix"` is the correct way to enable auto-fixing for the `ruff check` command.
Applied to files:
exports/ystdlib-py/pyproject.toml
🔇 Additional comments (2)
exports/lint-configs/python/README.md (2)
6-17: Documentation is clear and well-structured.The "Integration Methods" section properly documents the difference between Ruff (which supports
extend) and Mypy (which requires copying). The example path is appropriately generic with a placeholder. The reference to ystdlib-py/pyproject.toml as a concrete example is helpful and the relative path../../ystdlib-py/pyproject.tomlshould resolve correctly from the README location.
19-22: Mypy documentation accurately conveys the configuration requirement.The note correctly explains that Mypy does not support extending external configurations and provides clear instructions for users. No concerns identified.
|
|
||
| [lint.per-file-ignores] | ||
| "tests/**" = [ | ||
| "/**/tests/**" = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify Ruff glob pattern syntax for per-file-ignores with leading /**/.
The pattern change from "tests/**" to "/**/tests/**" is intended to match test directories at any project depth when this config is extended. However, I need to confirm that Ruff supports glob patterns starting with /**/ and that this syntax produces the expected behaviour when used with the extend directive.
🌐 Web query:
Does Ruff support glob patterns starting with /**/ in per-file-ignores configuration?
💡 Result:
Short answer: No — use "/" not "//". Ruff's per-file-ignores use the Rust globset-style globs (which support patterns that start with "/"), but patterns with a leading slash ("//…") are not the supported form; write "**/path" (or project-relative paths) instead. [1][2][3]
Sources:
- Ruff configuration (per-file-ignores) docs. [1]
- globset glob syntax (explains "**/" behavior). [2]
- Ruff issue noting pattern-syntax differences and glob behavior. [3]
Correct the glob pattern syntax in per-file-ignores; use "**/tests/**" instead of "/**/tests/**".
Ruff's per-file-ignores use Rust globset-style globs which support **/ patterns but not the leading-slash form /**/. The correct syntax is **/path or project-relative paths. Change line 29 from "/**/tests/**" to "**/tests/**" to match test directories at any depth when this config is extended.
🤖 Prompt for AI Agents
In exports/lint-configs/python/ruff.toml around line 29, the per-file-ignores
glob uses a leading-slash form "/**/tests/**" which Ruff's globset does not
accept; replace it with the correct Rust globset-style pattern "**/tests/**" so
test directories are matched at any depth (update the quoted string
accordingly).
| [tool.ruff] | ||
| line-length = 100 | ||
|
|
||
| [tool.ruff.lint] | ||
| select = ["ALL"] | ||
| ignore = [ | ||
| "ANN401", # Allow using Any type for function signatures | ||
| "COM812", # Redundant and conflicts with ruff format | ||
| "D203", # No blank line before docstrings (D211) | ||
| "D205", # Breaks if summary is larger than one line due to wrapping or if no summary exists | ||
| "D212", # Enforce docstring summary line on the next line after quotes (D213) | ||
| "D400", # First line of docstrings may not end in period | ||
| "D401", # Docstrings should be written in present tense (not imperative) | ||
| "D415", # First line of docstrings may not end in a period, question mark, or exclamation point | ||
| "FBT", # Allow bool positional parameters since other value positions are allowed | ||
| "FIX002", # Allow todo statements | ||
| "PERF401", # Allow for loops when creating lists | ||
| "PERF403", # Allow for loops when creating dicts | ||
| "S311", # Allow usage of `random` package | ||
| "S603", # Automatically trust inputs of subprocess execution | ||
| "SIM102", # Allow collapsible if statements for readability | ||
| "SIM300", # Skip Yoda-condition format fixes | ||
| "TD002", # Author unnecessary for todo statement | ||
| "TD003", # Issue link unnecessary for todo statement | ||
| "UP015", # Explicit open modes are helpful | ||
| ] | ||
| isort.order-by-type = false | ||
|
|
||
| [tool.ruff.lint.per-file-ignores] | ||
| "tests/**" = [ | ||
| "S101", # Allow usage of pytest `assert` | ||
| "TC003", # Ignore performance overhead of imports only used for type checking | ||
| ] | ||
|
|
||
| [tool.ruff.format] | ||
| docstring-code-format = true | ||
| docstring-code-line-length = 100 | ||
| extend = "../lint-configs/python/ruff.toml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify that the extend path is correctly resolved by Ruff.
The relative path ../lint-configs/python/ruff.toml appears correct for reaching the shared config from exports/ystdlib-py/pyproject.toml. However, I should verify that Ruff correctly resolves this path relative to the pyproject.toml file location and that there are no other references to the previously inlined configuration that might break.
🏁 Script executed:
#!/bin/bash
# Description: Verify the relative path and check for any other references to ystdlib-py Ruff config
# Validate the path exists and is readable
if [ -f "exports/ystdlib-py/../lint-configs/python/ruff.toml" ]; then
echo "✓ Path resolves correctly"
echo "File: exports/lint-configs/python/ruff.toml exists"
else
echo "✗ Path does not resolve to a valid file"
fi
# Search for any other pyproject.toml files that might reference ystdlib config
echo ""
echo "Searching for other pyproject.toml files that might reference ystdlib..."
rg -l "pyproject\.toml" --type=toml -g "pyproject.toml" | head -20
# Search for any documentation or comments referencing ystdlib Ruff config
echo ""
echo "Searching for documentation references to ystdlib Ruff config..."
rg -nC2 "ystdlib" --type=md exports/lint-configs/python/README.md 2>/dev/null || echo "No matches found in README"Length of output: 327
Now let me verify the content of the shared ruff.toml to ensure it contains the appropriate configuration:
Now let me check the content of the shared ruff.toml to verify what configuration is being inherited:
🏁 Script executed:
#!/bin/bash
# View the content of the shared ruff.toml file
cat "exports/lint-configs/python/ruff.toml"Length of output: 1544
Critical: Per-file-ignores patterns from the shared config will not resolve correctly when extended.
When per-file-ignores is set only in an extended ruff.toml file, Ruff calculates the path according to the extended configuration file location, not the project root. The pattern "/**/tests/**" in exports/lint-configs/python/ruff.toml will be resolved relative to exports/lint-configs/python/, not exports/ystdlib-py/. This means the per-file-ignores for test files will not work correctly for ystdlib-py.
Solution: Add extend-per-file-ignores in exports/ystdlib-py/pyproject.toml to override the test patterns:
[tool.ruff.lint.extend-per-file-ignores]
"/**/tests/**" = [
"S101",
"TC003",
]This ensures the glob patterns are resolved relative to the ystdlib-py project root.
🤖 Prompt for AI Agents
In exports/ystdlib-py/pyproject.toml around lines 30-31, the project extends the
shared Ruff config but does not override per-file-ignores, so glob patterns in
the shared config are resolved relative to the shared config path and won’t
match this project’s test files; fix by adding a
[tool.ruff.lint.extend-per-file-ignores] section in this pyproject.toml that
re-declares the test-file globs (e.g. "/**/tests/**") with the same error codes
(S101, TC003) so the patterns are resolved relative to exports/ystdlib-py.
Description
This PR fixes #97 by updating the ruff per-file-ignores pattern to support extending the shared configuration across projects.
Changes
ruff.tomlpattern: Changed"tests/**"to"/**/tests/**"to match test directories at any level when extendedextenddirective for ruffystdlib-py: Consolidated configuration by extending the shared ruff config instead of duplicating 36 linesContext
When projects extend the ruff config using
extend = "path/to/ruff.toml", the old pattern"tests/**"was resolved relative to the config file location, not the extending project's root. This prevented the per-file-ignores from working correctly in extending projects.The new pattern
"/**/tests/**"matches test directories anywhere in the project hierarchy, making it work correctly for both standalone use and when extended by other projects.Checklist
Validation performed
clp'sintegration-tests, verified the new pattern correctly ignores S101 and TC003 rules in test directories at any levelextenddirective to confirm it works in extending projectsSummary by CodeRabbit
Release Notes
Documentation
Chores