Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions src/oca_pre_commit_hooks/node_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions test_repo/odoo18_module/views/deprecated_qweb_directives15.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Deprecated QWeb directive 15 "t-esc" and "t-raw" -->
<!-- Deprecated QWeb directive 15 "t-esc" and "t-raw" autofixed with "t-out" -->
<template id="test_template_15" name="Test Template 15">
<div>
<span t-esc="price" />
Expand All @@ -10,8 +10,14 @@
<template id="test_template_15_2" name="test_template_15_2">
<div class="mt32">
<div class="text-left">
<strong>Name <t t-esc="o.name" /></strong>
<strong>Name <t
t-esc="o.name"
/>
</strong>
</div>
</div>
<p class="col"><strong>Line Template:</strong> <t
t-esc="lead.template_line_id.name"
/></p>
</template>
</odoo>
5 changes: 5 additions & 0 deletions test_repo/test_module/website_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<textarea name="fixed" t-out="campaign.description" />
<!--prettier compatible-->
<textarea name="mixed"> Ver: <t t-out="campaign.url" /></textarea>
<li>text<strong
t-out="o.name"
t-options="{&quot;widget&quot;: &quot;float&quot;, &quot;precision&quot;: 2}"
/>
</li>
</template>

<!-- Deprecated QWeb directive "t-field-options". -->
Expand Down
11 changes: 7 additions & 4 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"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": 3,
"xml-double-quotes-py": 4,
"xml-duplicate-fields": 3,
"xml-duplicate-record-id": 2,
"xml-not-valid-char-link": 2,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"
Loading