diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7217aec..07129ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,66 @@ +exclude: | + (?x) + # NOT INSTALLABLE ADDONS + # END NOT INSTALLABLE ADDONS + # Files and folders generated by bots, to avoid loops + ^setup/|/static/description/index\.html$| + # We don't want to mess with tool-generated files + .svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/| + # 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.*)| + # Exclude external addons + odoo/src/ext_addons/| + # Exclude container config file, especially the generated ones + ^odoo/*.* +default_language_version: + python: python3 + node: "14.18.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/myint/autoflake + rev: v1.4 + 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: 20.8b1 + rev: 21.9b0 hooks: - id: black - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.1.2 + rev: v2.4.1 hooks: - id: prettier - name: prettier + plugin-xml + name: prettier (with plugin-xml) additional_dependencies: - - "prettier@2.1.2" - - "@prettier/plugin-xml@0.12.0" + - "prettier@2.4.1" + - "@prettier/plugin-xml@1.1.0" args: - --config=odoo/.prettierrc.yml - --plugin=@prettier/plugin-xml - --ignore-path=odoo/.prettierignore - + files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$ - repo: https://github.com/pre-commit/mirrors-eslint - rev: v7.8.1 + rev: v7.32.0 hooks: - id: eslint verbose: true @@ -27,31 +69,62 @@ repos: - --fix - --config=odoo/.eslintrc.yml - --ignore-path=odoo/.eslintignore - - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.2 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear] - args: - - --config=odoo/.flake8 - + - 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.29.0 + hooks: + - id: pyupgrade + args: ["--keep-percent-format"] - repo: https://github.com/PyCQA/isort - rev: 5.5.1 + rev: 5.9.3 hooks: - id: isort - name: isort + name: isort except __init__.py + exclude: /__init__\.py$ args: - --settings=odoo/ - + - repo: https://gitlab.com/PyCQA/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + name: flake8 + additional_dependencies: ["flake8-bugbear==21.9.2"] + args: + - --config=odoo/.flake8 - repo: https://github.com/PyCQA/pylint - rev: pylint-2.5.3 + rev: v2.11.1 hooks: - id: pylint - name: pylint + name: pylint with optional checks args: - --rcfile=odoo/.pylintrc - --exit-zero verbose: true additional_dependencies: &pylint_deps - - pylint-odoo==5.0.0 + - pylint-odoo==5.0.4 + - id: pylint + name: pylint with mandatory checks + args: + - --rcfile=odoo/.pylintrc-mandatory + additional_dependencies: *pylint_deps diff --git a/odoo/.pylintrc b/odoo/.pylintrc index cc33682..a5eece0 100644 --- a/odoo/.pylintrc +++ b/odoo/.pylintrc @@ -3,7 +3,6 @@ load-plugins=pylint_odoo score=n [ODOOLINT] -readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" manifest_required_keys=license manifest_deprecated_keys=description,active license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 @@ -11,6 +10,13 @@ license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later [MESSAGES CONTROL] disable=all +# This .pylintrc contains optional AND mandatory checks and is meant to be +# loaded in an IDE to have it check everything, in the hope this will make +# optional checks more visible to contributors who otherwise never look at a +# green travis to see optional checks that failed. +# .pylintrc-mandatory containing only mandatory checks is used the pre-commit +# config as a blocking check. + enable=anomalous-backslash-in-string, api-one-deprecated, api-one-multi-together, @@ -19,6 +25,7 @@ enable=anomalous-backslash-in-string, class-camelcase, dangerous-default-value, dangerous-view-replace-wo-priority, + development-status-allowed, duplicate-id-csv, duplicate-key, duplicate-xml-fields, @@ -35,8 +42,6 @@ enable=anomalous-backslash-in-string, method-inverse, method-required-super, method-search, - missing-import-error, - missing-manifest-dependency, openerp-exception-warning, pointless-statement, pointless-string-statement, @@ -54,7 +59,56 @@ enable=anomalous-backslash-in-string, unreachable, use-vim-comment, wrong-tabs-instead-of-spaces, - xml-syntax-error + xml-syntax-error, + attribute-string-redundant, + character-not-valid-in-resource-link, + consider-merging-classes-inherited, + context-overridden, + create-user-wo-reset-password, + dangerous-filter-wo-user, + dangerous-qweb-replace-wo-priority, + deprecated-data-xml-node, + deprecated-openerp-xml-node, + duplicate-po-message-definition, + except-pass, + file-not-used, + invalid-commit, + manifest-maintainers-list, + missing-newline-extrafiles, + missing-readme, + missing-return, + odoo-addons-relative-import, + old-api7-method-defined, + po-msgstr-variables, + po-syntax-error, + renamed-field-parameter, + resource-not-exist, + str-format-used, + test-folder-imported, + translation-contains-variable, + translation-positional-used, + unnecessary-utf8-coding-comment, + website-manifest-key-not-valid-uri, + xml-attribute-translatable, + xml-deprecated-qweb-directive, + xml-deprecated-tree-attribute, + # messages that do not cause the lint step to fail + consider-merging-classes-inherited, + create-user-wo-reset-password, + dangerous-filter-wo-user, + deprecated-module, + file-not-used, + invalid-commit, + missing-manifest-dependency, + missing-newline-extrafiles, + missing-readme, + no-utf8-coding-comment, + odoo-addons-relative-import, + old-api7-method-defined, + redefined-builtin, + too-complex, + unnecessary-utf8-coding-comment + [REPORTS] msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} diff --git a/odoo/.pylintrc-mandatory b/odoo/.pylintrc-mandatory new file mode 100644 index 0000000..e72e587 --- /dev/null +++ b/odoo/.pylintrc-mandatory @@ -0,0 +1,92 @@ +[MASTER] +load-plugins=pylint_odoo +score=n + +[ODOOLINT] +manifest_required_keys=license +manifest_deprecated_keys=description,active +license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 + +[MESSAGES CONTROL] +disable=all + +enable=anomalous-backslash-in-string, + api-one-deprecated, + api-one-multi-together, + assignment-from-none, + attribute-deprecated, + class-camelcase, + dangerous-default-value, + dangerous-view-replace-wo-priority, + development-status-allowed, + duplicate-id-csv, + duplicate-key, + duplicate-xml-fields, + duplicate-xml-record-id, + eval-referenced, + eval-used, + incoherent-interpreter-exec-perm, + license-allowed, + manifest-author-string, + manifest-deprecated-key, + manifest-required-key, + manifest-version-format, + method-compute, + method-inverse, + method-required-super, + method-search, + openerp-exception-warning, + pointless-statement, + pointless-string-statement, + print-used, + redundant-keyword-arg, + redundant-modulename-xml, + reimported, + relative-import, + return-in-init, + rst-syntax-error, + sql-injection, + too-few-format-args, + translation-field, + translation-required, + unreachable, + use-vim-comment, + wrong-tabs-instead-of-spaces, + xml-syntax-error, + attribute-string-redundant, + character-not-valid-in-resource-link, + consider-merging-classes-inherited, + context-overridden, + create-user-wo-reset-password, + dangerous-filter-wo-user, + dangerous-qweb-replace-wo-priority, + deprecated-data-xml-node, + deprecated-openerp-xml-node, + duplicate-po-message-definition, + except-pass, + file-not-used, + invalid-commit, + manifest-maintainers-list, + missing-newline-extrafiles, + missing-readme, + missing-return, + odoo-addons-relative-import, + old-api7-method-defined, + po-msgstr-variables, + po-syntax-error, + renamed-field-parameter, + resource-not-exist, + str-format-used, + test-folder-imported, + translation-contains-variable, + translation-positional-used, + unnecessary-utf8-coding-comment, + website-manifest-key-not-valid-uri, + xml-attribute-translatable, + xml-deprecated-qweb-directive, + xml-deprecated-tree-attribute + +[REPORTS] +msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} +output-format=colorized +reports=no