GithubHelp home page GithubHelp logo

pylint-odoo's Introduction

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

Pylint Odoo plugin

Enable custom checks for Odoo modules.

Short Name Description Code
attribute-deprecated attribute "%s" deprecated W8105
attribute-string-redundant The attribute string is redundant. String parameter equal to name of variable W8113
bad-builtin-groupby Used builtin function itertools.groupby. Prefer odoo.tools.groupby instead. More info about odoo/odoo#105376 W8155
category-allowed Category "%s" not allowed in manifest file. C8114
consider-merging-classes-inherited Consider merging classes inherited to "%s" from %s. R8180
context-overridden Context overridden using dict. Better using kwargs with_context(**%s) or with_context(key=value) W8121
deprecated-odoo-model-method %s has been deprecated by Odoo. Please look for alternatives. W8160
development-status-allowed Manifest key development_status "%s" not allowed. Use one of: %s. C8111
except-pass pass into block except. If you really need to use the pass consider logging that exception W8138
external-request-timeout Use of external request method %s without timeout. It could wait for a long time E8106
invalid-commit Use of cr.commit() directly - More info https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#never-commit-the-transaction E8102
license-allowed License "%s" not allowed in manifest file. C8105
manifest-author-string The author key in the manifest file must be a string (with comma separated values) E8101
manifest-behind-migrations Manifest version (%s) is lower than migration scripts (%s) E8145
manifest-data-duplicated The file "%s" is duplicated in lines %s from manifest key "%s" W8125
manifest-deprecated-key Deprecated key "%s" in manifest file C8103
manifest-maintainers-list The maintainers key in the manifest file must be a list of strings E8104
manifest-required-author One of the following authors must be present in manifest: %s C8101
manifest-required-key Missing required key "%s" in manifest file C8102
manifest-version-format Wrong Version Format "%s" in manifest file. Regex to match: "%s" C8106
method-compute Name of compute method should start with "compute" C8108
method-inverse Name of inverse method should start with "inverse" C8110
method-required-super Missing super call in "%s" method. W8106
method-search Name of search method should start with "search" C8109
missing-readme Missing ./README.rst file. Template here: %s C8112
missing-return Missing return (super is used) in method %s. W8110
no-raise-unlink No exceptions should be raised inside unlink() functions E8140
no-wizard-in-models No wizard class for model directory. See the complete structure https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#complete-structure C8113
no-write-in-compute Compute method calling write. Use update instead. E8135
odoo-addons-relative-import Same Odoo module absolute import. You should use relative import with "." instead of "odoo.addons.%s" W8150
odoo-exception-warning odoo.exceptions.Warning is a deprecated alias to odoo.exceptions.UserError use from odoo.exceptions import UserError R8101
print-used Print used. Use logger instead. W8116
prohibited-method-override Prohibited override of "%s" method. W8107
renamed-field-parameter Field parameter "%s" is no longer supported. Use "%s" instead. W8111
resource-not-exist File "%s": "%s" not found. F8101
sql-injection SQL injection risk. Use parameters if you can. - More info https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#no-sql-injection E8103
test-folder-imported Test folder imported in module %s E8130
translation-contains-variable Translatable term in "%s" contains variables. Use %s instead W8115
translation-field Translation method _("string") in fields is not necessary. W8103
translation-format-interpolation Use %s formatting in odoo._ functions W8302
translation-format-truncated Logging format string ends in middle of conversion specifier E8301
translation-fstring-interpolation Use %s formatting in odoo._ functions W8303
translation-not-lazy Use %s formatting in odoo._ functions W8301
translation-positional-used Translation method _(%s) is using positional string printf formatting. Use named placeholder _("%%(placeholder)s") instead. W8120
translation-required String parameter on "%s" requires translation. Use %s_(%s) C8107
translation-too-few-args Not enough arguments for odoo._ format string E8306
translation-too-many-args Too many arguments for odoo._ format string E8305
translation-unsupported-format Unsupported odoo._ format character %r (%#02x) at index %d E8300
use-vim-comment Use of vim comment W8202
website-manifest-key-not-valid-uri Website "%s" in manifest key is not a valid URI W8114

Install

You do not need to install manually if you use pre-commit-config

But if you even need to install it

pip install pylint-odoo

Usage pre-commit-config.yaml

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

    - repo: https://github.com/OCA/pylint-odoo
        rev: v9.1.2 # may be a tag or commit hash
        hooks:
        # Add to your .pylintrc file:
        # [MASTER]
        # load-plugins=pylint_odoo
        - id: pylint_odoo

Usage

pylint --load-plugins=pylint_odoo -e odoolint path/to/test

or use configuration file you can generate the OCA one using the following template repository:

https://github.com/OCA/oca-addons-repo-template

Then running

pylint --rcfile=.pylintrc path/to/test

Example to test only pylint_odoo checks:

pylint --load-plugins=pylint_odoo -d all -e odoolint {ADDONS-PATH}/*

There are checks only valid for a particular Odoo version To know what version of odoo are you running pylint needs the parameter

pylint --load-plugins=pylint_odoo --valid-odoo-versions={YOUR_ODOO_VERSION}

with particular odoo version e.g. "16.0"

Checks valid only for odoo >= 14.0

translation-format-interpolation
translation-format-truncated
translation-fstring-interpolation
translation-not-lazy
translation-too-few-args
translation-too-many-args
translation-unsupported-format

Checks valid only for odoo <= 13.0

translation-contains-variable

Examples

Development

To run all the tests run:

tox

Use extra parameters to change the test behaviour

e.g. particular python version

tox -e py310

e.g. particular unittest method

tox -e py310 -- -k test_20_expected_errors

e.g. all the tests at the same time in parallel

tox -p auto

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.

pylint-odoo's People

Contributors

aleuffre avatar antonag32 avatar bizzappdev avatar dreispt avatar fernandahf avatar guewen avatar hbrunn avatar hugosantosred avatar joao-p-marques avatar johnw-bluemark avatar lasley avatar lmignon avatar luisg123v avatar max3903 avatar miquelrforgeflow avatar moylop260 avatar naglis avatar nhomar avatar nilshamerlinck avatar oca-git-bot avatar pedrobaeza avatar pexers avatar rven avatar shepilov-vladislav avatar stefanrijnhart avatar thomasbinsfeld avatar tmotyl avatar tomeyro avatar yajo avatar yvaucher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pylint-odoo's Issues

Ignore has no 'id' member (no-member)

How can I ignore has no 'id' member ?

************* Module my_module.contact
W:100, 0: TODO: rename this field (fixme)	
C: 46, 0: Line too long (102/100) (line-too-long)
C: 63, 0: Line too long (108/100) (line-too-long)
C: 70, 0: Line too long (104/100) (line-too-long)
C: 72, 0: Line too long (114/100) (line-too-long)
C: 15, 0: Invalid constant name "_logger" (invalid-name)
E:197,19: Instance of 'Contact' has no 'id' member (no-member) <<<<<
E:223,55: Instance of 'Contact' has no 'id' member (no-member) <<<<

The odoo code looks like:

 class Contact(models.Model):
      ......
      if self.id in agreement_ids:

W7907 %s Duplicate xml field "%s" in lines %s duplicate-xml-fields

This error should be reduced to informational or ignored in demo data xml files. It is entirely legitimate and occasionally necessary to have duplicate xml-ids, even if 99% of the time it is an error.

Sometimes, such as when dealing with products, product templates and attributes you need to create circular references in order to trigger ORM create functions correctly and get around required fields of each model.

The method message_post need the subject and body be translatable

The method self.message_post need the parameter subject and body be translatable

For example, the follow method raise the check translation-required because the parameter subject and body not is instance of _ function

self.message_post(
    subject='Error when trying to generate the invoice',  # translation-required
    body='<h2>%s</h2><hr>%s</hr>' % (  # translation-required
        _('Error when trying to generate the invoice'),
        _('The invoice should have a datetime set.')))

The correct way to this code is the follow

self.message_post(
    subject=_('Error when trying to generate the invoice'),
    body=_('<h2>%s</h2><hr>%s</hr>' % (
        _('Error when trying to generate the invoice'),
        _('The invoice should have a datetime set.'))))

I can not have demo and data with the same xml id because the next error is displayed: [W7902(duplicate-xml-record-id), ] Duplicate xml record id

Error

I can not have demo and data record with a same xml id because the next error is displayed:

data/res_company.xml:4: [W7902(duplicate-xml-record-id), ]  Duplicate xml record id "base.main_company.noupdate0" in demo/res_company.xml

Steps to reproduce the error:

  1. I have two files: data/res_company.xml and demo/res_company.xml
  2. The main company is edited in both files:

data/res_company.xml

<record id="base.main_company" model="res.company">
     <field name="new_field_id" ref="module.reference_example_1"/>
</record>

demo/res_company.xml

<record id="base.main_company" model="res.company">
     <field name="example_field">300</field>
</record>

With this scene, the next error is displayed:

data/res_company.xml:4: [W7902(duplicate-xml-record-id), ]  Duplicate xml record id "base.main_company.noupdate0" in demo/res_company.xml

Conclusion

I think I can have data and demo with the same xml_id, it is valid.

I think this is a bug

duplicate-xml-fields in search views

The linter gives duplicate-xml-fields error in the case of this search view:

<search>
    <field name="employee_id" />
    <field name="department_id" string="Department (subordinates)" filter_domain="[]" context="{...some context...}" />
    <field name="department_id" context="{...some other context...}" />

Duplicate fields should however be allowed in search views. Sometimes you just want two different filters on the same field.

Why do you pin pylint to 1.4.4?

Just like the title said, is there any specific reason you are pinning pylint to 1.4.4 version or can I make a PR to allow use the latest available pylint version?

Support version 11.0

If a module is for 11.0, pylint fails with message Wrong Version Format "11.0.0.0.0" in manifest file

osx: No module named pylint_odoo

Macs-Mac-mini:odoo macuser$ sudo pip install --upgrade git+https://github.com/oca/pylint-odoo.git
Password:
The directory '/Users/macuser/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/macuser/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting git+https://github.com/oca/pylint-odoo.git
  Cloning https://github.com/oca/pylint-odoo.git to /tmp/pip-Oy0jCY-build
Requirement already up-to-date: pylint==1.4.4 in /Library/Python/2.7/site-packages (from pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: pylint-plugin-utils==0.2.3 in /usr/local/lib/python2.7/site-packages (from pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: docutils==0.12 in /Library/Python/2.7/site-packages (from pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: lxml>=2.3.2 in /usr/local/lib/python2.7/site-packages (from pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: Pygments==2.0.2 in /Library/Python/2.7/site-packages (from pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: restructuredtext-lint==0.12.2 in /usr/local/lib/python2.7/site-packages (from pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: logilab-common>=0.53.0 in /Library/Python/2.7/site-packages (from pylint==1.4.4->pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: six in /Library/Python/2.7/site-packages (from pylint==1.4.4->pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: astroid>=1.3.6 in /Library/Python/2.7/site-packages (from pylint==1.4.4->pylint-odoo==1.0.3.dev2)
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/site-packages (from logilab-common>=0.53.0->pylint==1.4.4->pylint-odoo==1.0.3.dev2)
Installing collected packages: pylint-odoo
  Found existing installation: pylint-odoo 1.0.3.dev2
    Uninstalling pylint-odoo-1.0.3.dev2:
      Successfully uninstalled pylint-odoo-1.0.3.dev2
  Running setup.py install for pylint-odoo
Successfully installed pylint-odoo-1.0.3.dev2
Macs-Mac-mini:odoo macuser$ pylint --load-plugins=pylint_odoo -e odoolint
Traceback (most recent call last):
  File "/usr/local/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/Library/Python/2.7/site-packages/pylint/__init__.py", line 23, in run_pylint
    Run(sys.argv[1:])
  File "/Library/Python/2.7/site-packages/pylint/lint.py", line 1242, in __init__
    linter.load_plugin_modules(self._plugins)
  File "/Library/Python/2.7/site-packages/pylint/lint.py", line 498, in load_plugin_modules
    module = modutils.load_module_from_name(modname)
  File "/Library/Python/2.7/site-packages/astroid/modutils.py", line 137, in load_module_from_name
    return load_module_from_modpath(dotted_name.split('.'), path, use_sys)
  File "/Library/Python/2.7/site-packages/astroid/modutils.py", line 179, in load_module_from_modpath
    mp_file, mp_filename, mp_desc = imp.find_module(part, path)
ImportError: No module named pylint_odoo
Macs-Mac-mini:odoo macuser$

odoo-pylint install issue: No module named tasks

I managed to install odoo-pylint in my local, but I can't install it on a server.

Environment where it does works (on a server):

  • Ubuntu 16.04.3 LTS
  • nodejs: v6.11.2
  • setuptools 36.2.7 from /usr/local/lib/python2.7/dist-packages (Python 2.7)
  • pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
  • pbr 3.0.0
  • pylint==1.6.4
  • pylint-plugin-utils==0.2.4
  • npm eslint --version # 3.10.10

Environment where it works (in my local):

  • Ubuntu 16.04.3 LTS
  • nodejs: v6.11.2
  • setuptools 36.2.7 from /usr/local/lib/python2.7/dist-packages (Python 2.7)
  • pip 9.0.1
  • pbr 3.0.0
  • pylint==1.6.4
  • pylint-plugin-utils==0.2.4
  • npm eslint --version # 3.10.10
  • pylint-odoo==1.8.1.dev4

I face the same error with both installation commands

  • pip install --upgrade --pre pylint-odoo
  • pip install --upgrade git+https://github.com/oca/pylint-odoo.git

Finally, I tried to install from the source and get the same error:

╰─➤ sudo pip install -e . 
The directory '/home/myuser/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/myuser/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Obtaining file:///home/myuser/git-pylint-odoo/pylint-odoo 

Complete output from command python setup.py egg_info: 
ERROR:root:Error parsing 
Traceback (most recent call last): 
File "/usr/local/lib/python2.7/dist-packages/pbr/core.py", line 111, in pbr 
attrs = util.cfg_to_args(path, dist.script_args) 
File "/usr/local/lib/python2.7/dist-packages/pbr/util.py", line 267, in cfg_to_args wrap_commands(kwargs) 
File "/usr/local/lib/python2.7/dist-packages/pbr/util.py", line 569, in wrap_commands cmdclass = ep.resolve() 
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2322, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) 
ImportError: No module named tasks 
error in setup command: Error parsing /home/myuser/git-pylint-odoo/pylint-odoo/setup.cfg: ImportError: No module named tasks ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /home/myuser/git-pylint-odoo/pylint-odoo/ 

Thanks in advance for your help :)

Cannot specify valid_odoo_versions as option to pylint from CLI

This was still available in 1.8.2
In 1.9.3 it is not working

If we call pylint as

pylint --valid_odoo_versions=$ODOO_VERSION

then pylint should check addon version only against specified odoo version or versions

For example, we have addon with version 9.0.0.0.1 and if we run pylint_odoo for it as:

pylint --valid_odoo_versions=10.0

then pylint have to display message about wrong version format.

This will help to control correct addon versions via CI, because without this feature, when some addon is supported on multiple versions of odoo, sometimes it may have version '9.0.0.1.0' on branch '10.0', which is incorrect.

Things that may lead to this incorrect bechavior seems to be here - variable valid_odoo_versions simply redefined with default version list, making it impossible specify odoo version from pylint commandline.


Also this version have one more bug: if addon have not specified version, then pylint throws error with strange traceback:

Traceback (most recent call last):
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint/__init__.py", line 13, in run_pylint
    Run(sys.argv[1:])
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint/lint.py", line 1310, in __init__
    linter.check(args)
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint/lint.py", line 732, in check
    self._do_check(files_or_modules)
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint/lint.py", line 863, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint/lint.py", line 942, in check_astroid_module
    checker.process_tokens(tokens)
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint_odoo/checkers/format.py", line 94, in process_tokens
    self.add_message('no-utf8-coding-comment', line=1)
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint_odoo/misc.py", line 188, in add_message
    match = self.formatversion(version)
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/local/lib/python2.7/site-packages/pylint_odoo/misc.py", line 72, in formatversion
    return re.match(self.config.manifest_version_format_parsed, string)
  File "/home/katyukha/projects/OpenERP/odoo-10.0/venv/lib/python2.7/re.py", line 141, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or buffer

check 'website' manifest key is a valid URI

pypi checks the url key is a valid uri according to rfc3986, therefore addons with an invalid website key in the manifest cannot be published to pypi.

Hence, I'm suggesting the addition of the following check to pylint-odoo, similar to what pypi does:

import rfc3986

website = manifest.get('website')
uri = rfc3986.uri_reference(website)
if not uri.is_valid(require_scheme=True, require_authority=True):
    # error
if uri.scheme not in {"http", "https"}:
    # error

W7936 : False positive error

In my tests folder, I've several test files and a common one.

The common one is partly imported like 'from .common import ...' in tests files.

The pylint script returns the W7936 error ('missing external dependency) on one test file.

I have to import it like 'from . import common'

Add "Must bump version" check

This is a suggestion for a new check:

When doing a PR, it should bump the module's version should be bumped, either if we are porting, adding feature, or fixing code.
The check should run only for PRs.

Special case: some PR might not involve modules (e.g: changir .travis.yml) - in these case the check should not fail.

Crash with compute=None

Hi,

I have a case in which I want to change the behavior of a computed field to do a field that is not computed. So, I put compute=None and that works well.

Unfortunately this causes a problem with odoo-pylint like this

pylint_odoo/checkers/no_modules.py", line 295, in visit_call
not argument.value.value.startswith(
AttributeError: 'NoneType' object has no attribute 'startswith'

@moylop260 Do you have any comments about this one ?

Thanks,

Adrien

"Missing newline at end of file" check unwanted in some cases

Hello,

Sometime we have sample files to test import. Those file are integrated in the module and saved as they were generated. We don't want to alter them at all as they are reference file for test purpose.

Thus we should disable this check:

l10n_ch_account_statement_base_import/init.py:1: [W7908(missing-newline-extrafiles), ] data/UBS_export.csv Missing newline

Or provide a folder in module structure that isn't checked as it isn't odoo data but data to be processed by the module.

Or maybe we only want to check the files that are listed in the __openerp__.py

While we are searching for a solution I recommend to disable this check.

Example: https://travis-ci.org/OCA/l10n-switzerland/jobs/143363706

How to disable file-not-used warning for specific file

Hello,

I have a module which contains SQL script (module/script/script.sql) that are loaded directly from python code. With this case, the warning disable file-not-used is raised. Is it possible to ignore this one locally ?

Thanks,

Adrien

[ADD] xml-attribute-translatable: In order to avoid odoo/odoo#14497

History

We had the following issue odoo/odoo#14497
Fixed for odoo >= 9.0 but for odoo == 8.0 is a issue valid yet and we need add a flag like as: odoo/odoo#14497 (comment)

E.g. using the flag 8.0-odoo/addons/stock/product_view.xml#L11

This issue generated other one, we had technical items translated:
https://github.com/odoo/odoo/blob/8d724924f76a943035a8aa2d1b446418fd6b4034/addons/sale/i18n/es.po#L2152-L2155

Request

We need a new check to validate this case for 8.0 version (From MQT we choose the version enabled) in order to detect this case without a translatable flag.

[RFC] Tighten valid module version check

Currently, the following module versions will be considered as valid by pylint-odoo when using default configuration:

  • 10+0.1.0.0, because the dot from valid_odoo_versions is not escaped when building the valid module version pattern (and the . inside a regex matches any character other than a newline):
    def formatversion(self, string):
    self.config.manifest_version_format_parsed = \
    self.config.manifest_version_format % dict(
    valid_odoo_versions='|'.join(self.config.valid_odoo_versions))
    return re.match(self.config.manifest_version_format_parsed, string)
  • 10.0.1.0.0WHATEVER, because re.match is used inside formatversion(), which matches the string from the beginning, however, there is no $ at the end of the default value for manifest_version_format to match the end of the string:
    DFTL_MANIFEST_VERSION_FORMAT = r"(%(valid_odoo_versions)s)\.\d+\.\d+\.\d+"

    Thus, anything can follow once the version is matched from the beginning of the string.

I have started working on a fix, however, I have stumbled into a slight problem for which I need feedback from the authors - if a .pylintrc file is used with manifest_version_format defined inside it using the %(valid_odoo_versions)s placeholder, then manifest_version_format will be set automatically by ConfigParser (which pylint uses for configuration parsing) due to interpolation. This means that at the point when the manifest_version_format_parsed string is built:

def formatversion(self, string):
self.config.manifest_version_format_parsed = \
self.config.manifest_version_format % dict(
valid_odoo_versions='|'.join(self.config.valid_odoo_versions))
return re.match(self.config.manifest_version_format_parsed, string)

then self.config.manifest_version_format no longer contains the %(valid_odoo_versions)s placeholder, as it was already formatted by ConfigParser. This becomes a problem if we want to escape the dots from valid_odoo_versions (eg. 10.0 -> 10\.0) inside formatversion(), as our values will be simply ignored if a config file is used with manifest_version_format defined inside it using the %(valid_odoo_versions)s placeholder.

I have comeup with one solution - switch to str.format() style formatting for manifest_version_format in the config, which would allow to avoid interpolation by ConfigParser. However, I guess it would be a breaking change. So my question is - would it be ok?

Maybe someone has other suggestions?

Is there any way to locally disable file-not-used?

We have a really big data file, more than 9million records and is a must that we upload the information with our module.

Upload all that data into a database using the data field on manifiest takes ages, that's why we are uploading the information using plain queries. Is there any way to locally disable file-not-used only for that specific module?

EDIT: Forgot to said that already tried using # pylint: disable=file-not-used at the __openerp__.py file with no effect

Trailing comma on JSON objects not allowed

Some browsers are able to parse correctly the following:

        [{
            trigger: "a:contains(EN)",
            content: "Change Lang to EN",   
        },
        {
            trigger: "a:contains(ES)",
            content: "Change Lang to ES",   
            extra_trigger: "a[data-lang=en_US].active",
        },]

but the sad thing is we have to do it for all the browsers so the correct syntax would be:

        [{
            trigger: "a:contains(EN)",
            content: "Change Lang to EN",   
        },
        {
            trigger: "a:contains(ES)",
            content: "Change Lang to ES",   
            extra_trigger: "a[data-lang=en_US].active",
        }]

this is allowed from JSON5(specified in ES5) towards so the phantom browser does not handle it and errors can be caused on tests.

AttributeError: 'Getattr' object has no attribute 'name'

https://travis-ci.org/OCA/l10n-switzerland/jobs/143363706

Not sure why but we have pylint-odoo failing on multiple repositories.

Traceback (most recent call last):
  File "/home/travis/maintainer-quality-tools/travis/test_pylint", line 196, in <module>
    ] + modules_changed_cmd + extra_params_cmd, standalone_mode=False)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/travis/maintainer-quality-tools/travis/run_pylint.py", line 104, in main
    extra_params=extra_params)
  File "/home/travis/maintainer-quality-tools/travis/run_pylint.py", line 75, in run_pylint
    pylint_res = pylint.lint.Run(cmd, exit=False)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 1332, in __init__
    linter.check(args)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 747, in check
    self._do_check(files_or_modules)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 869, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 946, in check_astroid_module
    walker.walk(ast_node)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 874, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 874, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 874, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 874, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 874, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 874, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 871, in walk
    cb(astroid)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint_odoo/checkers/no_modules.py", line 472, in visit_raise
    func_name = node.exc.func.name
AttributeError: 'Getattr' object has no attribute 'name'

Check if a file called in __manifest__.py exists in the filesystem

Hello, I recently had an error while building a custom module:

17132811017-skortkefvw jpg

This error was caused because I deleted the unnecessary file from module's folder, but I forgot to remove it from the __manifest__.py file.

Could be possible pylint-odoo make that check to data and demo elements declared into modules manifest, to avoid this kind of errors?

AttributeError: 'BoolOp' object has no attribute 'targets'

Steps:

  1. Download the code from OCA/l10n-spain#434
  2. Run the pylint checks

Saw:
https://travis-ci.org/OCA/l10n-spain/jobs/196441078#L569

Traceback (most recent call last):
  File "/home/travis/maintainer-quality-tools/travis/test_pylint", line 201, in <module>
    ] + modules_changed_cmd + extra_params_cmd, standalone_mode=False)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/travis/maintainer-quality-tools/travis/run_pylint.py", line 105, in main
    extra_params=extra_params)
  File "/home/travis/maintainer-quality-tools/travis/run_pylint.py", line 75, in run_pylint
    pylint_res = pylint.lint.Run(cmd, exit=False)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 1310, in __init__
    linter.check(args)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 732, in check
    self._do_check(files_or_modules)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 863, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/lint.py", line 944, in check_astroid_module
    walker.walk(ast_node)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 944, in walk
    self.walk(child)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint/utils.py", line 941, in walk
    cb(astroid)
  File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/pylint_odoo/checkers/no_modules.py", line 384, in visit_call
    field_name = (argument.parent.parent.targets[0].name
AttributeError: 'BoolOp' object has no attribute 'targets'

Thanks @pedrobaeza for reporting

pylint-odoo fails if the addon contains Sphinx documentation

If you put into your addon a doc folder containing the documentation based on Sphinx, pylint-odoo will complain about unknown role entries etc
ie:

E:  1, 0: doc/index.rst:16 No role entry for "ref" in module "docutils.parsers.rst.languages.en".|Trying "ref" as canonical role name. (rst-syntax-error)
E:  1, 0: doc/index.rst:16 Unknown interpreted text role "ref". (rst-syntax-error)
E:  1, 0: doc/index.rst:48 No directive entry for "toctree" in module "docutils.parsers.rst.languages.en".|Trying "toctree" as canonical directive name. (rst-syntax-error)
E:  1, 0: doc/index.rst:48 Unknown directive type "toctree".||.. toctree::|   :maxdepth: 1||   project/contribute|   project/contributors|   project/license|   project/changes|   project/roadmap (rst-syntax-error)

I can't find a way to say to the linter to ignore my doc folder since pylint-odoo seems to not honor the '--ignore' parameter from pylint to filter out resources to check. (https://github.com/OCA/pylint-odoo/blob/master/pylint_odoo/misc.py#L109

translation-required on every exceptions

I like to distinguish 2 types of errors:

  • User errors, which concern the user and are more or less nicely displayed to her (UserError, ValidationError, ...)
  • Exception errors which concern the developers and are either logged, either caught by a try: except: reraising a UserError, either left as a connector job error, ...

While the first type of errors is surely translated, I dislike to translate the exception errors, that's a pain for the developers to search for translated errors.

Actual:

The translation-required lint actually requires every exception raised to be translated.

https://github.com/OCA/pylint-odoo/blob/master/pylint_odoo/checkers/no_modules.py#L443-L460

Expected:

The translation-required lint requires only the Odoo Exceptions (UserError, ValidationError) raised to be translated.

Detect default bad assignment

for example

bad

start_date = fields.Date(string='Start Date', default=date.today().strftime('%Y-%m-%d'))

good

start_date = fields.Date(string='Start Date', default=fields.Date.today)

Can not disable messages from `odoolint`

I tried command line and .pylintrc, both does not disable messages

~
pylint --reports=n --load-plugins=pylint_odoo -e odoolint my_odoo_module/configurations.py
************* Module  my_odoo_module.configurations
C:  1, 0: No UTF-8 coding comment found: Use `# coding: utf-8` or `# -*- coding: utf-8 -*-` (no-utf8-coding-comment)
W: 21, 0: Statement seems to have no effect (pointless-statement)
~
$ pylint --disable=pointless-statement --reports=n --load-plugins=pylint_odoo -e odoolint my_odoo_module/configurations.py
************* Module  my_odoo_module.configurations
C:  1, 0: No UTF-8 coding comment found: Use `# coding: utf-8` or `# -*- coding: utf-8 -*-` (no-utf8-coding-comment)
~
$ pylint --disable=no-utf8-coding-comment --reports=n --load-plugins=pylint_odoo -e odoolint my_odoo_module/configurations.py
************* Module  my_odoo_module.configurations
C:  1, 0: No UTF-8 coding comment found: Use `# coding: utf-8` or `# -*- coding: utf-8 -*-` (no-utf8-coding-comment)
W: 21, 0: Statement seems to have no effect (pointless-statement)

[REF] consider-merging-classes-inherited: Skip check if there is `_name` attribute

Steps:

  1. Using the following code:
class MyClass1(model.Models)
   _inherit = 'inherited.model'
   _name = 'my.class'

class MyClass2(model.Models)
   _inherit = 'inherited.model'
   _name = 'other.name'
  1. Running pylint-odoo

Saw:

  • Emit the message consider-merging-classes-inherited

Expected:

  • Don't emit message if there is _name attribute because is other table, other model and this way is common for model of reports.

[RFC] Deprecated <tree> attributes

string attribute in <tree> node is deprecated since 8.0 (no longer displayed) and colors and fonts are deprecated since 9.0 in favor of decoration-{$name}.

I went ahead an implemented a crude version of it, however, there is the question if something like this would likely be integrated into pylint-odoo?

If yes, then I have a few further questions:

  1. Since the rule deals with certain versions of Odoo only, the check should be skipped in other versions in order to avoid false positives. I saw valid_odoo_versions config value being used in one place. Is this a good/right approach?
  2. What is the policy for comming up with new message codes? Do I simply increment the highest existing code by one?

Roadmap

Version 1.2.0

  • Use jshint (javascript linter, in package node)
    • W7903
  • You odoo field string don't need translate method _ example
    • W8103
  • License allowed
    • C8105
  • Deprecated _fields={}, _defaults={}, (other one?)
    • W8105
  • Use restructuredtext_lint
    • E7901
  • Methods with super expected
    • W8106
  • Deprecated api.one in v9 and recommended use api.multi in v8 more info odoo/8527
    • W8104
  • Check duplicate "XML Ids" in ir.model.access.csv files (at least if following the standard columns structure): I recently saw a bug fix where the lines where duplicated but the author forgot to change the ID of the second line, so it overwrites the former permission and the module doesn't work.
  • Check manifest version format: numbers have 5 positions and start with either 8.0, 9.0, etc: https://github.com/oca/maintainer-tools/blob/master/CONTRIBUTING.md#version-numbers
  • Redundant use xml_id with current_module.xml_id
  • Validation of newline to final of all source code files. example
  • Validate no-tabs in xml files of all source code files.
  • Methods that required even a translation (warning, errors...)
  • Same field assigned 2 times in xml record.
  • Dual compatibility with pylint2.0.0
  • Creation of record res.users without context="{'no_reset_password': True}
  • Duplicated xml fields tag id

Version 1.3.x

  • Use def _compute_* methods for fields.functions of new api
  • avoid use of self.cr.commit or self.env.commit directly
  • avoid use of sql-injection
  • Enable and work the following pylint-dev/pylint#968
  • Avoid dummies super(method) without other sentence inherited
  • Deprecated select = True by index = True
  • Avoid use functional name equal to technical name for >=v8

Backlog

  • Avoid console.log from js OCA/maintainer-quality-tools#335 worked from #97
  • Enable new pylint check unexpected-line-ending-format with config expected_line_ending_format for \n
  • Avoid double magic comment : # coding: utf-8\n# coding: utf-8 or #!/bin/python\n#!/bin/python It isn't a common error
  • Avoid filtered of boolean obj.m2m_ids.filtered(lambda field: field.m2o_id.other_field is True). Use obj.m2m_ids.filtered('field.m2o_id.other_field') instead. Maybe is not so good check
  • Avoid obj.mapped('ids') use obj.ids directly instead. It could be valid
  • Avoid use of self.assertRaises better use self.assertRaisesRegex to catch exactly message of error
  • Validate basic structure of README.rst with OCA template
  • pylint enable E0213 - no-self-argument and E0211 - no-method-argument. (If you use empty or not use self in methods of class)
  • pylint enable E1003 - Bad first argument %r given to super()
  • pylint enable too-complex for cyclomatic complexity
  • pylint enable docstring
  • Files xml, csv, yml... of openerp without a entry in manifest
  • Files .py without a import in __init__.py files
  • Singular names of new modules or class.
  • Check for simple <data> element (with no update attribute).
  • Use <field name="".../> first. Avoid <field eval="value" name=""/>

Discussion

  • Detect bool field xml without a eval e.g. <field name="boolean_field"="False"/> use <field name="boolean_field" eval="False"/> instead. To know if is a field boolean there is not a static way (Its a work for dynamic check)
  • Depends base in manifest is redundant. Check if is really redundant
  • Documentation ./doc/index.rst First add guidelines
  • Missing icon ./static/description/icon.png After fix next issue odoo/odoo#7507
  • list, dict, tuple, with one element per line, append a comma to the last element. too complex
  • Avoid to use yml for test (better use unitest) Require argumentation
  • Use of openerp.exceptions instead of assert Open discussion with @dreispt
  • Add a po-lint Show many false errors
  • Fields declaration on top class. Check In a Model attribute order should be in https://github.com/oca/maintainer-tools/blob/master/CONTRIBUTING.md#field The following change of the guidelines broken this future lint OCA/maintainer-tools#199
  • Check if button object functions return dicts/ir.actions or a variable Out of scope for pylint-odoo maybe a runtime check
  • Cyclic depends (check before if odoo has this validation) Out of scope for pylint-odoo maybe a runtime check
  • Use of fields undefined in model Out of scope for pylint-odoo maybe a runtime check
  • <record.. \n ... <field boolean... without a eval Out of scope for pylint-odoo maybe a runtime check

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.