Skip to content

Commit

Permalink
Merge 94f7055 into a65fdf5
Browse files Browse the repository at this point in the history
  • Loading branch information
antonag32 committed Jun 14, 2022
2 parents a65fdf5 + 94f7055 commit ee61da3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
39 changes: 21 additions & 18 deletions pylint_odoo/checkers/format.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
import tokenize
from sys import platform
Expand Down Expand Up @@ -48,7 +47,6 @@


class FormatChecker(PylintOdooTokenChecker):

name = settings.CFG_SECTION
msgs = ODOO_MSGS
odoo_check_versions = {
Expand All @@ -67,7 +65,7 @@ def get_magic_comment_type(self, comment, line_num):
return MAGIC_COMMENT_INTERPRETER
elif "# -*- coding: " in comment or "# coding: " in comment:
if "# -*- coding: utf-8 -*-" in comment \
or "# coding: utf-8" in comment:
or "# coding: utf-8" in comment:
return MAGIC_COMMENT_CODING_UTF8
return MAGIC_COMMENT_CODING
elif "# -*- encoding: " in comment:
Expand All @@ -90,19 +88,24 @@ def process_tokens(self, tokens):
if magic_comment_type != NO_IDENTIFIED:
tokens_identified[magic_comment_type] = [
token_content, line_num]
elif self.is_vim_comment(token_content):
elif self.linter.is_message_enabled('use-vim-comment') and self.is_vim_comment(token_content):
self.add_message('use-vim-comment', line=line_num)
if not tokens_identified.get(MAGIC_COMMENT_CODING_UTF8) and \
not os.path.basename(self.linter.current_file) == '__init__.py':
self.add_message('no-utf8-coding-comment', line=1)
if (tokens_identified.get(MAGIC_COMMENT_CODING_UTF8)):
self.add_message('unnecessary-utf8-coding-comment', line=1)
access_x = os.access(self.linter.current_file, os.X_OK)
interpreter_content, line_num = tokens_identified.get(
MAGIC_COMMENT_INTERPRETER, ['', 0])
if (not platform.startswith('win') and
bool(interpreter_content) != access_x):
self.add_message(
'incoherent-interpreter-exec-perm',
line=line_num, args=(
os.path.basename(self.linter.current_file)))

if self.linter.is_message_enabled('no-utf8-coding-comment'):
if not tokens_identified.get(MAGIC_COMMENT_CODING_UTF8) and \
not os.path.basename(self.linter.current_file) == '__init__.py':
self.add_message('no-utf8-coding-comment', line=1)

if self.linter.is_message_enabled('unnecessary-utf8-coding-comment'):
if tokens_identified.get(MAGIC_COMMENT_CODING_UTF8):
self.add_message('unnecessary-utf8-coding-comment', line=1)

if self.linter.is_message_enabled('incoherent-interpreter-exec-perm'):
access_x = os.access(self.linter.current_file, os.X_OK)
interpreter_content, line_num = tokens_identified.get(MAGIC_COMMENT_INTERPRETER, ['', 0])
if not platform.startswith('win') and bool(interpreter_content) != access_x:
self.add_message(
'incoherent-interpreter-exec-perm',
line=line_num,
args=(os.path.basename(self.linter.current_file))
)
38 changes: 22 additions & 16 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,18 @@ def open(self):

def close(self):
"""Final process get all cached values and add messages"""
for (odoo_node, class_dup_name), nodes in self.inh_dup.items():
if len(nodes) == 1:
continue
path_nodes = []
for node in nodes[1:]:
relpath = os.path.relpath(node.file,
os.path.dirname(odoo_node.file))
path_nodes.append("%s:%d" % (relpath, node.lineno))
self.add_message('consider-merging-classes-inherited',
node=nodes[0],
args=(class_dup_name, ', '.join(path_nodes)))
if self.linter.is_message_enabled('consider-merging-classes-inherited'):
for (odoo_node, class_dup_name), nodes in self.inh_dup.items():
if len(nodes) == 1:
continue
path_nodes = []
for node in nodes[1:]:
relpath = os.path.relpath(node.file,
os.path.dirname(odoo_node.file))
path_nodes.append("%s:%d" % (relpath, node.lineno))
self.add_message('consider-merging-classes-inherited',
node=nodes[0],
args=(class_dup_name, ', '.join(path_nodes)))

def _get_odoo_module_imported(self, node):
odoo_module = []
Expand Down Expand Up @@ -364,11 +365,13 @@ def _get_odoo_module_imported(self, node):
odoo_module.append(packages[2])
return odoo_module

@utils.check_messages('odoo-addons-relative-import')
def check_odoo_relative_import(self, node):
if self.odoo_module_name in self._get_odoo_module_imported(node):
self.add_message('odoo-addons-relative-import', node=node,
args=(self.odoo_module_name))

@utils.check_messages('test-folder-imported')
def check_folder_test_imported(self, node):
if (hasattr(node.parent, 'file')
and os.path.basename(node.parent.file) == '__init__.py'):
Expand Down Expand Up @@ -422,6 +425,7 @@ def _is_module_name_in_whitelist(self, module_name):
return True
return False

@utils.check_messages('missing-import-error', 'missing-manifest-dependency')
def _check_imported_packages(self, node, module_name):
"""Check if the import node is a external dependency to validate it"""
if not module_name:
Expand Down Expand Up @@ -459,11 +463,13 @@ def _check_imported_packages(self, node, module_name):
py_ext_deps = ext_deps.get('python') or []
if isinstance(node, astroid.ImportFrom) and (node.level or 0) >= 1:
return
if module_name not in py_ext_deps and \
module_name.split('.')[0] not in py_ext_deps and \
not any(dep in module_name for dep in py_ext_deps):
self.add_message('missing-manifest-dependency', node=node,
args=(module_name,))

if self.linter.is_message_enabled('missing-manifest-dependency'):
if module_name not in py_ext_deps and \
module_name.split('.')[0] not in py_ext_deps and \
not any(dep in module_name for dep in py_ext_deps):
self.add_message('missing-manifest-dependency', node=node,
args=(module_name,))

@utils.check_messages('odoo-addons-relative-import',
'missing-import-error',
Expand Down

0 comments on commit ee61da3

Please sign in to comment.