Skip to content

Instantly share code, notes, and snippets.

@antoinedelia
Last active June 7, 2024 13:06
Show Gist options
  • Save antoinedelia/d6cca39f319dbb3258bedd41bca0c525 to your computer and use it in GitHub Desktop.
Save antoinedelia/d6cca39f319dbb3258bedd41bca0c525 to your computer and use it in GitHub Desktop.
Ruff starter
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-json
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-merge-conflict
- id: detect-aws-credentials
- id: detect-private-key
- id: requirements-txt-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
[tool.ruff]
# Exclude common directories that are typically not part of the source code or are generated by tools.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]
# Set the maximum line length to 127 characters.
line-length = 127
# Define the number of spaces used for indentation, aligning with Black's style.
indent-width = 4
# The minimum Python version to target, e.g., when considering automatic code upgrades,
# like rewriting type annotations
target-version = "py312"
[tool.ruff.lint]
# Enable Pyflakes (F) and a subset of the pycodestyle (E) codes by default.
# pycodestyle warnings (W)
# Activate Security Rules (S) to replace bandit
# Enable the isort rules (I) to replace isort
# flake8-bugbear (B)
# flake8-simplify (SIM)
select = ["F", "E4", "E7", "E9", "W", "S", "I", "B", "SIM", "PGH004"]
ignore = [] # List any rules to be ignored, currently empty.
# Allow auto-fixing of all enabled rules when using the `--fix` option.
fixable = ["ALL"]
unfixable = [] # Specify rules that cannot be auto-fixed, if any.
# Define a regex pattern for allowed unused variables (typically underscore-prefixed).
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.format]
# Enforce double quotes for strings, following Black's style.
quote-style = "double"
# Use spaces for indentation, in line with Black's formatting style.
indent-style = "space"
# Keep magic trailing commas, a feature of Black's formatting.
skip-magic-trailing-comma = false
# Automatically detect and use the appropriate line ending style.
line-ending = "auto"
pip install uv --upgrade
uv venv
source .venv/bin/activate
uv pip install -r requirements.txt
pip install ruff --upgrade
ruff check --fix
ruff format
pip install pre-commit --upgrade
pre-commit install
pre-commit run --all-files
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff"
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit",
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment