Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,168 @@ skip = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/a

[tool.ruff]
exclude = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/airbytehq/airbyte-python-cdk/issues/12
include = ["airbyte_cdk/**/*.py"] # Ignore test and script folders

target-version = "py310"
line-length = 100
preview = true

Comment on lines +120 to +125
Copy link
Contributor

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

[tool.ruff.lint]
select = [
# For rules reference, see https://docs.astral.sh/ruff/rules/
"A", # flake8-builtins
"ANN", # flake8-annotations
"ARG", # flake8-unused-arguments
"ASYNC", # flake8-async
"B", # flake8-bugbear
"BLE", # Blind except
"C4", # flake8-comprehensions
"C90", # mccabe (complexity)
"COM", # flake8-commas
"CPY", # missing copyright notice
"DTZ", # flake8-datetimez
"E", # pycodestyle (errors)
"ERA", # flake8-eradicate (commented out code)
"EXE", # flake8-executable
"F", # Pyflakes
"FA", # flake8-future-annotations
"FBT", # flake8-boolean-trap
"FIX", # flake8-fixme
"FLY", # flynt
"FURB", # Refurb
"I", # isort
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
"INT", # flake8-gettext
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"N", # pep8-naming
"PERF", # Perflint
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # Pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"PYI", # flake8-pyi
"Q", # flake8-quotes
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"SLF", # flake8-self
"SLOT", # flake8-slots
"T10", # debugger calls
"TCH", # flake8-type-checking
"TD", # flake8-todos
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"TRY002", # Disallow raising vanilla Exception. Create or use a custom exception instead.
"UP", # pyupgrade
"W", # pycodestyle (warnings)
"YTT", # flake8-2020
]
ignore = [
# For rules reference, see https://docs.astral.sh/ruff/rules/

# Consider re-enabling these when we have time to address them:
"A003", # Class attribute 'type' is shadowing a Python builtin
"BLE001", # Do not catch blind exception: Exception
"C416", # Allow unnecessary-comprehensions. Auto-fix sometimes unsafe if operating over a mapping.
"DTZ005", # Allow use of 'datetime.datetime.now()' without timezone (we should fix these eventually)
"DTZ007", # Allow use of 'strptime()' without timezone (we should fix these eventually)
"D", # pydocstyle (Docstring conventions)
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"E501", # Line too long
"ERA001", # Remove commented-out code
"FIX002", # Allow "TODO:" comments
"PGH003", # Allow non-specific "type: ignore" comments
"PLW0108", # Lambda may be unnecessary; consider inlining inner function
"PLW0603", # Using the global statement to update _cache is discouraged
"T20", # flake8-print, consider re-enabling once we have logging
"TD003", # Require issue links for TODOs

# These we don't agree with or don't want to prioritize to enforce:
"ANN003", # kwargs missing type annotations
"ANN101", # Type annotations for 'self' args
"ANN102", # Type annotations for 'cls' args
"ASYNC1", # flake8-trio (opinionated, noisy)
"COM812", # Because it conflicts with ruff auto-format
"DJ", # Django linting
"EM", # flake8-errmsgs (may reconsider later)
"FURB189", # Subclassing safety at the cost if isinstance() instability
"G", # flake8-logging-format
"INP001", # Dir 'examples' is part of an implicit namespace package. Add an __init__.py.
"ISC001", # Conflicts with ruff auto-format
"N818", # Custom exception names should use the suffix "Error"
"NPY", # NumPy-specific rules
"N805", # Enforce first-arg is 'self' (false positive for class methods in Pydantic)
"PD", # pandas-vet
"PERF203", # exception handling in loop
"PIE790", # Allow unnecssary 'pass' (sometimes useful for readability)
"PLR6201", # Allow membership checks in lists (set-based check is unsafe when values are unhashable)
"PLR6301", # Allow class methods that don't use 'self' (otherwise noisy)
"RET504", # Ignore unnecessary assign before return
"RUF022", # Allow unsorted __all__ (sometimes useful for grouping by type with pdoc)
"S", # flake8-bandit (noisy, security related)
"SIM910", # Allow "None" as second argument to Dict.get(). "Explicit is better than implicit."
"TCH003", # Moving standard library imports under `TYPE_CHECKING` blocks is unsafe with Pydantic and Serpyco models
"TD002", # Require author for TODOs
"TRY003", # Allow string passing to exception constructor.
"TRY400", # Ignore for now: prefer logging.exception over logging.error
]
fixable = ["ALL"]
unfixable = [
"ERA001", # Commented-out code (avoid silent loss of code)
"T201", # print() calls (avoid silent loss of code / log messages)
"TCH001", # Moving application imports under `TYPE_CHECKING` blocks is unsafe with Pydantic and Serpyco models
"TCH002", # Moving 3rd part imports under `TYPE_CHECKING` blocks is unsafe with Pydantic and Serpyco models
]
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.pylint]
max-args = 8 # Relaxed from default of 5
max-branches = 15 # Relaxed from default of 12


[tool.ruff.lint.isort]
force-sort-within-sections = false
lines-after-imports = 2
known-first-party = [
"airbyte_protocol",
"airbyte_protocol_dataclasses",
]
known-local-folder = ["airbyte_cdk"]
required-imports = ["from __future__ import annotations"]
known-third-party = []
section-order = [
"future",
"standard-library",
"third-party",
"first-party",
"local-folder",
]

[tool.ruff.lint.mccabe]
max-complexity = 24

[tool.ruff.lint.pycodestyle]
ignore-overlong-task-comments = true

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = false
ignore-fully-untyped = false

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
preview = false
docstring-code-format = true

[tool.ruff.lint]
select = ["I"]
Expand Down
Loading