From 5283ca81db50561de819f3e1b92241030bc968ad Mon Sep 17 00:00:00 2001 From: Jesus Zapata Date: Fri, 30 Dec 2016 02:30:39 -0400 Subject: [PATCH] [ADD] eval-referenced: Detects if a "eval" is referenced (without call it) Cases detected: my_dict = { 'my_eval': eval, # [eval-used] } my_list = [eval] # [eval-used] my_var = eval # [eval-used] # inferred case my_var('d = 3') # [eval-used] func2(eval) # [eval-used] --- pylint_odoo/checkers/no_modules.py | 17 +++++++++++++++- pylint_odoo/test/main.py | 1 + .../test_repo/no_odoo_module/__init__.py | 1 + .../test_repo/no_odoo_module/eval_used.py | 20 +++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pylint_odoo/test_repo/no_odoo_module/eval_used.py diff --git a/pylint_odoo/checkers/no_modules.py b/pylint_odoo/checkers/no_modules.py index 7b62f2ca..7734bf69 100644 --- a/pylint_odoo/checkers/no_modules.py +++ b/pylint_odoo/checkers/no_modules.py @@ -197,7 +197,12 @@ 'String parameter equal to name of variable', 'attribute-string-redundant', settings.DESC_DFLT - ) + ), + 'W%d13' % settings.BASE_NOMODULE_ID: ( + '"eval" referenced detected.', + 'eval-referenced', + settings.DESC_DFLT + ), } @@ -605,6 +610,16 @@ def visit_assign(self, node): self.add_message('attribute-deprecated', node=node_left, args=(node_left.name,)) + @utils.check_messages('eval-referenced') + def visit_name(self, node): + """Detect when a "bad" built-in is referenced.""" + node_infer = utils.safe_infer(node) + if not utils.is_builtin_object(node_infer): + # Skip not builtin objects + return + if node_infer.name == 'eval': + self.add_message('eval-referenced', node=node) + def camelize(self, string): return re.sub(r"(?:^|_)(.)", lambda m: m.group(1).upper(), string) diff --git a/pylint_odoo/test/main.py b/pylint_odoo/test/main.py index 91e9f7ad..8e6a52b1 100644 --- a/pylint_odoo/test/main.py +++ b/pylint_odoo/test/main.py @@ -54,6 +54,7 @@ 'translation-required': 4, 'use-vim-comment': 1, 'wrong-tabs-instead-of-spaces': 2, + 'eval-referenced': 5, 'xml-syntax-error': 2, 'renamed-field-parameter': 2, 'attribute-string-redundant': 33, diff --git a/pylint_odoo/test_repo/no_odoo_module/__init__.py b/pylint_odoo/test_repo/no_odoo_module/__init__.py index 62f81e55..fdc2e3ea 100644 --- a/pylint_odoo/test_repo/no_odoo_module/__init__.py +++ b/pylint_odoo/test_repo/no_odoo_module/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- from . import myfile +from . import eval_used diff --git a/pylint_odoo/test_repo/no_odoo_module/eval_used.py b/pylint_odoo/test_repo/no_odoo_module/eval_used.py new file mode 100644 index 00000000..2d724ca5 --- /dev/null +++ b/pylint_odoo/test_repo/no_odoo_module/eval_used.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + + +def func2(param): + """eval used from param""" + param("c = 2") + + +def func3(): + """eval used from many ways""" + my_dict = { + 'my_eval': eval, # [eval-used] + } + my_list = [eval] # [eval-used] + + my_var = eval # [eval-used] + # inferred case + my_var('d = 3') # [eval-used] + func2(eval) # [eval-used] + return my_dict, my_list