Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] pylint-odoo: Adding support for parameters --ignore and --ignore-patterns #103

Merged
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
19 changes: 16 additions & 3 deletions pylint_odoo/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from lxml import etree
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from pylint.utils import _basename_in_blacklist_re
from restructuredtext_lint import lint_file as rst_lint

from . import settings
Expand Down Expand Up @@ -67,14 +68,26 @@ def get_manifest_file(self, node_file):

def set_ext_files(self):
"""Create `self.ext_files` dictionary with {extension_file: [files]}
and exclude files using --ignore and --ignore-patterns parameters
"""
self.ext_files = {}
for root, _, filenames in os.walk(self.module_path, followlinks=True):
for filename in filenames:
fext = os.path.splitext(filename)[1].lower()
fname_rel = os.path.relpath(
os.path.join(root, filename), self.module_path)
self.ext_files.setdefault(fext, []).append(fname_rel)
fname = os.path.join(root, filename)
# If the file is within black_list_re is ignored
if _basename_in_blacklist_re(fname,
self.linter.config.black_list_re):
continue
# If the file is within ignores is ignored
find = False
for ignore in self.linter.config.black_list:
if ignore in fname:
find = True
break
if not find:
fname_rel = os.path.relpath(fname, self.module_path)
self.ext_files.setdefault(fext, []).append(fname_rel)

def set_caches(self):
# TODO: Validate if is a odoo module before and has checks enabled
Expand Down
21 changes: 21 additions & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ def test_40_deprecated_modules(self):
real_errors = pylint_res.linter.stats['by_msg']
self.assertEqual(real_errors.items(), [('deprecated-module', 4)])

def test_50_ignore(self):
"""Test --ignore parameter """
extra_params = ['--ignore=test_module/res_users.xml',
'--disable=all',
'--enable=deprecated-openerp-xml-node']
pylint_res = self.run_pylint(self.paths_modules, extra_params)
real_errors = pylint_res.linter.stats['by_msg']
self.assertEqual(real_errors.items(),
[('deprecated-openerp-xml-node', 4)])

def test_60_ignore_patternls(self):
"""Test --ignore-patterns parameter """
extra_params = ['--ignore-patterns='
'.*\/test_module\/*\/.*xml$',
'--disable=all',
'--enable=deprecated-openerp-xml-node']
pylint_res = self.run_pylint(self.paths_modules, extra_params)
real_errors = pylint_res.linter.stats['by_msg']
self.assertEqual(real_errors.items(),
[('deprecated-openerp-xml-node', 3)])


if __name__ == '__main__':
unittest.main()