diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index c9a20a6..ba40965 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -27,7 +27,7 @@ jobs: run: pre-commit run --all-files --show-diff-on-failure --color=always - name: Check that all files generated by pre-commit are in git run: | - newfiles="$(git ls-files --others --exclude-from=.gitignore)" + newfiles="$(git ls-files --others --exclude-from=.gitignore --exclude=.ruff_cache)" if [ "$newfiles" != "" ] ; then echo "Please check-in the following files:" echo "$newfiles" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b518033..75677f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,119 +21,70 @@ exclude: | ^docs/_templates/.*\.html$| # You don't usually want a bot to modify your legal texts (LICENSE.*|COPYING.*) -default_language_version: - python: python3 - node: "16.17.0" + repos: - - repo: local - hooks: - # These files are most likely copier diff rejection junks; if found, - # review them manually, fix the problem (if needed) and remove them - - id: forbidden-files - name: forbidden files - entry: found forbidden files; remove them - language: fail - files: "\\.rej$" - - id: en-po-files - name: en.po files cannot exist - entry: found a en.po file - language: fail - files: '[a-zA-Z0-9_]*/i18n/en\.po$' - - repo: https://github.com/oca/maintainer-tools - rev: 4cd2b852214dead80822e93e6749b16f2785b2fe - hooks: - # update the NOT INSTALLABLE ADDONS section above - - id: oca-update-pre-commit-excluded-addons - - id: oca-fix-manifest-website - args: ["https://github.com/camptocamp/odoo-cloud-platform"] - - repo: https://github.com/myint/autoflake - rev: v1.6.1 - hooks: - - id: autoflake - args: - - --expand-star-imports - - --ignore-init-module-imports - - --in-place - - --remove-all-unused-imports - - --remove-duplicate-keys - - --remove-unused-variables - - repo: https://github.com/psf/black - rev: 22.8.0 - hooks: - - id: black - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.7.1 - hooks: - - id: prettier - name: prettier (with plugin-xml) - additional_dependencies: - - "prettier@2.7.1" - - "@prettier/plugin-xml@2.2.0" - args: - - --plugin=@prettier/plugin-xml - files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$ - - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.24.0 - hooks: - - id: eslint - verbose: true - args: - - --color - - --fix - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 - hooks: - - id: trailing-whitespace - # exclude autogenerated files - exclude: /README\.rst$|\.pot?$ - - id: end-of-file-fixer - # exclude autogenerated files - exclude: /README\.rst$|\.pot?$ - - id: debug-statements - - id: fix-encoding-pragma - args: ["--remove"] - - id: check-case-conflict - - id: check-docstring-first - - id: check-executables-have-shebangs - - id: check-merge-conflict - # exclude files where underlines are not distinguishable from merge conflicts - exclude: /README\.rst$|^docs/.*\.rst$ - - id: check-symlinks - - id: check-xml - - id: mixed-line-ending - args: ["--fix=lf"] - - repo: https://github.com/asottile/pyupgrade - rev: v2.38.2 - hooks: - - id: pyupgrade - args: ["--keep-percent-format"] - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - name: isort except __init__.py - args: - - --settings=. - exclude: /__init__\.py$ - - repo: https://github.com/acsone/setuptools-odoo - rev: 3.1.8 - hooks: - - id: setuptools-odoo-make-default - - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 - hooks: - - id: flake8 - name: flake8 - additional_dependencies: ["flake8-bugbear==21.9.2"] - - repo: https://github.com/OCA/pylint-odoo - rev: v8.0.19 - hooks: - - id: pylint_odoo - name: pylint with optional checks - args: - - --rcfile=.pylintrc - - --exit-zero - verbose: true - - id: pylint_odoo - args: - - --rcfile=.pylintrc-mandatory + +# pylint +- repo: https://github.com/pycqa/pylint + rev: v4.0.5 + hooks: + - id: pylint + name: pylint odoo + # check only specific Odoo addons + files: odoo/local-src/ + types: ['file', 'python'] # to not check .csv and .conf files + args: ["--rcfile=.ci/pylintrc_odoo"] + additional_dependencies: [pylint-odoo==v10.0.1] + +# pre-commit-hooks +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-yaml + - id: check-symlinks + - id: check-xml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + args: ["--fix=lf"] + types_or: [python, javascript, css, xml, yaml] + - id: trailing-whitespace + types_or: [python, javascript, css, xml, yaml] + +# Odoo pre-commit hooks +- repo: https://github.com/OCA/odoo-pre-commit-hooks + rev: v0.2.20 + hooks: + - id: oca-checks-odoo-module + args: + - --disable= + xml-deprecated-tree-attribute, + xml-header-wrong, + xml-id-position-first, + - id: oca-checks-po + args: ["--fix"] + +# ruff (= flake8 + isort + pyupgrade) +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.4 + hooks: + - id: ruff-check + args: [--fix, --show-fixes] + exclude: __manifest__.py|__init__.py + - id: ruff-format + args: [--diff] + exclude: __manifest__.py|__init__.py + - id: ruff-format + exclude: __manifest__.py|__init__.py + +# rstcheck +- repo: https://github.com/rstcheck/rstcheck + rev: v6.2.5 + hooks: + - id: rstcheck + +# setuptools-odoo +- repo: https://github.com/acsone/setuptools-odoo + rev: 3.3.2 + hooks: + - id: setuptools-odoo-make-default diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..141835e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +[tool.ruff] +line-length = 88 +target-version = "py312" + + +[tool.ruff.lint] +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "C90", # mccabe + "F", # pyflakes + "UP", # pyupgrade + "I", # isort +] +ignore = [ + "UP031", # pyupgrade: use format specifiers instead of percent format (no autofix) +] + +[tool.ruff.lint.pycodestyle] +# line-length is set in [tool.ruff], and it's used by the formatter +# in case the formatted can't autofix the line length, it will be reported as an error +# if it exceeds the max-line-length set here. We use 320 which is maximum allowed value. +max-line-length = 320 + +[tool.ruff.lint.isort] +combine-as-imports = true +force-wrap-aliases = true +known-third-party = [ + "anthem", + "git", + "invoke", + "marabunta", + "openupgradelib", + "pkg_resources", + "psycopg2", + "requests", + "setuptools", + "urllib2", + "yaml", +] +section-order = [ + "future", + "standard-library", + "third-party", + "odoo", + "first-party", + "local-folder", +] + +[tool.ruff.lint.isort.sections] +odoo = ["odoo"] + +[tool.ruff.lint.mccabe] +max-complexity = 16