diff --git a/pylint_odoo/misc.py b/pylint_odoo/misc.py index 9ce000f2..af1b6c40 100644 --- a/pylint_odoo/misc.py +++ b/pylint_odoo/misc.py @@ -10,6 +10,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 translate.storage import factory, pypo from translate.filters.pofilter import (build_checkerconfig, pocheckfilter, @@ -112,14 +113,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 diff --git a/pylint_odoo/test/main.py b/pylint_odoo/test/main.py index 8e6a52b1..04d4f297 100644 --- a/pylint_odoo/test/main.py +++ b/pylint_odoo/test/main.py @@ -209,6 +209,27 @@ def my_which(bin_name, *args, **kwargs): self.expected_errors.pop('javascript-lint') self.assertEqual(self.expected_errors, real_errors) + def test_70_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_80_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()