Skip to content

Commit

Permalink
[PERF] Checkers only run when enabled OCA#372
Browse files Browse the repository at this point in the history
  • Loading branch information
antonag32 committed Jun 22, 2022
1 parent 1c91fce commit 0332ea8
Show file tree
Hide file tree
Showing 3 changed files with 423 additions and 337 deletions.
44 changes: 26 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,29 @@ 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))
)
Loading

0 comments on commit 0332ea8

Please sign in to comment.