-
Notifications
You must be signed in to change notification settings - Fork 5
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
Chore(linting): Add ruff lint rules #22
base: main
Are you sure you want to change the base?
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe Changes
Possibly related PRs
Wdyt about considering any additional linting rules or configurations that might further improve the code quality? Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 0
🧹 Outside diff range and nitpick comments (3)
pyproject.toml (3)
166-215
: Consider enabling some ignored rules in the futureWhile the ignore list is well-documented, consider enabling these rules in the future to improve code quality:
D102
,D103
: Enforcing docstrings would improve code documentationE501
: Since line length is set to 100, this rule could help maintain consistent line lengths
248-250
: Consider reducing complexity thresholdsThe current McCabe complexity threshold of 24 is quite high and might allow overly complex functions. Consider:
- Reducing it to a more standard value (10-15)
- Gradually decreasing it over time to encourage simpler functions
225-228
: Review relaxed Pylint thresholdsThe relaxed thresholds for
max-args
(8) andmax-branches
(15) might lead to functions that are harder to maintain. Consider:
- Keeping
max-args
but adding a comment explaining why 8 is acceptable- Reducing
max-branches
to align with cognitive complexity best practices
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
pyproject.toml
(1 hunks)pyproject.toml-bak
(0 hunks)
💤 Files with no reviewable changes (1)
- pyproject.toml-bak
🔇 Additional comments (3)
pyproject.toml (3)
110-110
: Consider the stability implications of enabling preview mode
Preview mode enables features that are not yet stable and may introduce breaking changes in future Ruff updates. Consider disabling it if stability is a priority.
113-165
: Well-structured and comprehensive rule selection
The selected rules provide excellent coverage across various aspects of code quality:
- Security rules (B, BLE)
- Performance rules (PERF)
- Code quality rules (E, F)
- Style rules (I, Q)
Each rule is well-documented with references to the official documentation.
216-222
: Good safety considerations in fix configurations
The unfixable rules are well-chosen to prevent accidental data loss and maintain code safety:
- Preserving commented code (ERA001)
- Preserving print statements (T201)
- Preventing unsafe type checking modifications (TCH001, TCH002)
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: 1
🧹 Outside diff range and nitpick comments (3)
pyproject.toml (3)
118-171
: Consider potential rule conflictsYou've selected a comprehensive set of rules! 🎉 However, I noticed some rules that might conflict with each other or be too strict initially:
FA
(future-annotations) withANN
(annotations) might have overlapping concernsFBT
(boolean-trap) might be too strict for existing codebaseWould it make sense to start with a smaller subset and gradually enable more rules as the codebase adapts? This could help with adoption and reduce initial friction. wdyt?
172-221
: Consider documenting rationale for ignored rulesLove how you've organized the ignore list into categories! 🌟 For some rules like
PLR6201
andSIM910
, you've added clear explanations. Would it be helpful to add similar rationales for other ignored rules? This could help future maintainers understand why certain decisions were made.For example:
- Why is
D
(pydocstyle) ignored when we're using Google convention?- Is
S
(bandit) something we want to enable later for security?wdyt?
222-228
: Review unfixable rules listGreat job protecting against unsafe changes! 🛡️ I noticed
TCH001
andTCH002
are marked as unfixable due to Pydantic and Serpyco models. Since we're using these frameworks extensively, this makes sense.However, would it be worth reconsidering
ERA001
(commented-out code)? While I understand the caution, commented-out code often indicates technical debt. Maybe we could enable fixing it in a separate cleanup PR? wdyt?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
pyproject.toml
(1 hunks)
🔇 Additional comments (1)
pyproject.toml (1)
231-273
: Document rationale for relaxed limits
I see you've relaxed some limits:
max-args = 8
(up from 5)max-branches = 15
(up from 12)max-complexity = 24
These values are quite permissive. Would it be helpful to add comments explaining why these specific values were chosen? This could help prevent them from being accidentally tightened in the future. Also, should we consider gradually reducing these limits over time? wdyt?
include = ["airbyte_cdk/**/*.py"] # Ignore test and script folders | ||
|
||
target-version = "py310" | ||
line-length = 100 | ||
preview = true | ||
|
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.
💡 Codebase verification
Preview mode is already disabled in the codebase
Hey! I noticed that while this PR is adding preview = true
, there's actually a conflicting setting elsewhere in the codebase that sets preview = false
. Since preview features can indeed introduce breaking changes, would it be better to keep it disabled for now? This would help maintain stability across ruff updates. wdyt?
🔗 Analysis chain
Consider the implications of enabling preview mode
Hey! I noticed you've enabled preview mode for ruff. While this gives us access to the latest features, it might introduce breaking changes in future updates. What do you think about adding a comment explaining why we need preview mode? This would help future maintainers understand the decision. wdyt?
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if any preview features are actually being used
rg -l "preview.*=.*true" . | xargs ruff --show-settings 2>&1 | grep -i "preview"
Length of output: 75
Script:
#!/bin/bash
# Let's check what ruff rules are currently enabled and if any preview features are mentioned
rg -A 5 -B 5 "\[tool\.ruff\]" pyproject.toml
# Also check if there are any comments mentioning preview features
rg -i "preview" pyproject.toml
Length of output: 586
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: 0
🧹 Outside diff range and nitpick comments (4)
pyproject.toml (4)
122-122
: Consider using a more inclusive pattern for Python filesThe current pattern
"airbyte_cdk/**/*.py"
looks good but might miss Python files in other directories. Would you consider using["**/*.py", "**/*.pyi"]
to catch all Python files and type stubs, and then useexclude
for specific directories you want to ignore? wdyt?
129-181
: Great selection of rules! Consider phasing them in graduallyThe rule selection is comprehensive and well-documented! However, enabling all these rules at once might be overwhelming. Would you consider:
- Adding comments for each rule category explaining why it was chosen?
- Implementing rules in phases, starting with the most critical ones?
182-231
: Excellent documentation of ignored rules!Love how you've documented the rationale for ignored rules and separated them into "fix later" vs "won't fix"! This will be super helpful for maintenance. One suggestion: would you consider adding GitHub issues for the rules marked with "Consider re-enabling these when we have time"? This would help track technical debt. wdyt?
241-244
: Consider documenting the rationale for relaxed limitsThe relaxed limits for
max-args
andmax-branches
make sense, but would you consider adding comments explaining why these specific values were chosen? This would help future maintainers understand if these limits need adjustment. wdyt?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
pyproject.toml
(1 hunks)
🔇 Additional comments (3)
pyproject.toml (3)
126-126
: Consider the implications of enabling preview mode
Hey! I noticed you've enabled preview mode for ruff. While this gives us access to the latest features, it might introduce breaking changes in future updates. What do you think about adding a comment explaining why we need preview mode? This would help future maintainers understand the decision. wdyt?
#!/bin/bash
# Check if any preview features are actually being used
rg -l "preview.*=.*true" . | xargs ruff --show-settings 2>&1 | grep -i "preview"
232-238
: LGTM! Safe configuration for auto-fixes
Great choice on marking code comments and print statements as unfixable to prevent accidental loss of important information!
264-265
: Verify if the complexity threshold is appropriate
The McCabe complexity threshold of 24 is quite high compared to the typical recommendation of 10-15. Would you consider:
- Adding a comment explaining why this threshold was chosen?
- Running some analysis to see what the current complexity distribution looks like in the codebase?
✅ Verification successful
Based on the analysis of the codebase, I can provide a final response:
The McCabe complexity threshold of 24 seems reasonable for this codebase
Looking at the test files and implementation code, there are legitimate cases of higher complexity, particularly in:
- Test scenarios with multiple nested conditions (e.g., test_client_side_record_filter_decorator_with_cursor_types)
- Stream handling with various state management scenarios
- Error handling and retry logic
The threshold of 24 appears to be a pragmatic choice that balances code maintainability with the inherent complexity of implementing streaming data connectors. Would you consider adding a comment like this to explain the rationale? wdyt?
[tool.ruff.lint.mccabe]
# Higher threshold to accommodate complex stream handling, state management,
# and comprehensive test scenarios typical in data connector implementations
max-complexity = 24
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check current complexity distribution
rg -l "def " | xargs ruff check --select C90 --statistics 2>&1 | sort -n
Length of output: 108
Script:
#!/bin/bash
# Find Python files with high cyclomatic complexity using ast-grep
# Look for functions with many conditional branches, loops, and exception handlers
ast-grep --pattern 'def $_ ($$$):
$$$
if $_:
$$$
if $_:
$$$
if $_:
$$$
$$$'
# Also search for functions with many elif branches
ast-grep --pattern 'def $_ ($$$):
$$$
if $_:
$$$
elif $_:
$$$
elif $_:
$$$
$$$'
# Search for functions with nested loops
ast-grep --pattern 'def $_ ($$$):
$$$
for $_ in $_:
$$$
for $_ in $_:
$$$'
# Get a list of all Python files for manual inspection if needed
fd -e py
Length of output: 60867
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: 0
🧹 Nitpick comments (5)
pyproject.toml (5)
120-121
: Consider using a more specific include patternThe current pattern includes all Python files in
airbyte_cdk
. Would it be more precise to use["airbyte_cdk/**/*.py", "airbyte_cdk/*.py"]
to explicitly catch both root and nested files? wdyt?
127-179
: Consider a phased rollout of lint rulesYou've selected a comprehensive set of rules, which is great! However, would it make sense to introduce these in phases? We could start with essential rules (E, F, W) and gradually enable others as the codebase adapts. This could help with adoption and reduce initial friction. wdyt?
180-230
: Consider enabling security-related rulesI notice that security-related rules (S) are ignored. While they can be noisy, would it be worth enabling specific ones like S101 (assert statements) or S106 (hardcoded passwords)? This could help catch potential security issues early. wdyt?
239-242
: Consider documenting the rationale for relaxed limitsThe increased limits for max-args (8) and max-branches (15) seem reasonable, but would it be helpful to add a comment explaining why these specific values were chosen? This could help future maintainers understand the decision. wdyt?
275-281
: Inconsistent preview settings between format and lintI noticed that format.preview is set to false while lint.preview is true. Should we align these settings to maintain consistency? wdyt?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pyproject.toml
(1 hunks)
🔇 Additional comments (2)
pyproject.toml (2)
124-125
: Preview mode is already disabled in the codebase
Hey! I noticed that while this PR is adding preview = true
, there's actually a conflicting setting elsewhere in the codebase that sets preview = false
. Since preview features can indeed introduce breaking changes, would it be better to keep it disabled for now? This would help maintain stability across ruff updates. wdyt?
230-238
: LGTM! Good safeguards against unsafe fixes
The fixable/unfixable configuration looks well-balanced, especially protecting against silent code loss and unsafe type checking moves.
Summary by CodeRabbit
New Features
Improvements