addons-cm/.pre-commit-config.yaml
snt 0a2cc4c8c4 [FIX] Code quality refactoring: remove F401, fix translations, improve test coverage
- Remove unused imports (F401) across multiple addons (__init__.py files)
- Fix W8161 (prefer-env-translation): replace global _() with self.env._() and request.env._()
- Fix W8301 (translation-not-lazy): use named placeholders instead of % formatting
  - group_order.py: Fix 2 constraint messages
  - wizard_update_product_category.py: Fix notification message
- Fix E722 (bare except): add proper Exception handling with logging in website_sale.py
- Fix W8116/E8102 (post-migrate.py): remove cr.commit() and print(), add logging
- Fix W8150 (relative imports): update test_templates_rendering.py imports
- Fix F841 (assigned but unused): Remove unused variable assignments in tests
- Add mypy.ini with exclude pattern for migrations to avoid duplicate module errors
- Add __init__.py files in migration directories for proper Python package structure
- Restore migration scripts (post-migration.py) that were deleted
- Update pyproject.toml with mypy configuration
- Replace print() with logging in test_prices.py
- Fix CSS indentation in header.css
- Add portal access tests to improve test coverage

This refactoring improves:
- Code quality: All F401, E722, W8161, W8301, W8150, E8102/W8116 violations resolved
- Internationalization: Proper use of env._() with lazy formatting
- Testing: Reduced unused variable assignments and improved portal user testing
- Linting: All pre-commit hooks passing (except non-critical B018, C8116, W8113)
2026-02-21 02:13:40 +01:00

144 lines
5 KiB
YAML

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
/setup/|/README\.rst$|/static/description/index\.html$|
# Maybe reactivate this when all README files include prettier ignore tags?
^README\.md$|
# Library files can have extraneous formatting (even minimized)
/static/(src/)?lib/|
# Repos using Sphinx to generate docs don't need prettying
^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$"
- repo: https://github.com/oca/maintainer-tools
rev: 71aa4caec15e8c1456b4da19e9f39aa0aa7377a9
hooks:
# update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons
- repo: https://github.com/myint/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args: ["-i", "--ignore-init-module-imports"]
- repo: https://github.com/psf/black
rev: 26.1.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
name: prettier + 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|json5|scss|toml|xml|yaml|yml)$
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v10.0.0
hooks:
- id: eslint
verbose: true
args:
- --color
- --fix
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.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: 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: v3.21.2
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/PyCQA/isort
rev: 7.0.0
hooks:
- id: isort
name: isort except __init__.py
args:
- --settings=.
exclude: /__init__\.py$
# setuptools-odoo deshabilitado temporalmente (no soporta Odoo 18.0)
# - repo: https://github.com/acsone/setuptools-odoo
# rev: 3.3.2
# hooks:
# - id: setuptools-odoo-make-default
# - id: setuptools-odoo-get-requirements
# args:
# - --output
# - requirements.txt
# - --header
# - "# generated from manifests external_dependencies"
- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==23.12.2"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.19.1
hooks:
- id: mypy
# do not run on test files or __init__ files (mypy does not support
# namespace packages)
exclude: (/tests/|/__init__\.py$)
# Exclude migrations explicitly to avoid duplicate-module errors
args: ["--exclude", "(?i).*/migrations/.*"]
additional_dependencies:
- "lxml"
- "odoo-stubs"
- "types-python-dateutil"
- "types-pytz"
- "types-requests"
- "types-setuptools"
- repo: https://github.com/PyCQA/pylint
rev: v4.0.4
hooks:
- id: pylint
name: pylint with optional checks
args:
- --rcfile=.pylintrc
- --exit-zero
verbose: true
additional_dependencies: &pylint_deps
- pylint-odoo==10.0.0
- id: pylint
name: pylint with mandatory checks
args:
- --rcfile=.pylintrc-mandatory
additional_dependencies: *pylint_deps