Skip to content

Commit

Permalink
build(ruff): 🏗️ support use of ruff (#125)
Browse files Browse the repository at this point in the history
* build(ruff): 🏗️ support use of ruff

* ci: add missing ruff dependency

* ci: update ruff hook names

* build(lint): ⚰️ remove black and isort dependencies

This is not needed as they have been replaced with support from ruff.

---------

Co-authored-by: Oleksandr Yaremchuk <[email protected]>
  • Loading branch information
CandiedCode and asofter authored Apr 26, 2024
1 parent 2d5d4a6 commit fb795f9
Show file tree
Hide file tree
Showing 18 changed files with 1,058 additions and 1,013 deletions.
31 changes: 6 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,17 @@ repos:

- repo: local
hooks:
- id: black
name: black
entry: black
- id: ruff check
name: ruff-check
entry: ruff check --force-exclude --fix
language: system
pass_filenames: true
types: [ python ]
# this is not technically always safe but usually is
# use comments `# isort: off` and `# isort: on` to disable/re-enable isort
- id: isort
name: isort
entry: isort
- id: ruff format
name: ruff-format
entry: ruff format --force-exclude
language: system
pass_filenames: true
types: [ python ]

# this is slightly dangerous because python imports have side effects
# and this tool removes unused imports, which may be providing
# necessary side effects for the code to run
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args:
- "--in-place"
- "--expand-star-imports"
- "--remove-duplicate-keys"
- "--remove-unused-variables"
- "--remove-all-unused-imports"
exclude: "llm_guard/__init__.py"

- repo: https://github.com/zricethezav/gitleaks
rev: v8.18.2
hooks:
Expand Down
48 changes: 48 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
extend-include = ["*.ipynb"]
line-length = 100
src = [
"llm_guard",
"tests",
]
exclude = ["examples/google_gemini.py"]

[lint]
ignore = [
'RUF001' # String contains ambiguous `,`
]
ignore-init-module-imports = true
select = [
'A', # flake8-builtins
'ASYNC', # flake8-async
'ERA', # eradicate
'F', # Pyflakes
'I', # Isort
'NPY', # NumPy Rules
'PERF', # performance
'PYI', # flake8-pyi
]

[lint.flake8-builtins]
builtins-ignorelist = ["input"]


[lint.isort]
combine-as-imports = true
known-first-party = [
"llm_guard",
"tests",
]
split-on-trailing-comma = false

[lint.pep8-naming]
ignore-names = []

[lint.per-file-ignores]
"__init__.py" = [
"F401", # Import imported into __init__ by unused; consider adding to `__all__` or using a redundant alias
"F403", # Unable to detect undefined names
"F405", # May be undefined, or defined from star imports
]

[lint.pydocstyle]
convention = "google"
Loading

0 comments on commit fb795f9

Please sign in to comment.