From deb61506fcbafb754186762568064b95d326663b Mon Sep 17 00:00:00 2001 From: "Moises Lopez - https://www.vauxoo.com/" Date: Tue, 27 Jan 2026 00:04:19 -0600 Subject: [PATCH 1/2] [FIX] xml-double-quotes-py,xml-deprecated-qweb-directive-15: Consider multiple tags in the same line and multi-line tags --- README.md | 10 +++++----- src/oca_pre_commit_hooks/node_xml.py | 8 +++++--- .../views/deprecated_qweb_directives15.xml | 7 +++++-- test_repo/test_module/website_templates.xml | 5 +++++ tests/test_checks.py | 9 ++++++--- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7f3bb8dc..1a574af1 100644 --- a/README.md +++ b/README.md @@ -456,13 +456,13 @@ options: * xml-deprecated-qweb-directive - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L7 Deprecated QWeb directive `t-esc-options`. Use `t-options` instead - - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L37 Deprecated QWeb directive `t-field-options`. Use `t-options` instead + - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L42 Deprecated QWeb directive `t-field-options`. Use `t-options` instead * xml-deprecated-qweb-directive-15 - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml#L6 Deprecated QWeb directive `t-esc`. Use `t-out` instead - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml#L7 Deprecated QWeb directive `t-raw`. Use `t-out` instead - - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml#L13 Deprecated QWeb directive `t-esc`. Use `t-out` instead + - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml#L15 Deprecated QWeb directive `t-esc`. Use `t-out` instead * xml-deprecated-tree-attribute @@ -523,14 +523,14 @@ options: * xml-not-valid-char-link - - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L59 The resource in in src/href contains a not valid character - - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L61 The resource in in src/href contains a not valid character + - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L64 The resource in in src/href contains a not valid character + - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L66 The resource in in src/href contains a not valid character * xml-oe-structure-missing-id - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L9 Consider removing the class `oe_structure` or adding a proper id to the tag. The id must contain `oe_structure` - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L13 Consider removing the class `oe_structure` or adding a proper id to the tag. The id must contain `oe_structure` - - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L41 Consider removing the class `oe_structure` or adding a proper id to the tag. The id must contain `oe_structure` + - https://github.com/OCA/odoo-pre-commit-hooks/blob/v0.2.20/test_repo/test_module/website_templates.xml#L46 Consider removing the class `oe_structure` or adding a proper id to the tag. The id must contain `oe_structure` * xml-record-missing-id diff --git a/src/oca_pre_commit_hooks/node_xml.py b/src/oca_pre_commit_hooks/node_xml.py index a1726cf3..15bdb34c 100644 --- a/src/oca_pre_commit_hooks/node_xml.py +++ b/src/oca_pre_commit_hooks/node_xml.py @@ -29,7 +29,7 @@ def _read_node(self): # noqa:C901 pylint:disable=too-complex if (node_previous := self.node.getprevious()) is not None: search_start_line = node_previous.sourceline + 1 elif (node_parent := self.node.getparent()) is not None: - search_start_line = node_parent.sourceline + 1 + search_start_line = node_parent.sourceline else: search_start_line = 2 # first element and it is the root @@ -40,12 +40,14 @@ def _read_node(self): # noqa:C901 pylint:disable=too-complex with open(self.filename, "rb") as f_content: all_lines = list((i, line) for i, line in enumerate(f_content, start=1)) + search_start_line = min(search_start_line, search_end_line) + # Find the actual node start by looking for the tag node_start_idx = None for idx, (no_line, line) in enumerate(all_lines): if search_start_line <= no_line <= search_end_line: stripped_line = line.lstrip() - if stripped_line.startswith(b"<" + node_tag): + if b"<" + node_tag in stripped_line: node_start_idx = idx self.start_sourceline = no_line break @@ -82,7 +84,7 @@ def _read_node(self): # noqa:C901 pylint:disable=too-complex node_end_idx = idx self.end_sourceline = no_line break - if b"/>" in stripped_line and not stripped_line.startswith(b"<"): + if b"/>" in stripped_line and b"<" not in stripped_line: # Self-closing continuation node_end_idx = idx self.end_sourceline = no_line diff --git a/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml b/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml index 8e1e8554..8763a9bd 100644 --- a/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml +++ b/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml @@ -1,6 +1,6 @@ - + diff --git a/tests/test_checks.py b/tests/test_checks.py index 65a413a1..21ebc59f 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -38,7 +38,7 @@ "xml-deprecated-qweb-directive-15": 3, "xml-deprecated-qweb-directive": 2, "xml-deprecated-tree-attribute": 3, - "xml-double-quotes-py": 3, + "xml-double-quotes-py": 4, "xml-duplicate-fields": 3, "xml-duplicate-record-id": 2, "xml-not-valid-char-link": 2, @@ -258,7 +258,8 @@ def test_autofix(self): with open(t_out, "rb") as f: content = f.read() - assert b"t-out" not in content, "The deprecated t-out was previously fixed" + assert content.count(b"t-esc") > 1, "The deprecated t-esc was previously fixed" + assert content.count(b"t-raw") > 1, "The deprecated t-raw was previously fixed" self.checks_run(self.file_paths, autofix=True, no_exit=True, no_verbose=False) @@ -343,4 +344,6 @@ def test_autofix(self): with open(t_out, "rb") as f: content = f.read() - assert b"t-out" in content, "The deprecated t-out was not fixed" + # comments contain 1 valid deprecated + assert content.count(b"t-esc") == 1, "The deprecated t-esc was not fixed" + assert content.count(b"t-raw") == 1, "The deprecated t-esc was not fixed" From 1b50b103e8cbc7c260a61493b5bd309ac9bf7c8b Mon Sep 17 00:00:00 2001 From: "Moises Lopez - https://www.vauxoo.com/" Date: Tue, 27 Jan 2026 11:10:49 -0600 Subject: [PATCH 2/2] [REF] tests: Add new corner case --- test_repo/odoo18_module/views/deprecated_qweb_directives15.xml | 3 +++ tests/test_checks.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml b/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml index 8763a9bd..d989026e 100644 --- a/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml +++ b/test_repo/odoo18_module/views/deprecated_qweb_directives15.xml @@ -16,5 +16,8 @@ +

Line Template:

diff --git a/tests/test_checks.py b/tests/test_checks.py index 21ebc59f..cca714c2 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -35,7 +35,7 @@ "xml-dangerous-qweb-replace-low-priority": 9, "xml-deprecated-data-node": 8, "xml-deprecated-openerp-node": 4, - "xml-deprecated-qweb-directive-15": 3, + "xml-deprecated-qweb-directive-15": 4, "xml-deprecated-qweb-directive": 2, "xml-deprecated-tree-attribute": 3, "xml-double-quotes-py": 4,