Skip to content

Commit 4643118

Browse files
authored
πŸ’š feat: replace flake, isort, etc. with ruff (#8)
* πŸ’š feat: replace flake, isort, etc. with ruff * docs: update pre-commit doc * πŸ’š ci: fix python version in github action * πŸ“ docs: update doc
1 parent 3172981 commit 4643118

5 files changed

Lines changed: 199 additions & 117 deletions

File tree

β€Ž.github/workflows/main.yamlβ€Ž

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Style check
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
pre-commit:
10+
name: Run pre-commit
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
15+
with:
16+
python-version: "3.10"
17+
- uses: pre-commit/action@v3.0.1
18+
with:
19+
extra_args: --all-files

β€Ž.pre-commit-config.yamlβ€Ž

Lines changed: 92 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,92 @@
1-
# Pre-commit hooks
2-
3-
default_language_version:
4-
python: python3.10
5-
6-
# Define bot property if installed via https://github.com/marketplace/pre-commit-ci
7-
ci:
8-
autofix_prs: true
9-
autofix_commit_msg: '🎨 style: [pre-commit.ci] auto fixes from pre-commit.com hooks'
10-
autoupdate_commit_msg: 'πŸ’š ci: [pre-commit.ci] pre-commit autoupdate'
11-
autoupdate_schedule: monthly
12-
13-
repos:
14-
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.6.0
16-
hooks:
17-
- id: check-added-large-files
18-
- id: check-case-conflict
19-
- id: check-docstring-first
20-
- id: check-json
21-
- id: check-yaml
22-
- id: detect-aws-credentials
23-
args: [--allow-missing-credentials]
24-
- id: detect-private-key
25-
- id: double-quote-string-fixer
26-
- id: end-of-file-fixer
27-
- id: mixed-line-ending
28-
- id: trailing-whitespace
29-
- id: pretty-format-json
30-
args: [--autofix, --indent=4, --no-ensure-ascii, --no-sort-keys]
31-
32-
- repo: https://github.com/asottile/pyupgrade
33-
rev: v3.17.0
34-
hooks:
35-
- id: pyupgrade
36-
name: Upgrade code
37-
args: [ --py310-plus ]
38-
39-
- repo: https://github.com/psf/black
40-
rev: 24.8.0
41-
hooks:
42-
- id: black
43-
name: PEP8 formatting
44-
args: [ --skip-string-normalization, --line-length=100]
45-
46-
- repo: https://github.com/PyCQA/isort
47-
rev: 5.13.2
48-
hooks:
49-
- id: isort
50-
name: I-sort imports
51-
52-
- repo: https://github.com/PyCQA/autoflake
53-
rev: v2.3.1
54-
hooks:
55-
- id: autoflake
56-
name: Autoflake - remove unused imports/variables
57-
args: [
58-
--in-place,
59-
--remove-all-unused-imports,
60-
--remove-unused-variables,
61-
--ignore-init-module-imports,
62-
--ignore-pass-after-docstring,
63-
]
64-
65-
- repo: https://github.com/PyCQA/flake8
66-
rev: 7.1.1
67-
hooks:
68-
- id: flake8
69-
name: Flake8 check
1+
# Pre-commit hooks
2+
3+
default_language_version:
4+
python: python3
5+
6+
# Define bot property if installed via https://github.com/marketplace/pre-commit-ci
7+
ci:
8+
autofix_prs: true
9+
autofix_commit_msg: '🎨 style: [pre-commit.ci] auto fixes from pre-commit.com hooks'
10+
autoupdate_commit_msg: 'πŸ’š ci: [pre-commit.ci] pre-commit autoupdate'
11+
autoupdate_schedule: monthly
12+
13+
repos:
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v4.6.0
16+
hooks:
17+
- id: check-added-large-files
18+
- id: check-case-conflict
19+
- id: check-docstring-first
20+
- id: check-json
21+
- id: check-yaml
22+
- id: detect-aws-credentials
23+
args: [--allow-missing-credentials]
24+
- id: detect-private-key
25+
- id: double-quote-string-fixer
26+
- id: end-of-file-fixer
27+
- id: mixed-line-ending
28+
- id: trailing-whitespace
29+
- id: pretty-format-json
30+
args: [--autofix, --indent=4, --no-ensure-ascii, --no-sort-keys]
31+
32+
- repo: https://github.com/pre-commit/mirrors-mypy
33+
rev: "v1.11.2"
34+
hooks:
35+
- id: mypy
36+
args: ["--strict", "--ignore-missing-imports"]
37+
38+
- repo: https://github.com/astral-sh/ruff-pre-commit
39+
rev: v0.6.6
40+
hooks:
41+
# Run the linter
42+
- id: ruff
43+
types_or: [ python, pyi ]
44+
args: [ --fix ]
45+
46+
# Run the formatter
47+
- id: ruff-format
48+
types_or: [ python, pyi ]
49+
50+
- repo: https://github.com/codespell-project/codespell
51+
rev: v2.2.4
52+
hooks:
53+
- id: codespell
54+
55+
# - repo: https://github.com/asottile/pyupgrade
56+
# rev: v3.15.2
57+
# hooks:
58+
# - id: pyupgrade
59+
# name: Upgrade code
60+
# args: [ --py310-plus ]
61+
62+
# - repo: https://github.com/psf/black
63+
# rev: 24.4.2
64+
# hooks:
65+
# - id: black
66+
# name: PEP8 formatting
67+
# args: [ --skip-string-normalization, --line-length=100]
68+
69+
# - repo: https://github.com/PyCQA/isort
70+
# rev: 5.13.2
71+
# hooks:
72+
# - id: isort
73+
# name: I-sort imports
74+
75+
# - repo: https://github.com/PyCQA/autoflake
76+
# rev: v2.3.1
77+
# hooks:
78+
# - id: autoflake
79+
# name: Autoflake - remove unused imports/variables
80+
# args: [
81+
# --in-place,
82+
# --remove-all-unused-imports,
83+
# --remove-unused-variables,
84+
# --ignore-init-module-imports,
85+
# --ignore-pass-after-docstring,
86+
# ]
87+
88+
# - repo: https://github.com/PyCQA/flake8
89+
# rev: 7.0.0
90+
# hooks:
91+
# - id: flake8
92+
# name: Flake8 check

β€ŽREADME.mdβ€Ž

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,29 @@ Add `chore` and `wip` to basic angular commit types.
3030
| `refactor` | ♻️ | Refactor code |
3131
| `style` | 🎨 | Improve structure/format of the code |
3232
| `test` | βœ… | Add, update or pass tests |
33-
| `chore` | 🧹 | Something that doesn’t fit the other types |
33+
| `chore` | πŸ”΅ | Something that doesn’t fit the other types |
3434
| `wip` | 🚧 | Working in progress |
35+
36+
## Pre-commit
37+
### Hooks
38+
#### Basic hooks
39+
- [pre-commit-hooks](https://github.com/pre-commit/pre-commit-hooks): Some out-of-the-box hooks for pre-commit.
40+
41+
#### Python code linter and formatter
42+
> We are using ruff in this repo because it can be used to replace most of the other tools.
43+
44+
- [ruff](https://github.com/astral-sh/ruff): Extremely fast Python linter and code formatter that support lint rules from many popular tools like Flake8, isort, etc.
45+
- [mypy](https://github.com/python/mypy): Static Typing for Python.
46+
- [flake8](https://github.com/PyCQA/flake8): Plugin for flake8 (wrap PyFlakes, pycodestyle, McCabe)
47+
- [black](https://github.com/psf/black): Uncompromising Python code formatter.
48+
- [isort](https://github.com/PyCQA/isort): Python code formatter for sorting and categorizing imports.
49+
- [autoflake](https://github.com/PyCQA/autoflake): Tool to removes unused imports/variables as reported by pyflakes.
50+
- [pyupgrade](https://github.com/asottile/pyupgrade): Tool to automatically upgrade syntax for newer versions of the language.
51+
52+
#### Text/Doc
53+
- [doctoc](https://github.com/thlorenz/doctoc): Tool to generates table of contents for markdown files.
54+
- [markdownlint](https://github.com/markdownlint/markdownlint): Markdown lint tool.
55+
- [codespell](https://github.com/codespell-project/codespell): Tool for code misspellings checking.
56+
57+
### CI
58+
[pre-commit.ci](https://pre-commit.ci/): GitHub app for pre-commit.

β€Žsetup.cfgβ€Ž

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,69 @@
22
# Example usage: global configuration for PEP8 (via flake8) setting or default pytest arguments
33
# Local usage: pip install pre-commit, pre-commit run --all-files
44

5-
[isort]
6-
# https://pycqa.github.io/isort/docs/configuration/options.html
7-
line_length = 100
8-
# see: https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html
9-
multi_line_output = 0
10-
include_trailing_comma = True
11-
12-
[flake8]
13-
# https://flake8.pycqa.org/en/latest/user/options.html
14-
max-line-length = 100
15-
max-complexity = 20
16-
verbose = 2
17-
format = pylint
18-
# https://pep8.readthedocs.io/en/latest/intro.html#error-codes
19-
# see: https://www.flake8rules.com/
20-
select = B, C, E, F, W
21-
ignore = C101, C407, C408, E402, E731, E741, W503
22-
# C101: Coding magic comment not found
23-
# C407: Unnecessary <dict/list> comprehension - <builtin> can take a generator
24-
# C408: Unnecessary <dict/list/tuple> call - rewrite as a literal
25-
# E402: module level import not at top of file
5+
[ruff]
6+
# https://docs.astral.sh/ruff/configuration/
7+
line-length = 100
8+
indent-width = 4
9+
# see: https://docs.astral.sh/ruff/rules
10+
select =
11+
F # Pyflakes
12+
E # Pycodestyle
13+
W # Pycodestyle
14+
C90 # McCabe
15+
I # Isort
16+
UP # PyUpgrade
17+
B # Flake8-bugbear
18+
C4 # Flake8-comprehensions
19+
ignore = C407, C408, E402, E731, E741, W503
20+
# E402: Module level import not at top of file
2621
# E731: Do not assign a lambda expression, use a def
2722
# E741: Do not use variables named 'I', 'O', or 'l'
28-
# W503: Line break occurred before a binary operator
23+
# W503: Line break occurred before a binary operator
24+
# C408: Unnecessary <dict/list/tuple> call - rewrite as a literal
25+
fixable = ["ALL"]
26+
unfixable = ["F401"]
27+
# F401: module imported but unused
28+
[ruff.lint]
2929
per-file-ignores =
30-
**/__init__.py: E402, F401, F403, F405
31-
# E402: module level import not at top of file
32-
# F401: module imported but unused
33-
# F403: β€˜from module import *’ used; unable to detect undefined names
34-
# F405: Name may be undefined, or defined from star imports: module
30+
**/__init__.py: E402, F401, F403, F405
31+
# E402: Module level import not at top of file
32+
# F401: Module imported but unused
33+
# F403: β€˜from module import *’ used; unable to detect undefined names
34+
# F405: Name may be undefined, or defined from star imports: module
35+
[ruff.format]
36+
quote-style = "single"
37+
indent-style = "tab"
38+
skip-magic-trailing-comma = false
39+
line-ending = "auto"
40+
41+
# [isort]
42+
# # https://pycqa.github.io/isort/docs/configuration/options.html
43+
# line_length = 100
44+
# # see: https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html
45+
# multi_line_output = 0
46+
# include_trailing_comma = True
47+
48+
# [flake8]
49+
# # https://flake8.pycqa.org/en/latest/user/options.html
50+
# max-line-length = 100
51+
# max-complexity = 20
52+
# verbose = 2
53+
# format = pylint
54+
# # https://pep8.readthedocs.io/en/latest/intro.html#error-codes
55+
# # see: https://www.flake8rules.com/
56+
# select = B, C, E, F, W
57+
# ignore = C101, C407, C408, E402, E731, E741, W503
58+
# # C101: Coding magic comment not found
59+
# # C407: Unnecessary <dict/list> comprehension - <builtin> can take a generator
60+
# # C408: Unnecessary <dict/list/tuple> call - rewrite as a literal
61+
# # E402: Module level import not at top of file
62+
# # E731: Do not assign a lambda expression, use a def
63+
# # E741: Do not use variables named 'I', 'O', or 'l'
64+
# # W503: Line break occurred before a binary operator
65+
# per-file-ignores =
66+
# **/__init__.py: E402, F401, F403, F405
67+
# # E402: Module level import not at top of file
68+
# # F401: Module imported but unused
69+
# # F403: β€˜from module import *’ used; unable to detect undefined names
70+
# # F405: Name may be undefined, or defined from star imports: module

0 commit comments

Comments
Β (0)