Skip to main content

odoo-pre-commit-hooks to use in pre-commit-config.yml files

Project description

Build Status codecov version wheel supported-versions commits-since code-style-black

odoo-pre-commit-hooks

OCA's custom pre-commit hooks for Odoo modules

Installation

You don't need to install it directly only configure your ".pre-commit-config.yaml" file

You even can install it directly:

  • Installing from pypi:

    • pip install -U oca-odoo-pre-commit-hooks
  • Installing from github:

    • pip install --force-reinstall -U git+https://github.com/OCA/odoo-pre-commit-hooks.git@main

Usage pre-commit-config.yaml

Add to your ".pre-commit-config.yaml" configuration file the following input

    - repo: https://github.com/OCA/odoo-pre-commit-hooks
        rev: v0.0.14
        hooks:
        - id: oca-checks-odoo-module
        - id: oca-checks-po

Usage directly the entry points

If you install directly the package use the entry point:

oca-checks-odoo-module --help
oca-checks-po --help

Skip one xml-check for only one file

If you need to skip one check in one particular XML file you can use the follow comment

<?xml version="1.0" encoding="utf-8"?>
<!-- oca-hooks:disable=xml-check-to-skip -->
<odoo>
...
</odoo>
<?xml version="1.0" encoding="utf-8"?>
<!-- oca-hooks:disable=xml-check-to-skip,
                       xml-check-to-skip2 -->
<odoo>
...
</odoo>

The position of the comment it is not relative to the line that throw the check

It disable the entire file

Checks

  • Check manifest-syntax-error Check if the manifest file has syntax error

  • Check csv-duplicate-record-id duplicate CSV "id" AKA xmlid but for CSV files

  • Check csv-syntax-error Check syntax error for CSV files declared in the manifest

  • Check xml-dangerous-qweb-replace-low-priority Dangerous qweb view defined with low priority

  • Check xml-deprecated-data-node Deprecated node inside xml node

  • Check xml-deprecated-openerp-node deprecated xml node

  • Check xml-deprecated-qweb-directive for use of deprecated QWeb directives t-*-options

  • Check xml-not-valid-char-link The resource in in src/href contains a not valid character.

  • Check xml-redundant-module-name

      If the module is called "module_a" and the xmlid is
      `<record id="module_a.xmlid_name1" ...`
    
      The "module_a." is redundant it could be replaced to only
      `<record id="xmlid_name1" ...`
    
  • Check xml-dangerous-filter-wo-user Check dangerous filter without a user assigned.

  • Check xml-create-user-wo-reset-password records of user without context="{'no_reset_password': True}" This context avoid send email and mail log warning

  • Check xml-view-dangerous-replace-low-priority in ir.ui.view

          <field name="priority" eval="10"/>
          ...
              <field name="name" position="replace"/>
    
  • Check xml-deprecated-tree-attribute The tree-view declaration is using a deprecated attribute.

  • Check xml-duplicate-record-id

      If a module has duplicated record_id AKA xml_ids
      file1.xml
          <record id="xmlid_name1"
      file2.xml
          <record id="xmlid_name1"
    
  • Check xml-duplicate-fields in all record nodes <record id="xmlid_name1"... <field name="field_name1"... <field name="field_name1"...

  • Check xml-syntax-error Check syntax of XML files declared in the Odoo manifest

Checks PO

  • Check po-requires-module Translation entry requires comment #. module: MODULE

  • Check po-python-parse-printf Check if msgid is using str variables like %s So translation msgstr must be the same number of variables too

  • Check po-python-parse-format Check if msgid is using str variables like {} So translation msgstr must be the same number of variables too

  • Check po-duplicate-message-definition (message-id) in all entries of PO files

      We are not using `check_for_duplicates` parameter of polib.pofile method
          e.g. `polib.pofile(..., check_for_duplicates=True)`
      Because the output is:
          `raise ValueError('Entry "%s" already exists' % entry.msgid)`
      It doesn't show the number of lines duplicated
      and it shows the entire string of the message_id without truncating it
      or replacing newlines
    
  • Check po-syntax-error Check syntax of PO files from i18n* folders

Help

usage: oca-checks-odoo-module [-h] [--no-verbose] [--no-exit]
                              [--disable DISABLE] [--enable ENABLE]
                              [--config CONFIG]
                              [files_or_modules ...]

positional arguments:
  files_or_modules      Odoo __manifest__.py paths or Odoo module paths.

options:
  -h, --help            show this help message and exit
  --no-verbose          If enabled so disable verbose mode.
  --no-exit             If enabled so it will not call exit.
  --disable DISABLE, -d DISABLE
                        Disable the checker with the given 'check-name',
                        separated by commas.
  --enable ENABLE, -e ENABLE
                        Enable the checker with the given 'check-name',
                        separated by commas. Default: All checks are enabled
                        by default
  --config CONFIG, -c CONFIG
                        Path to a configuration file

Help PO

usage: oca-checks-po [-h] [--no-verbose] [--no-exit] [--disable DISABLE]
                     [--enable ENABLE] [--config CONFIG]
                     [po_files ...]

positional arguments:
  po_files              PO files.

options:
  -h, --help            show this help message and exit
  --no-verbose          If enabled so disable verbose mode.
  --no-exit             If enabled so it will not call exit.
  --disable DISABLE, -d DISABLE
                        Disable the checker with the given 'check-name',
                        separated by commas.
  --enable ENABLE, -e ENABLE
                        Enable the checker with the given 'check-name',
                        separated by commas. Default: All checks are enabled
                        by default
  --config CONFIG, -c CONFIG
                        Path to a configuration file

Examples

Examples PO

Licenses

This repository is licensed under AGPL-3.0.


OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

CHANGES

v0.0.14

  • Bump version: 0.0.13 → 0.0.14
  • [IMP] oca_pre_commit_hooks: Support for config file (#41)

v0.0.13

  • Bump version: 0.0.12 → 0.0.13
  • [REF] pylint_odoo: Remove TODO comments (#47)
  • [REF] requirements: Remove unused libraries and pre-commit hooks (#45)
  • [REF] xml-deprecated-data-node: Use the data node sourceline instead of odoo node (#43)
  • [IMP] oca_pre_commit_hooks: Support disable XML checks from disable comments (#42)
  • [REF] README: Fix name of pypi package (#35)
  • [REF] oca_pre_commit_hooks: cli_po, cli: Add cli_po and cli global (#36)
  • [REF] setup: Match requires-python = ">=3.7" from pre-commit
  • [REF] CI: Enable py3.11

v0.0.12

  • Bump version: 0.0.11 → 0.0.12
  • [REF] checks_odoo_module_xml: Allow duplicated fields with 'groups' (#32)
  • [REF] CI: Enable tox with parallels + codecov compatibility (#33)

v0.0.11

  • Bump version: 0.0.10 → 0.0.11
  • [REF] codecov: Enable codecov again
  • [REM] missing-readme: Check add to pylint-odoo
  • [REF] TOX: Strip names, remove no-cover, compatible with parallels option (#24)
  • [REF] lint: Adapt lints for py packages instead of odoo module (#23)

v0.0.10

  • Bump version: 0.0.9 → 0.0.10
  • [REF] README: Update README and fix mutable results auto-generating it (#22)
  • [REF] checks_odoo_module_po: Run on modified PO files only (#21)
  • [REF] manifest: Skip duplicated data files (#20)

v0.0.9

  • Bump version: 0.0.8 → 0.0.9
  • [FIX] README: Fix regex to replace autogenerated content (#18)
  • [REF] README: Detect from CI if README needs to be updated (#17)

v0.0.8

  • Bump version: 0.0.7 → 0.0.8
  • [REF] README: Add examples of checks section and script to auto-generate it (#16)
  • [REF] README: Add help section and script to auto-generate it (#15)

v0.0.7

  • Bump version: 0.0.6 → 0.0.7
  • [REF] checks: name_checks changed to name-checks (#14)
  • [REF] oca_pre_commit_hooks: Use shorter path in messages (#13)
  • [FIX] pre-commit-hooks.yaml: Run checks even if the manifest was not changed
  • [REF] test: Remove TODO comments already fixed

v0.0.6

  • Bump version: 0.0.5 → 0.0.6
  • [FIX] oca_pre_commit_hooks: Fix checks if it has syntax error (#8)

v0.0.5

  • Bump version: 0.0.4 → 0.0.5
  • [REF] oca_pre_commit_hooks: Small improvements (#7)

v0.0.4

  • Bump version: 0.0.3 → 0.0.4
  • [IMP] oca_pre_commit_hooks: Enable feature to 'enable' checks (#6)
  • [IMP] oca_pre_commit_hooks: Add entrypoint arguments to disable checks (#5)

v0.0.3

  • Bump version: 0.0.2 → 0.0.3
  • [REF] README: Remove deprecated CI build

v0.0.2

  • Bump version: 0.0.1 → 0.0.2
  • [REF] CI: Re-use tox to run pre-commit in the CI with same caches and packages
  • [ADD] .pre-commit-hooks.yaml: Compatible with pre-commit-hooks to use as hook id directly

v0.0.1

  • [ADD] Migrate pylint-odoo checks (not related to python) to pre-commit hooks (#2)
  • Initialize

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oca-odoo-pre-commit-hooks-0.0.14.tar.gz (36.1 kB view hashes)

Uploaded Source

Built Distribution

oca_odoo_pre_commit_hooks-0.0.14-py3-none-any.whl (35.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page