OCA / pylint-odoo

Odoo plugin for Pylint
http://www.pylint.org
143 stars 168 forks source link

Validate method call inside t-foreach loop #299

Closed oscarolar closed 3 years ago

oscarolar commented 3 years ago

Validate if a method that always returns the same result is called inside a t-foreach loop to avoid unnecessary method calls and performance issues.

This is an obvious thing for some experienced programmers but not for the newbies, here is an example of what should't be done

<t t-foreach="attributes" t-as="attribute">
    <t t-set="so" t-value="request.website.sale_get_order()"/>
    #
    # do something with the so variable.
    #
</t>     

what to do:

<t t-set="so" t-value="request.website.sale_get_order()"/>
<t t-foreach="attributes" t-as="attribute">
    #
    # do something with the so variable.
    #
</t>     

The conditions that the lint should met are:

moylop260 commented 3 years ago

It is a good check

But it is hard to make this check from pylint

Since that it is using a combination of many languages python, xml, html, js, qweb

QWeb is a custom Odoo parser xml2python:

It could require transform it to astroid/pylint format but it is not an easy way to do

Feel free to re-open or discuss it