Skip to content

Commit

Permalink
Change Main Linter to Ruff (#1301)
Browse files Browse the repository at this point in the history
* Change main linter to ruff

* Yaml format

* Replace tools in CI container with ruff
  • Loading branch information
TimPansino authored Feb 11, 2025
1 parent 9abd5a1 commit ee128f8
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 21 deletions.
6 changes: 1 addition & 5 deletions .github/containers/requirements-tools.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
bandit
black
flake8
flynt
isort
ruff
tox
2 changes: 2 additions & 0 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
DEFAULT_BRANCH: ${{ github.event_name == 'pull_request' && github.base_ref || 'main' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
PYTHON_RUFF_ARGUMENTS: '--config=''output-format="github"'''
PYTHON_RUFF_FORMAT_ARGUMENTS: '--config=''output-format="github"'''

# Upload Mega-Linter artifacts
- name: Archive production artifacts
Expand Down
20 changes: 4 additions & 16 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,14 @@ FILTER_REGEX_EXCLUDE: "(.*/?packages/.*)" # Ignore packages directories
ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
- MARKDOWN_MARKDOWN_LINK_CHECK
- MARKDOWN_MARKDOWNLINT
- PYTHON_BANDIT
- PYTHON_BLACK
- PYTHON_FLAKE8
- PYTHON_ISORT
- PYTHON_PYLINT
- PYTHON_RUFF
- PYTHON_RUFF_FORMAT
- RST_RST_LINT
- RST_RSTCHECK
- RST_RSTFMT
- YAML_PRETTIER
- YAML_V8R
- YAML_YAMLLINT

PYTHON_FLAKE8_CONFIG_FILE: setup.cfg
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
PYTHON_PYLINT_CONFIG_FILE: pyproject.toml
PYTHON_ISORT_CONFIG_FILE: pyproject.toml
PYTHON_BANDIT_CONFIG_FILE: pyproject.toml
PYTHON_BANDIT_FILTER_REGEX_EXCLUDE: "tests"
PYTHON_BANDIT_PRE_COMMANDS:
- command: "pip install bandit[toml]"
cwd: "workspace"

PYTHON_PYLINT_ARGUMENTS: "--fail-under=0 --fail-on=E"
PYTHON_RUFF_CONFIG_FILE: pyproject.toml
PYTHON_RUFF_FORMAT_CONFIG_FILE: pyproject.toml
104 changes: 104 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,107 @@
[tool.ruff]
output-format = "grouped"
line-length = 120
target-version = "py37"
extend-exclude = [
"newrelic/packages/",
"setup.py",
]
namespace-packages = ["testing_support"]

[tool.ruff.format]
skip-magic-trailing-comma = true

[tool.ruff.lint]
isort.split-on-trailing-comma=false
select = [
# Enabled linters and rules
"F", # Pyflakes
"E", # pycodestyle
"W", # pycodestyle
"I", # isort
"N", # pep8-naming
"D", # pydocstyle
"UP", # pyupgrade
"YTT", # flake8-2020
"ANN", # flake8-annotations
"ASYNC", # flake8-async
"S", # flake8-bandit
"BLE", # flake8-blind-except
"FBT", # flake8-boolean-trap
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
"C4", # flake8-comprehensions
"T10", # flake8-debugger
"EM", # flake8-errmsg
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"LOG", # flake8-logging
"G", # flake8-logging-format
"INP", # flake8-no-pep420
"PYI", # flake8-pyi
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SLF", # flake8-self
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"INT", # flake8-gettext
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"PGH", # pygrep-hooks
"PL", # Pylint
"TRY", # tryceratops
"FLY", # flynt
"PERF", # Perflint
"FURB", # refurb
"RUF", # Ruff-specific rules
]

# Disabled Linters
# "C90", # mccabe
# "CPY", # flake8-copyright
# "DTZ", # flake8-datetimez
# "DJ", # flake8-django
# "EXE", # flake8-executable
# "PIE", # flake8-pie
# "T20", # flake8-print
# "TC", # flake8-type-checking
# "TD", # flake8-todos
# "FIX", # flake8-fixme
# "ERA", # eradicate
# "PD", # pandas-vet
# "NPY", # NumPy-specific rules
# "FAST", # FastAPI
# "AIR", # Airflow
# "DOC", # pydoclint

ignore = [
# Ruff recommended linter rules to disable when using formatter
"W191", # tab-indentation
"E111", # indentation-with-invalid-multiple
"E114", # indentation-with-invalid-multiple-comment
"E117", # over-indented
"D206", # docstring-tab-indentation
"D300", # triple-single-quotes
"Q000", # bad-quotes-inline-string
"Q001", # bad-quotes-multiline-string
"Q002", # bad-quotes-docstring
"Q003", # avoidable-escaped-quote
"COM812", # missing-trailing-comma
"COM819", # prohibited-trailing-comma
# Additional disabled rules
"D203", # incorrect-blank-line-before-class
"D213", # multi-line-summary-second-line
]

[tool.ruff.lint.per-file-ignores]
"conftest.py" = ["F401"]

# Alternate linters and formatters
[tool.black]
line-length = 120
include = '\.pyi?$'
Expand Down

0 comments on commit ee128f8

Please sign in to comment.