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

[ADD] eval-referenced: Detects if a "eval" is referenced (without call it) #101

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
15 changes: 15 additions & 0 deletions pylint_odoo/checkers/no_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
'old-api7-method-defined',
settings.DESC_DFLT
),
'W%d11' % settings.BASE_NOMODULE_ID: (
'"eval" referenced detected.',
'eval-referenced',
settings.DESC_DFLT
),
}

DFTL_MANIFEST_REQUIRED_KEYS = ['license']
Expand Down Expand Up @@ -483,6 +488,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)

Expand Down
1 change: 1 addition & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'translation-required': 4,
'use-vim-comment': 1,
'wrong-tabs-instead-of-spaces': 2,
'eval-referenced': 5,
'xml-syntax-error': 2,
}

Expand Down
1 change: 1 addition & 0 deletions pylint_odoo/test_repo/no_odoo_module/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# -*- coding: utf-8 -*-
from . import myfile
from . import eval_used
20 changes: 20 additions & 0 deletions pylint_odoo/test_repo/no_odoo_module/eval_used.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-


def eval_from_param(param):
"""eval used from param"""
param("c = 2")


def eval_from_other():
"""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]
eval_from_param(eval) # [eval-used]
return my_dict, my_list