OCA / odoo-pre-commit-hooks

Linters of Odoo addons that complement pylint-odoo
GNU Affero General Public License v3.0
9 stars 11 forks source link

[ADD] xml-xpath-translatable-item: Add new check to identify mutable item used from xpath #50

Closed moylop260 closed 1 year ago

moylop260 commented 1 year ago

[ADD] xml-xpath-translatable-item: Add new check to identify mutable item used from xpath

Using the following xpath:

<xpath expr="//div[contains(text(), 'Translatable String')]/more/path" position="attributes">
    <attribute name="t-if">o.value</attribute>
</xpath>

It will raise error if the lang is changed since that the text is a translatable item

You should use no-mutable items in the xpath

e.g. id, name

e.g. https://github.com/odoo/odoo/blob/57544f3b40d26e5c131cf4e3a2b0396a22b61bc6/addons/l10n_ae_pos/__manifest__.py#L12

e.g. https://github.com/odoo/odoo/blob/ae0a11a8ce3c35542ba5ae8f6366018b88ec40d5/addons/l10n_ae_pos/__manifest__.py#L14-L18

luisg123v commented 1 year ago

Instead of mutable, I'd name it translatable. Odoo has a native check to prevent filtering by string

moylop260 commented 1 year ago

@tde-banana-odoo

FYI a case was detected in odoo core of this lint check:

addons/l10n_ae_pos/static/src/xml/Screens/ReceiptScreen/OrderReceipt.xml:4 Use of translatable xpath `text()` - [xml-xpath-translatable-item]

Related to https://github.com/odoo/odoo/blob/f2be38bbd3a65bbc529d50486e50edee75e8b471/addons/l10n_ae_pos/static/src/xml/Screens/ReceiptScreen/OrderReceipt.xml#L4

tde-banana-odoo commented 1 year ago

Hello @moylop260 ,

Thanks for pointing it out :) a PR has been done to fix it at https://github.com/odoo/odoo/pull/104686 .

Cheers !