diff --git a/docs/external_rules.rst b/docs/external_rules.rst index 9392b0bea..e98df13a5 100644 --- a/docs/external_rules.rst +++ b/docs/external_rules.rst @@ -35,7 +35,7 @@ This is an example of the file with custom checker that asserts that no test hav class NoExamplesChecker(VisitorChecker): reports = ("example-in-name",) - def visit_TestCaseName(self, node): + def visit_TestCaseName(self, node): # noqa: N802 if 'Example' in node.name: self.report("example-in-name", node=node, col=node.name.find('Example')) @@ -64,7 +64,7 @@ Rules can have configurable values. You need to specify them using RuleParam cla class NoExamplesChecker(VisitorChecker): reports = ("example-in-name",) - def visit_TestCaseName(self, node): + def visit_TestCaseName(self, node): # noqa: N802 configured_param = self.param("example-in-name", "param_name") if configured_param in node.name: self.report( @@ -155,7 +155,7 @@ inside ``some_rules.py``: """ Checker for missing keyword name. """ reports = ("external-rule",) - def visit_KeywordCall(self, node): # noqa + def visit_KeywordCall(self, node): # noqa: N802 if node.keyword and 'Example' not in node.keyword: self.report("external-rule", node=node) diff --git a/docs/releasenotes/5.0.0.rst b/docs/releasenotes/5.0.0.rst index a52e4fe85..57495c6fa 100644 --- a/docs/releasenotes/5.0.0.rst +++ b/docs/releasenotes/5.0.0.rst @@ -305,7 +305,7 @@ Example custom rule with ``ProjectChecker``:: self.test_count = 0 super().__init__() - def visit_TestCase(self, node): # noqa + def visit_TestCase(self, node): # noqa: N802 self.test_count += 1 def scan_project(self) -> List[Message]: diff --git a/pyproject.toml b/pyproject.toml index 8cf3e7472..3b798ec18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ lint.ignore = [ "T201", # TODO: print "FBT003", # TODO: boolean positional value in function call "ARG002", # TODO: unused method argument - "SLF001", # TODO: private member accessed + "SLF001", # TODO: private member accessedAsnfz "PLR0913", # TODO: too many arguments in fn def (consider if it's good to keep the rule) "B007", # TODO: loop variable not used "TRY003", # TODO: exception with long message outside exception class @@ -68,8 +68,6 @@ lint.ignore = [ "FIX001", # TODO: code with fixme "TD003", # TODO: code with fixme and without issue link "TD001", # TODO: invalid TODO tag - "N802", # TODO: function name should be lowercase (use noqa for visitors) - "N815", # TODO: same as N802 "N818", # TODO: exception without error in name "N999", # TODO: invalid module name unused-keyword "PLR2004", # TODO: magic value used in comparison (50 issues) diff --git a/robocop/checkers/__init__.py b/robocop/checkers/__init__.py index 9d633166b..4c0a93b93 100644 --- a/robocop/checkers/__init__.py +++ b/robocop/checkers/__init__.py @@ -132,7 +132,7 @@ def scan_file(self, ast_model, filename, in_memory_content, templated=False) -> self.visit_File(ast_model) return self.issues - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 """Perform generic ast visit on file node.""" self.generic_visit(node) diff --git a/robocop/checkers/comments.py b/robocop/checkers/comments.py index 56542b249..8d9998297 100644 --- a/robocop/checkers/comments.py +++ b/robocop/checkers/comments.py @@ -175,16 +175,16 @@ def block(self): self._block = self.param("missing-space-after-comment", "block") return self._block - def visit_Comment(self, node): + def visit_Comment(self, node): # noqa: N802 self.find_comments(node) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 self.check_invalid_comments(node.name, node) self.generic_visit(node) - visit_Keyword = visit_TestCase + visit_Keyword = visit_TestCase # noqa: N815 - def visit_Statement(self, node): + def visit_Statement(self, node): # noqa: N802 self.find_comments(node) def find_comments(self, node): diff --git a/robocop/checkers/community_rules/keywords.py b/robocop/checkers/community_rules/keywords.py index f27361c01..2f66ac63f 100644 --- a/robocop/checkers/community_rules/keywords.py +++ b/robocop/checkers/community_rules/keywords.py @@ -151,7 +151,7 @@ class SleepKeywordUsedChecker(VisitorChecker): reports = ("sleep-keyword-used",) - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if not node.keyword: # Keyword name can be empty if the syntax is invalid return # Robot Framework ignores case, underscores and whitespace when searching for keywords @@ -211,28 +211,28 @@ def check_keyword_naming(self, name: str, keyword): end_col=keyword.end_col_offset + 1, ) - def visit_Setup(self, node): + def visit_Setup(self, node): # noqa: N802 self.check_keyword_naming_with_subkeywords(node, Token.NAME) - visit_TestTeardown = visit_SuiteTeardown = visit_Teardown = visit_TestSetup = visit_SuiteSetup = visit_Setup + visit_TestTeardown = visit_SuiteTeardown = visit_Teardown = visit_TestSetup = visit_SuiteSetup = visit_Setup # noqa: N815 - def visit_Template(self, node): + def visit_Template(self, node): # noqa: N802 # allow / disallow param if node.value: name_token = node.get_token(Token.NAME) self.check_keyword_naming(node.value, name_token) self.generic_visit(node) - visit_TestTemplate = visit_Template + visit_TestTemplate = visit_Template # noqa: N815 - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 self.check_keyword_naming_with_subkeywords(node, Token.KEYWORD) class NoEmbeddedKeywordArgumentsChecker(VisitorChecker): reports = ("no-embedded-keyword-arguments",) - def visit_Keyword(self, node: Keyword): + def visit_Keyword(self, node: Keyword): # noqa: N802 name_token: Token = node.header.get_token(Token.KEYWORD_NAME) variable_tokens = [t for t in name_token.tokenize_variables() if t.type == Token.VARIABLE] diff --git a/robocop/checkers/community_rules/misc.py b/robocop/checkers/community_rules/misc.py index 5e79d84bb..a824cbaf7 100644 --- a/robocop/checkers/community_rules/misc.py +++ b/robocop/checkers/community_rules/misc.py @@ -57,7 +57,7 @@ def __init__(self): self.resources = [] super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.non_builtin_libraries = [] self.resources = [] self.generic_visit(node) @@ -88,11 +88,11 @@ def visit_File(self, node): ) previous = resource - def visit_LibraryImport(self, node): + def visit_LibraryImport(self, node): # noqa: N802 if node.name and node.name not in STDLIBS: self.non_builtin_libraries.append(node) - def visit_ResourceImport(self, node): + def visit_ResourceImport(self, node): # noqa: N802 if not node.name: return self.resources.append(node) diff --git a/robocop/checkers/community_rules/usage.py b/robocop/checkers/community_rules/usage.py index d95574994..b6548cd7b 100644 --- a/robocop/checkers/community_rules/usage.py +++ b/robocop/checkers/community_rules/usage.py @@ -147,12 +147,12 @@ def scan_project(self) -> List["Message"]: ) return self.issues - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.current_file = RobotFile(node.source) # TODO: handle "-" self.generic_visit(node) self.files[self.current_file.path] = self.current_file - def visit_TestCaseSection(self, node): + def visit_TestCaseSection(self, node): # noqa: N802 self.current_file.is_suite = True self.generic_visit(node) @@ -169,24 +169,24 @@ def mark_used_keyword(self, name: str, keyword): self.current_file.used_keywords[normalized_name].update(name) # what about possible library names? searching removes, but for sake of collecting - def visit_Setup(self, node): + def visit_Setup(self, node): # noqa: N802 self.mark_used_keywords(node, Token.NAME) - visit_TestTeardown = visit_SuiteTeardown = visit_Teardown = visit_TestSetup = visit_SuiteSetup = visit_Setup + visit_TestTeardown = visit_SuiteTeardown = visit_Teardown = visit_TestSetup = visit_SuiteSetup = visit_Setup # noqa: N815 - def visit_Template(self, node): + def visit_Template(self, node): # noqa: N802 # allow / disallow param if node.value: name_token = node.get_token(Token.NAME) self.mark_used_keyword(node.value, name_token) self.generic_visit(node) - visit_TestTemplate = visit_Template + visit_TestTemplate = visit_Template # noqa: N815 - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 self.mark_used_keywords(node, Token.KEYWORD) - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 try: embedded = KeywordEmbedded(node.name) if embedded and embedded.args: diff --git a/robocop/checkers/documentation.py b/robocop/checkers/documentation.py index 6f3c293e2..3d05e6896 100644 --- a/robocop/checkers/documentation.py +++ b/robocop/checkers/documentation.py @@ -103,24 +103,24 @@ def __init__(self): self.settings_section_exists = False super().__init__() - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 if node.name.lstrip().startswith("#"): return self.check_if_docs_are_present(node, "missing-doc-keyword", extend_disablers=True) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 if self.param("missing-doc-test-case", "ignore_templated") and self.templated_suite: return self.check_if_docs_are_present(node, "missing-doc-test-case", extend_disablers=True) - def visit_SettingSection(self, node): + def visit_SettingSection(self, node): # noqa: N802 self.settings_section_exists = True if self.is_resource: self.check_if_docs_are_present(node, "missing-doc-resource-file", extend_disablers=False) else: self.check_if_docs_are_present(node, "missing-doc-suite", extend_disablers=False) - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 source = node.source if node.source else self.source self.is_resource = source and ".resource" in Path(source).suffix self.settings_section_exists = False diff --git a/robocop/checkers/duplications.py b/robocop/checkers/duplications.py index 74af368e7..01d6a6b13 100644 --- a/robocop/checkers/duplications.py +++ b/robocop/checkers/duplications.py @@ -295,7 +295,7 @@ def __init__(self): self.variable_imports = defaultdict(list) super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.test_cases = defaultdict(list) self.keywords = defaultdict(list) self.variables = defaultdict(list) @@ -336,17 +336,17 @@ def check_library_duplicates(self, container, rule): end_col=lib_token.end_col_offset + 1, ) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 testcase_name = normalize_robot_name(node.name) self.test_cases[testcase_name].append(node) self.generic_visit(node) - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 keyword_name = normalize_robot_name(node.name) self.keywords[keyword_name].append(node) self.generic_visit(node) - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 assign = node.get_tokens(Token.ASSIGN) seen = set() for var in assign: @@ -366,10 +366,10 @@ def visit_KeywordCall(self, node): else: seen.add(name) - def visit_VariableSection(self, node): + def visit_VariableSection(self, node): # noqa: N802 self.generic_visit(node) - def visit_Variable(self, node): + def visit_Variable(self, node): # noqa: N802 if not node.name or get_errors(node): return var_name = normalize_robot_name(self.replace_chars(node.name, "${}@&")) @@ -379,22 +379,22 @@ def visit_Variable(self, node): def replace_chars(name, chars): return "".join(c for c in name if c not in chars) - def visit_ResourceImport(self, node): + def visit_ResourceImport(self, node): # noqa: N802 if node.name: self.resources[node.name].append(node) - def visit_LibraryImport(self, node): + def visit_LibraryImport(self, node): # noqa: N802 if not node.name: return lib_name = node.alias if node.alias else node.name name_with_args = lib_name + "".join(token.value for token in node.get_tokens(Token.ARGUMENT)) self.libraries[name_with_args].append(node) - def visit_Metadata(self, node): + def visit_Metadata(self, node): # noqa: N802 if node.name is not None: self.metadata[node.name + node.value].append(node) - def visit_VariablesImport(self, node): + def visit_VariablesImport(self, node): # noqa: N802 if not node.name: return # only YAML files can't have arguments - covered in E0404 variables-import-with-args @@ -403,7 +403,7 @@ def visit_VariablesImport(self, node): name_with_args = node.name + "".join(token.value for token in node.data_tokens[2:]) self.variable_imports[name_with_args].append(node) - def visit_Arguments(self, node): + def visit_Arguments(self, node): # noqa: N802 args = set() for arg in node.get_tokens(Token.ARGUMENT): orig, *_ = arg.value.split("=", maxsplit=1) @@ -420,7 +420,7 @@ def visit_Arguments(self, node): else: args.add(name) - def visit_Error(self, node): + def visit_Error(self, node): # noqa: N802 for error in get_errors(node): if "is allowed only once" in error: self.report( @@ -459,12 +459,12 @@ def section_order_to_str(order): order_str.append(mapped_name) return " > ".join(order_str) - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.sections_by_order = [] self.sections_by_existence = {} super().visit_File(node) - def visit_SectionHeader(self, node): + def visit_SectionHeader(self, node): # noqa: N802 section_name = node.type if section_name not in self.param("section-out-of-order", "sections_order"): return diff --git a/robocop/checkers/errors.py b/robocop/checkers/errors.py index 795914072..840f5240d 100644 --- a/robocop/checkers/errors.py +++ b/robocop/checkers/errors.py @@ -334,26 +334,26 @@ def __init__(self): super().__init__() self.in_block = None - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.generic_visit(node) - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 self.in_block = node # to ensure we're in IF for `invalid-if` rule self.parse_errors(node) self.generic_visit(node) - visit_For = visit_While = visit_Try = visit_If + visit_For = visit_While = visit_Try = visit_If # noqa: N815 - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if node.keyword and node.keyword.startswith("..."): col = node.data_tokens[0].col_offset + 1 self.report("not-enough-whitespace-after-newline-marker", node=node, col=col, end_col=col + 3) self.generic_visit(node) - def visit_Statement(self, node): + def visit_Statement(self, node): # noqa: N802 self.parse_errors(node) - def visit_InvalidSection(self, node): + def visit_InvalidSection(self, node): # noqa: N802 invalid_header = node.header.get_token(Token.INVALID_HEADER) if "Resource file with" in invalid_header.error: section_name = invalid_header.value @@ -637,7 +637,7 @@ def __init__(self): self.setting_pattern = re.compile(r"\[\s?(\w+)\s?\]") super().__init__() - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 """Invalid settings like '[Arguments] ${var}' will be parsed as keyword call""" if not node.keyword: return @@ -660,10 +660,10 @@ class MissingKeywordName(VisitorChecker): reports = ("missing-keyword-name",) - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.generic_visit(node) - def visit_EmptyLine(self, node): + def visit_EmptyLine(self, node): # noqa: N802 if ROBOT_VERSION.major < 5: return assign_token = node.get_token(Token.ASSIGN) @@ -675,7 +675,7 @@ def visit_EmptyLine(self, node): col=assign_token.col_offset + 1, ) - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if not node.keyword: self.report( "missing-keyword-name", @@ -691,6 +691,6 @@ class VariablesImportErrorChecker(VisitorChecker): reports = ("variables-import-with-args",) - def visit_VariablesImport(self, node): + def visit_VariablesImport(self, node): # noqa: N802 if node.name and node.name.endswith((".yaml", ".yml")) and node.get_token(Token.ARGUMENT): self.report("variables-import-with-args", node=node) diff --git a/robocop/checkers/lengths.py b/robocop/checkers/lengths.py index 8dff90858..7a87135f8 100644 --- a/robocop/checkers/lengths.py +++ b/robocop/checkers/lengths.py @@ -435,7 +435,7 @@ def __init__(self): ) super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 if node.end_lineno > self.param("file-too-long", "max_lines"): self.report( "file-too-long", @@ -448,7 +448,7 @@ def visit_File(self, node): ) super().visit_File(node) - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 if node.name.lstrip().startswith("#"): return for child in node.body: @@ -510,7 +510,7 @@ def test_is_templated(self, node): return False return any(isinstance(statement, Template) for statement in node.body) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 length, node_end_line = check_node_length(node, ignore_docs=self.param("too-long-test-case", "ignore_docs")) if length > self.param("too-long-test-case", "max_len"): self.report( @@ -608,7 +608,7 @@ def check_if_empty(self, node): end_col=node.header.end_col_offset, ) - def visit_Section(self, node): + def visit_Section(self, node): # noqa: N802 self.check_if_empty(node) @@ -617,12 +617,12 @@ class NumberOfReturnedArgsChecker(VisitorChecker): reports = ("number-of-returned-values",) - def visit_Return(self, node): + def visit_Return(self, node): # noqa: N802 self.check_node_returns(len(node.values), node) - visit_ReturnStatement = visit_ReturnSetting = visit_Return + visit_ReturnStatement = visit_ReturnSetting = visit_Return # noqa: N815 - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if not node.keyword: return @@ -674,29 +674,29 @@ def __init__(self): self.parent_node_name = "" super().__init__() - def visit_SettingSection(self, node): + def visit_SettingSection(self, node): # noqa: N802 self.parent_node_name = "Test Suite" self.generic_visit(node) - def visit_TestCaseName(self, node): + def visit_TestCaseName(self, node): # noqa: N802 if node.name: self.parent_node_name = f"'{node.name}' Test Case" else: self.parent_node_name = "" self.generic_visit(node) - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 if node.name: self.parent_node_name = f"'{node.name}' Keyword" else: self.parent_node_name = "" self.generic_visit(node) - def visit_Metadata(self, node): + def visit_Metadata(self, node): # noqa: N802 if not node.name: self.report("empty-metadata", node=node, col=node.col_offset + 1) - def visit_Documentation(self, node): + def visit_Documentation(self, node): # noqa: N802 if not node.value: self.report( "empty-documentation", @@ -706,31 +706,31 @@ def visit_Documentation(self, node): end_col=node.end_col_offset, ) - def visit_ForceTags(self, node): + def visit_ForceTags(self, node): # noqa: N802 if not node.values: self.report("empty-force-tags", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_DefaultTags(self, node): + def visit_DefaultTags(self, node): # noqa: N802 if not node.values: self.report("empty-default-tags", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_KeywordTags(self, node): + def visit_KeywordTags(self, node): # noqa: N802 if not node.values: self.report("empty-keyword-tags", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_VariablesImport(self, node): + def visit_VariablesImport(self, node): # noqa: N802 if not node.name: self.report("empty-variables-import", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_ResourceImport(self, node): + def visit_ResourceImport(self, node): # noqa: N802 if not node.name: self.report("empty-resource-import", node=node, col=node.col_offset + 1) - def visit_LibraryImport(self, node): + def visit_LibraryImport(self, node): # noqa: N802 if not node.name: self.report("empty-library-import", node=node, col=node.col_offset + 1) - def visit_Setup(self, node): + def visit_Setup(self, node): # noqa: N802 if not node.name: self.report( "empty-setup", @@ -740,15 +740,15 @@ def visit_Setup(self, node): end_col=node.end_col_offset, ) - def visit_SuiteSetup(self, node): + def visit_SuiteSetup(self, node): # noqa: N802 if not node.name: self.report("empty-suite-setup", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_TestSetup(self, node): + def visit_TestSetup(self, node): # noqa: N802 if not node.name: self.report("empty-test-setup", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_Teardown(self, node): + def visit_Teardown(self, node): # noqa: N802 if not node.name: self.report( "empty-teardown", @@ -758,19 +758,19 @@ def visit_Teardown(self, node): end_col=node.end_col_offset, ) - def visit_SuiteTeardown(self, node): + def visit_SuiteTeardown(self, node): # noqa: N802 if not node.name: self.report("empty-suite-teardown", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_TestTeardown(self, node): + def visit_TestTeardown(self, node): # noqa: N802 if not node.name: self.report("empty-test-teardown", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_TestTemplate(self, node): + def visit_TestTemplate(self, node): # noqa: N802 if not node.value: self.report("empty-test-template", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_Template(self, node): + def visit_Template(self, node): # noqa: N802 if len(node.data_tokens) < 2: self.report( "empty-template", @@ -780,7 +780,7 @@ def visit_Template(self, node): end_col=node.end_col_offset, ) - def visit_Timeout(self, node): + def visit_Timeout(self, node): # noqa: N802 if not node.value: self.report( "empty-timeout", @@ -790,11 +790,11 @@ def visit_Timeout(self, node): end_col=node.end_col_offset, ) - def visit_TestTimeout(self, node): + def visit_TestTimeout(self, node): # noqa: N802 if not node.value: self.report("empty-test-timeout", node=node, col=node.col_offset + 1, end_col=node.end_col_offset) - def visit_Arguments(self, node): + def visit_Arguments(self, node): # noqa: N802 if not node.values: self.report( "empty-arguments", @@ -810,7 +810,7 @@ class TestCaseNumberChecker(VisitorChecker): reports = ("too-many-test-cases",) - def visit_TestCaseSection(self, node): + def visit_TestCaseSection(self, node): # noqa: N802 max_testcases = ( self.param("too-many-test-cases", "max_templated_testcases") if self.templated_suite @@ -831,7 +831,7 @@ def visit_TestCaseSection(self, node): class TooManyArgumentsInLineChecker(VisitorChecker): reports = ("arguments-per-line",) - def visit_Arguments(self, node): + def visit_Arguments(self, node): # noqa: N802 any_cont_token = node.get_token(Token.CONTINUATION) if not any_cont_token: # only one line, ignoring return diff --git a/robocop/checkers/misc.py b/robocop/checkers/misc.py index b4a68f367..bfa76c6ba 100644 --- a/robocop/checkers/misc.py +++ b/robocop/checkers/misc.py @@ -710,7 +710,7 @@ class ReturnChecker(VisitorChecker): "empty-return", ) - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 return_setting_node = None keyword_after_return = False return_from = False @@ -752,7 +752,7 @@ def visit_Keyword(self, node): ) self.generic_visit(node) - visit_If = visit_For = visit_While = visit_Try = visit_Keyword + visit_If = visit_For = visit_While = visit_Try = visit_Keyword # noqa: N815 class UnreachableCodeChecker(VisitorChecker): @@ -760,7 +760,7 @@ class UnreachableCodeChecker(VisitorChecker): reports = ("unreachable-code",) - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 statement_node = None for child in node.body: @@ -780,7 +780,7 @@ def visit_Keyword(self, node): self.generic_visit(node) - visit_If = visit_For = visit_While = visit_Try = visit_Keyword + visit_If = visit_For = visit_While = visit_Try = visit_Keyword # noqa: N815 class NestedForLoopsChecker(VisitorChecker): @@ -792,7 +792,7 @@ class NestedForLoopsChecker(VisitorChecker): reports = ("nested-for-loop",) - def visit_ForLoop(self, node): + def visit_ForLoop(self, node): # noqa: N802 # For RF 4.0 node is "For" but we purposely don't visit it because nested for loop is allowed in 4.0 for child in node.body: if child.type == "FOR": @@ -810,7 +810,7 @@ class IfBlockCanBeUsed(VisitorChecker): reports = ("if-can-be-used",) run_keyword_variants = {"runkeywordif", "runkeywordunless"} - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if not node.keyword: return if normalize_robot_name(node.keyword, remove_prefix="builtin.") in self.run_keyword_variants: @@ -846,7 +846,7 @@ def __init__(self): self.variables_expected_sign_type = None super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.keyword_expected_sign_type = self.param("inconsistent-assignment", "assignment_sign_type") self.variables_expected_sign_type = self.param("inconsistent-assignment-in-variables", "assignment_sign_type") if "autodetect" in [ @@ -860,7 +860,7 @@ def visit_File(self, node): self.variables_expected_sign_type = auto_detector.variables_most_common self.generic_visit(node) - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if self.keyword_expected_sign_type is None or not node.keyword: return None if node.assign: # if keyword returns any value @@ -872,7 +872,7 @@ def visit_KeywordCall(self, node): ) return node - def visit_VariableSection(self, node): + def visit_VariableSection(self, node): # noqa: N802 if self.variables_expected_sign_type is None: return None for child in node.body: @@ -921,7 +921,7 @@ def __init__(self): self.libraries = [] super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.libraries = [] self.generic_visit(node) first_non_builtin = None @@ -953,7 +953,7 @@ def visit_File(self, node): ) previous_builtin = library - def visit_LibraryImport(self, node): + def visit_LibraryImport(self, node): # noqa: N802 if not node.name: return self.libraries.append(node) @@ -969,23 +969,23 @@ def __init__(self): self.visit_var = False super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 variable_source = self.param("empty-variable", "variable_source") self.visit_var_section = "section" in variable_source self.visit_var = "var" in variable_source self.generic_visit(node) - def visit_VariableSection(self, node): + def visit_VariableSection(self, node): # noqa: N802 if self.visit_var_section: self.generic_visit(node) - def visit_KeywordSection(self, node): + def visit_KeywordSection(self, node): # noqa: N802 if self.visit_var: self.generic_visit(node) - visit_TestCaseSection = visit_KeywordSection + visit_TestCaseSection = visit_KeywordSection # noqa: N815 - def visit_Variable(self, node): + def visit_Variable(self, node): # noqa: N802 if get_errors(node): return if not node.value: # catch variable declaration without any value @@ -1001,7 +1001,7 @@ def visit_Variable(self, node): end_col=token.end_col_offset + 1, ) - def visit_Var(self, node): + def visit_Var(self, node): # noqa: N802 if node.errors: return if not node.value: # catch variable declaration without any value @@ -1030,7 +1030,7 @@ class ResourceFileChecker(VisitorChecker): reports = ("can-be-resource-file",) - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 source = node.source if node.source else self.source if source: extension = Path(source).suffix @@ -1053,12 +1053,12 @@ class IfChecker(VisitorChecker): "multiline-inline-if", ) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 if get_errors(node): return self.check_adjacent_ifs(node) - visit_For = visit_If = visit_Keyword = visit_TestCase # TODO: While, Try Except? + visit_For = visit_If = visit_Keyword = visit_TestCase # noqa: N815 # TODO: While, Try Except? @staticmethod def is_inline_if(node): @@ -1148,18 +1148,18 @@ def __init__(self): self.loops = 0 super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.loops = 0 self.generic_visit(node) - def visit_For(self, node): + def visit_For(self, node): # noqa: N802 self.loops += 1 self.generic_visit(node) self.loops -= 1 - visit_While = visit_For + visit_While = visit_For # noqa: N815 - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if node.errors or self.loops: return if normalize_robot_name(node.keyword, remove_prefix="builtin.") in self.for_keyword: @@ -1173,13 +1173,13 @@ def visit_KeywordCall(self, node): end_col=col + len(node.keyword), ) - def visit_Continue(self, node): + def visit_Continue(self, node): # noqa: N802 self.check_statement_in_loop(node, "CONTINUE") # type: ignore[arg-type] - def visit_Break(self, node): + def visit_Break(self, node): # noqa: N802 self.check_statement_in_loop(node, "BREAK") # type: ignore[arg-type] - def visit_Error(self, node): + def visit_Error(self, node): # noqa: N802 """Support for RF >= 6.1""" for error_token in node.get_tokens(Token.ERROR): if "is not allowed in this context" in error_token.error: @@ -1216,7 +1216,7 @@ class SectionVariablesCollector(ast.NodeVisitor): def __init__(self): self.section_variables: Dict[str, CachedVariable] = {} - def visit_Variable(self, node): + def visit_Variable(self, node): # noqa: N802 if get_errors(node): return var_token = node.get_token(Token.VARIABLE) @@ -1245,7 +1245,7 @@ def __init__(self): self.test_or_task_section = False super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.test_or_task_section = False section_variables = SectionVariablesCollector() section_variables.visit(node) @@ -1258,18 +1258,18 @@ def report_not_used_section_variables(self): return self.check_unused_variables_in_scope(self.section_variables) - def visit_TestCaseSection(self, node): + def visit_TestCaseSection(self, node): # noqa: N802 self.test_or_task_section = True self.generic_visit(node) - visit_TaskSection = visit_TestCaseSection + visit_TaskSection = visit_TestCaseSection # noqa: N815 - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 self.variables = [{}] self.generic_visit(node) self.check_unused_variables() - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 self.arguments = {} self.variables = [{}] name_token = node.header.get_token(Token.KEYWORD_NAME) @@ -1336,7 +1336,7 @@ def parse_embedded_arguments(self, name_token): except VariableError: pass - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 if node.header.errors: return node for token in node.header.get_tokens(Token.ARGUMENT): @@ -1366,15 +1366,15 @@ def add_variables_from_if_to_scope(self): else: self.variables[-1][var_name] = cached_var - def visit_LibraryImport(self, node): + def visit_LibraryImport(self, node): # noqa: N802 for token in node.get_tokens(Token.NAME, Token.ARGUMENT): self.find_not_nested_variable(token.value, is_var=False) - visit_TestTags = visit_ForceTags = visit_Metadata = visit_DefaultTags = visit_Variable = visit_ReturnStatement = ( - visit_ReturnSetting - ) = visit_Teardown = visit_Timeout = visit_Return = visit_SuiteSetup = visit_SuiteTeardown = visit_TestSetup = ( - visit_TestTeardown - ) = visit_Setup = visit_ResourceImport = visit_VariablesImport = visit_Tags = visit_Documentation = ( + visit_TestTags = visit_ForceTags = visit_Metadata = visit_DefaultTags = visit_Variable = visit_ReturnStatement = ( # noqa: N815 + visit_ReturnSetting # noqa: N815 + ) = visit_Teardown = visit_Timeout = visit_Return = visit_SuiteSetup = visit_SuiteTeardown = visit_TestSetup = ( # noqa: N815 + visit_TestTeardown # noqa: N815 + ) = visit_Setup = visit_ResourceImport = visit_VariablesImport = visit_Tags = visit_Documentation = ( # noqa: N815 visit_LibraryImport ) @@ -1399,7 +1399,7 @@ def revisit_variables_used_in_loop(self): for name in self.used_in_scope: self._set_variable_as_used(name, self.variables[-1]) - def visit_While(self, node): + def visit_While(self, node): # noqa: N802 if node.header.errors: return node self.in_loop = True @@ -1413,7 +1413,7 @@ def visit_While(self, node): self.revisit_variables_used_in_loop() self.clear_variables_after_loop() - def visit_For(self, node): + def visit_For(self, node): # noqa: N802 if getattr(node.header, "errors", None): return node self.in_loop = True @@ -1429,7 +1429,7 @@ def visit_For(self, node): self.revisit_variables_used_in_loop() self.clear_variables_after_loop() - visit_ForLoop = visit_For + visit_ForLoop = visit_For # noqa: N815 @staticmethod def try_assign(try_node) -> str: @@ -1437,7 +1437,7 @@ def try_assign(try_node) -> str: return try_node.variable return try_node.assign - def visit_Try(self, node): + def visit_Try(self, node): # noqa: N802 if node.errors or node.header.errors: return node self.variables.append({}) @@ -1451,13 +1451,13 @@ def visit_Try(self, node): if node.next: self.visit_Try(node.next) - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 for token in node.get_tokens(Token.ARGUMENT, Token.KEYWORD): # argument can be used in keyword name self.find_not_nested_variable(token.value, is_var=False) for token in node.get_tokens(Token.ASSIGN): # we first check args, then assign for used and then overwritten self.handle_assign_variable(token) - def visit_Var(self, node): + def visit_Var(self, node): # noqa: N802 if node.errors: # for example invalid variable definition like $var} return for arg in node.get_tokens(Token.ARGUMENT): @@ -1466,7 +1466,7 @@ def visit_Var(self, node): if variable and _is_var_scope_local(node): self.handle_assign_variable(variable) - def visit_TemplateArguments(self, node): + def visit_TemplateArguments(self, node): # noqa: N802 for argument in node.data_tokens: self.find_not_nested_variable(argument.value, is_var=False) @@ -1600,14 +1600,14 @@ class ExpressionsChecker(VisitorChecker): COMPARISON_SIGNS = {"==", "!="} EMPTY_COMPARISON = {"${true}", "${false}", "true", "false", "[]", "{}", "set()", "list()", "dict()", "0"} - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 condition_token = node.header.get_token(Token.ARGUMENT) self.check_condition(node.header.type, condition_token, node.condition) self.generic_visit(node) - visit_While = visit_If + visit_While = visit_If # noqa: N815 - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 normalized_name = normalize_robot_name(node.keyword, remove_prefix="builtin.") if normalized_name not in self.CONDITION_KEYWORDS: return @@ -1694,7 +1694,7 @@ def __init__(self): self.expected_order = {} super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.rules_by_node_type = {Keyword: "keyword-section-out-of-order", TestCase: "test-case-section-out-of-order"} self.expected_order = { Keyword: self.param("keyword-section-out-of-order", "sections_order"), @@ -1724,4 +1724,4 @@ def check_order(self, node): else: max_order_indicator = this_node_expected_order - visit_Keyword = visit_TestCase = check_order + visit_Keyword = visit_TestCase = check_order # noqa: N815 diff --git a/robocop/checkers/naming.py b/robocop/checkers/naming.py index 75db6d9fe..bfa65e731 100644 --- a/robocop/checkers/naming.py +++ b/robocop/checkers/naming.py @@ -628,7 +628,7 @@ class InvalidCharactersInNameChecker(VisitorChecker): "not-allowed-char-in-name", ) - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 source = node.source if node.source else self.source if source: suite_name = Path(source).stem @@ -683,10 +683,10 @@ def check_if_pattern_in_node_name(self, node, name_of_node, is_keyword=False): end_col=node.col_offset + iter.end(0) + 1, ) - def visit_TestCaseName(self, node): + def visit_TestCaseName(self, node): # noqa: N802 self.check_if_pattern_in_node_name(node, "test case") - def visit_KeywordName(self, node): + def visit_KeywordName(self, node): # noqa: N802 self.check_if_pattern_in_node_name(node, "keyword", is_keyword=True) @@ -731,34 +731,34 @@ def check_keyword_naming_with_subkeywords(self, node, name_token_type): for keyword in iterate_keyword_names(node, name_token_type): self.check_keyword_naming(keyword.value, keyword) - def visit_Setup(self, node): + def visit_Setup(self, node): # noqa: N802 self.check_bdd_keywords(node.name, node) self.check_keyword_naming_with_subkeywords(node, Token.NAME) - visit_TestTeardown = visit_SuiteTeardown = visit_Teardown = visit_TestSetup = visit_SuiteSetup = visit_Setup + visit_TestTeardown = visit_SuiteTeardown = visit_Teardown = visit_TestSetup = visit_SuiteSetup = visit_Setup # noqa: N815 - def visit_Template(self, node): + def visit_Template(self, node): # noqa: N802 if node.value: name_token = node.get_token(Token.NAME) self.check_keyword_naming(node.value, name_token) self.generic_visit(node) - visit_TestTemplate = visit_Template + visit_TestTemplate = visit_Template # noqa: N815 - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 if not node.name: self.report("keyword-name-is-empty", node=node) else: self.check_keyword_naming(node.name, node) self.generic_visit(node) - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if self.inside_if_block and node.keyword and node.keyword.lower() in self.else_statements: self.report("else-not-upper-case", node=node, col=keyword_col(node)) self.check_keyword_naming_with_subkeywords(node, Token.KEYWORD) self.check_bdd_keywords(node.keyword, node) - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 self.inside_if_block = True self.generic_visit(node) self.inside_if_block = False @@ -844,7 +844,7 @@ def __init__(self): self.task_section: Optional[bool] = None super().__init__() - def visit_InvalidSection(self, node): + def visit_InvalidSection(self, node): # noqa: N802 name = node.header.data_tokens[0].value invalid_header = node.header.get_token(Token.INVALID_HEADER) if "Resource file with" in invalid_header.error: @@ -858,7 +858,7 @@ def visit_InvalidSection(self, node): end_col=node.header.end_col_offset + 1, ) - def visit_SectionHeader(self, node): + def visit_SectionHeader(self, node): # noqa: N802 name = node.data_tokens[0].value if not self.section_name_pattern.match(name) or not (name.istitle() or name.isupper()): valid_name = f"*** {node.name.title()} ***" @@ -870,7 +870,7 @@ def visit_SectionHeader(self, node): end_col=node.col_offset + len(name) + 1, ) - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.task_section = None for section in node.sections: if isinstance(section, TestCaseSection): @@ -883,19 +883,19 @@ def visit_File(self, node): break super().visit_File(node) - def visit_Setup(self, node): + def visit_Setup(self, node): # noqa: N802 self.check_setting_name(node.data_tokens[0].value, node) self.check_settings_consistency(node.data_tokens[0].value, node) - visit_SuiteSetup = visit_TestSetup = visit_Teardown = visit_SuiteTeardown = visit_TestTeardown = ( - visit_TestTimeout - ) = visit_TestTemplate = visit_TestTags = visit_ForceTags = visit_DefaultTags = visit_ResourceImport = ( - visit_VariablesImport - ) = visit_Documentation = visit_Tags = visit_Timeout = visit_Template = visit_Arguments = visit_ReturnSetting = ( - visit_Return + visit_SuiteSetup = visit_TestSetup = visit_Teardown = visit_SuiteTeardown = visit_TestTeardown = ( # noqa: N815 + visit_TestTimeout # noqa: N815 + ) = visit_TestTemplate = visit_TestTags = visit_ForceTags = visit_DefaultTags = visit_ResourceImport = ( # noqa: N815 + visit_VariablesImport # noqa: N815 + ) = visit_Documentation = visit_Tags = visit_Timeout = visit_Template = visit_Arguments = visit_ReturnSetting = ( # noqa: N815 + visit_Return # noqa: N815 ) = visit_Setup - def visit_LibraryImport(self, node): + def visit_LibraryImport(self, node): # noqa: N802 self.check_setting_name(node.data_tokens[0].value, node) if ROBOT_VERSION.major < 6: arg_nodes = node.get_tokens(Token.ARGUMENT) @@ -956,7 +956,7 @@ class TestCaseNamingChecker(VisitorChecker): "test-case-name-is-empty", ) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 if not node.name: self.report("test-case-name-is-empty", node=node) else: @@ -1008,12 +1008,12 @@ class VariableNamingChecker(VisitorChecker): # "options": "&{OPTIONS}", This variable is widely used and is relatively safe to overwrite } - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 name_token = node.header.get_token(Token.KEYWORD_NAME) self.parse_embedded_arguments(name_token) self.generic_visit(node) - def visit_Variable(self, node): + def visit_Variable(self, node): # noqa: N802 token = node.data_tokens[0] try: var_name = search_variable(token.value).base @@ -1033,7 +1033,7 @@ def visit_Variable(self, node): ) self.check_for_reserved_naming_or_hyphen(token, "Variable") - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 for token in node.get_tokens(Token.ASSIGN): self.check_for_reserved_naming_or_hyphen(token, "Variable", is_assign=True) if not node.keyword: @@ -1064,7 +1064,7 @@ def check_non_local_variable(self, variable_name: str, node, token): end_col=token.end_col_offset + 1, ) - def visit_Var(self, node): + def visit_Var(self, node): # noqa: N802 if node.errors: # for example invalid variable definition like $var} return variable = node.get_token(Token.VARIABLE) @@ -1075,12 +1075,12 @@ def visit_Var(self, node): if not _is_var_scope_local(node): self.check_non_local_variable(search_variable(variable.value).base, node, variable) - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 for token in node.header.get_tokens(Token.ASSIGN): self.check_for_reserved_naming_or_hyphen(token, "Variable") self.generic_visit(node) - def visit_Arguments(self, node): + def visit_Arguments(self, node): # noqa: N802 for arg in node.get_tokens(Token.ARGUMENT): self.check_for_reserved_naming_or_hyphen(arg, "Argument") @@ -1135,7 +1135,7 @@ def __init__(self): self.parent_type = "" super().__init__() - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 self.assigned_variables = defaultdict(list) self.parent_name = node.name self.parent_type = type(node).__name__ @@ -1144,13 +1144,13 @@ def visit_Keyword(self, node): self.visit_vars_and_find_similar(node) self.generic_visit(node) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 self.assigned_variables = defaultdict(list) self.parent_name = node.name self.parent_type = type(node).__name__ self.generic_visit(node) - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if normalize_robot_name(node.keyword, remove_prefix="builtin.") in SET_VARIABLE_VARIANTS: normalized, assign_value = "", "" for index, token in enumerate(node.data_tokens[1:]): @@ -1166,7 +1166,7 @@ def visit_KeywordCall(self, node): tokens = node.get_tokens(Token.ASSIGN) self.find_similar_variables(tokens, node) - def visit_Var(self, node): + def visit_Var(self, node): # noqa: N802 if node.errors: # for example invalid variable definition like $var} return for arg in node.get_tokens(Token.ARGUMENT): @@ -1175,14 +1175,14 @@ def visit_Var(self, node): if variable: self.find_similar_variables([variable], node, ignore_overwriting=not _is_var_scope_local(node)) - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 for token in node.header.get_tokens(Token.ARGUMENT): self.find_not_nested_variable(token, token.value, is_var=False) tokens = node.header.get_tokens(Token.ASSIGN) self.find_similar_variables(tokens, node) self.generic_visit(node) - def visit_While(self, node): + def visit_While(self, node): # noqa: N802 for token in node.header.get_tokens(Token.ARGUMENT): self.find_not_nested_variable(token, token.value, is_var=False) return self.generic_visit(node) @@ -1194,20 +1194,20 @@ def for_assign_vars(for_node) -> Iterable[str]: else: yield from for_node.assign - def visit_For(self, node): + def visit_For(self, node): # noqa: N802 for token in node.header.get_tokens(Token.ARGUMENT): self.find_not_nested_variable(token, token.value, is_var=False) for var in self.for_assign_vars(node): self.assigned_variables[normalize_robot_var_name(var)].append(var) self.generic_visit(node) - visit_ForLoop = visit_For + visit_ForLoop = visit_For # noqa: N815 - def visit_Return(self, node): + def visit_Return(self, node): # noqa: N802 for token in node.get_tokens(Token.ARGUMENT): self.find_not_nested_variable(token, token.value, is_var=False) - visit_ReturnStatement = visit_Teardown = visit_Timeout = visit_Return + visit_ReturnStatement = visit_Teardown = visit_Timeout = visit_Return # noqa: N815 def parse_embedded_arguments(self, name_token): """Store embedded arguments from keyword name. Ignore embedded variables patterns (${var:pattern}).""" @@ -1364,29 +1364,29 @@ class DeprecatedStatementChecker(VisitorChecker): } create_keywords = {"createdictionary", "createlist"} - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 self.check_if_keyword_is_deprecated(node.keyword, node) self.check_keyword_can_be_replaced_with_var(node.keyword, node) - def visit_SuiteSetup(self, node): + def visit_SuiteSetup(self, node): # noqa: N802 self.check_if_keyword_is_deprecated(node.name, node) - visit_TestSetup = visit_Setup = visit_SuiteTeardown = visit_TestTeardown = visit_Teardown = visit_SuiteSetup + visit_TestSetup = visit_Setup = visit_SuiteTeardown = visit_TestTeardown = visit_Teardown = visit_SuiteSetup # noqa: N815 - def visit_Template(self, node): + def visit_Template(self, node): # noqa: N802 if not node.value: return self.check_if_keyword_is_deprecated(node.value, node) - visit_TestTemplate = visit_Template + visit_TestTemplate = visit_Template # noqa: N815 - def visit_Return(self, node): + def visit_Return(self, node): # noqa: N802 """For RETURN use visit_ReturnStatement - visit_Return will most likely visit RETURN in the future""" if ROBOT_VERSION.major not in (5, 6): return self.check_deprecated_return(node) - def visit_ReturnSetting(self, node): + def visit_ReturnSetting(self, node): # noqa: N802 self.check_deprecated_return(node) def check_deprecated_return(self, node): @@ -1400,7 +1400,7 @@ def check_deprecated_return(self, node): version="5.*", ) - def visit_ForceTags(self, node): + def visit_ForceTags(self, node): # noqa: N802 if ROBOT_VERSION.major < 6: return setting_name = node.data_tokens[0].value.lower() @@ -1455,7 +1455,7 @@ def check_keyword_can_be_replaced_with_var(self, keyword_name, node): end_col=col + len(keyword_name), ) - def visit_LibraryImport(self, node): + def visit_LibraryImport(self, node): # noqa: N802 if ROBOT_VERSION.major < 5 or (ROBOT_VERSION.major == 5 and ROBOT_VERSION.minor == 0): return with_name_token = node.get_token(Token.WITH_NAME) @@ -1468,7 +1468,7 @@ def visit_LibraryImport(self, node): end_col=with_name_token.end_col_offset + 1, ) - def visit_SectionHeader(self, node): + def visit_SectionHeader(self, node): # noqa: N802 if not node.name: return normalized_name = string.capwords(node.name) diff --git a/robocop/checkers/spacing.py b/robocop/checkers/spacing.py index aa1757a49..3dfd61cc5 100644 --- a/robocop/checkers/spacing.py +++ b/robocop/checkers/spacing.py @@ -418,7 +418,7 @@ def check_empty_lines_in_keyword_test(self, node): self.verify_consecutive_empty_lines(reversed(node_lines)) return self.verify_consecutive_empty_lines(reversed(trailing_lines)) - def visit_Statement(self, node): + def visit_Statement(self, node): # noqa: N802 prev_token = None for token in node.tokens: if token.type == Token.EOL: @@ -428,11 +428,11 @@ def visit_Statement(self, node): else: prev_token = None - def visit_VariableSection(self, node): + def visit_VariableSection(self, node): # noqa: N802 self.verify_consecutive_empty_lines(node.body, check_leading=False) self.generic_visit(node) - def visit_SettingSection(self, node): + def visit_SettingSection(self, node): # noqa: N802 self.verify_consecutive_empty_lines(node.body, check_leading=False) self.generic_visit(node) @@ -453,11 +453,11 @@ def verify_empty_lines_between_nodes(self, node, node_type, issue_name, allowed_ ) self.generic_visit(node) - def visit_TestCaseSection(self, node): + def visit_TestCaseSection(self, node): # noqa: N802 allowed_lines = -1 if self.templated_suite else self.param("empty-lines-between-test-cases", "empty_lines") self.verify_empty_lines_between_nodes(node, TestCase, "empty-lines-between-test-cases", allowed_lines) - def visit_KeywordSection(self, node): + def visit_KeywordSection(self, node): # noqa: N802 self.verify_empty_lines_between_nodes( node, Keyword, @@ -465,13 +465,13 @@ def visit_KeywordSection(self, node): self.param("empty-lines-between-keywords", "empty_lines"), ) - def visit_For(self, node): + def visit_For(self, node): # noqa: N802 self.verify_consecutive_empty_lines(node.body, check_trailing=True) self.generic_visit(node) - visit_ForLoop = visit_While = visit_Try = visit_If = visit_For + visit_ForLoop = visit_While = visit_Try = visit_If = visit_For # noqa: N815 - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 for section in node.sections: self.check_empty_lines_after_section(section) for section in node.sections[:-1]: @@ -531,11 +531,11 @@ def __init__(self): self.found, self.tabs, self.spaces = False, False, False super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.found, self.tabs, self.spaces = False, False, False super().visit_File(node) - def visit_Statement(self, node): + def visit_Statement(self, node): # noqa: N802 if self.found: return for token in node.get_tokens(Token.SEPARATOR): @@ -660,14 +660,14 @@ def __init__(self): self.end_of_node = False super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.indents = [] self.parent_indent = 0 self.parent_line = 0 self.end_of_node = False self.generic_visit(node) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 end_index = index_of_first_standalone_comment(node) with block_indent(self, node): for index, child in enumerate(node.body): @@ -675,12 +675,12 @@ def visit_TestCase(self, node): self.end_of_node = True self.visit(child) - visit_Keyword = visit_TestCase + visit_Keyword = visit_TestCase # noqa: N815 - def visit_TestCaseSection(self, node): + def visit_TestCaseSection(self, node): # noqa: N802 self.check_standalone_comments_indent(node) - def visit_KeywordSection(self, node): + def visit_KeywordSection(self, node): # noqa: N802 self.check_standalone_comments_indent(node) def check_standalone_comments_indent(self, node): @@ -700,14 +700,14 @@ def check_standalone_comments_indent(self, node): ) self.generic_visit(node) - def visit_For(self, node): + def visit_For(self, node): # noqa: N802 self.visit_Statement(node.header) with block_indent(self, node): for child in node.body: self.visit(child) self.visit_Statement(node.end) - visit_While = visit_ForLoop = visit_For + visit_While = visit_ForLoop = visit_For # noqa: N815 def get_common_if_indent(self, node): indents = count_indents(node) @@ -732,7 +732,7 @@ def visit_statements_in_branch(self, node): for child in node.body: self.visit(child) - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 self.visit_Statement(node.header) if node.type == "INLINE IF": return @@ -743,7 +743,7 @@ def visit_If(self, node): self.indents.pop() self.visit_Statement(node.end) - def visit_IfBranch(self, node): + def visit_IfBranch(self, node): # noqa: N802 indent = self.indents.pop() self.visit_Statement(node.header) self.indents.append(indent) @@ -751,7 +751,7 @@ def visit_IfBranch(self, node): if node.orelse is not None: self.visit_IfBranch(node.orelse) - def visit_Try(self, node): + def visit_Try(self, node): # noqa: N802 self.visit_Statement(node.header) self.get_common_try_indent(node) self.visit_statements_in_branch(node) @@ -760,7 +760,7 @@ def visit_Try(self, node): self.indents.pop() self.visit_Statement(node.end) - def visit_TryBranch(self, node): + def visit_TryBranch(self, node): # noqa: N802 indent = self.indents.pop() self.visit_Statement(node.header) self.indents.append(indent) @@ -775,7 +775,7 @@ def get_required_indent(self, statement): return self.param("bad-indent", "indent") * len(self.indents) return self.indents[-1] - def visit_Statement(self, statement): + def visit_Statement(self, statement): # noqa: N802 if statement is None or isinstance(statement, EmptyLine) or not self.indents: return # Ignore indent if current line is on the same line as parent, i.e. test case header or inline IFs @@ -816,7 +816,7 @@ class MisalignedContinuation(VisitorChecker, ModelVisitor): def is_inline_if(node): return isinstance(node.header, InlineIfHeader) - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 # suppress the rules if the multiline-inline-if is already reported if ROBOT_VERSION.major >= 5 and self.is_inline_if(node): return @@ -829,7 +829,7 @@ def is_ignorable_run_keyword(self, node) -> bool: ) # TODO: test on different version, may lack .keyword - def visit_Statement(self, node): + def visit_Statement(self, node): # noqa: N802 if not node.data_tokens or self.is_ignorable_run_keyword(node): return starting_row = self.get_indent(node.tokens) @@ -934,7 +934,7 @@ class LeftAlignedChecker(VisitorChecker): "variables": "Variables", } - def visit_VariableSection(self, node): + def visit_VariableSection(self, node): # noqa: N802 for child in node.body: if not child.data_tokens: continue @@ -946,7 +946,7 @@ def visit_VariableSection(self, node): pos = child.get_token(Token.ARGUMENT).col_offset + 1 self.report("variable-should-be-left-aligned", lineno=token.lineno, col=1, end_col=pos) - def visit_SettingSection(self, node): + def visit_SettingSection(self, node): # noqa: N802 for child in node.body: for error in get_errors(child): if "Non-existing setting" in error: @@ -982,7 +982,7 @@ def parse_error(self, node, error): class ArgumentsChecker(VisitorChecker): reports = ("first-argument-in-new-line",) - def visit_Arguments(self, node): + def visit_Arguments(self, node): # noqa: N802 eol_already = None for t in node.tokens: if t.type == Token.EOL: diff --git a/robocop/checkers/tags.py b/robocop/checkers/tags.py index 390d81227..9c892fcc1 100644 --- a/robocop/checkers/tags.py +++ b/robocop/checkers/tags.py @@ -240,12 +240,12 @@ class TagNameChecker(VisitorChecker): "robot:private", } - def visit_ForceTags(self, node): + def visit_ForceTags(self, node): # noqa: N802 self.check_tags(node) - visit_DefaultTags = visit_Tags = visit_KeywordTags = visit_ForceTags + visit_DefaultTags = visit_Tags = visit_KeywordTags = visit_ForceTags # noqa: N815 - def visit_Documentation(self, node): + def visit_Documentation(self, node): # noqa: N802 """ Parse tags from last line of documentation. @@ -282,7 +282,7 @@ def _get_new_tag_token(self, tag_value: str, lineno: int, col_offset: int) -> To subtoken.col_offset = col_offset return subtoken - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 self.is_keyword = True super().generic_visit(node) self.is_keyword = False @@ -369,7 +369,7 @@ def __init__(self): self.in_keywords = False super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.tags = [] self.test_tags = set() self.default_tags = set() @@ -400,24 +400,24 @@ def visit_File(self, node): node=report_node, ) - def visit_KeywordSection(self, node): + def visit_KeywordSection(self, node): # noqa: N802 self.in_keywords = True self.generic_visit(node) self.in_keywords = False - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 self.test_cases_count += 1 self.generic_visit(node) - def visit_ForceTags(self, node): + def visit_ForceTags(self, node): # noqa: N802 self.test_tags = {token.value for token in node.data_tokens[1:]} self.test_tags_node = node - def visit_DefaultTags(self, node): + def visit_DefaultTags(self, node): # noqa: N802 self.default_tags = {token.value for token in node.data_tokens[1:]} self.default_tags_node = node - def visit_Tags(self, node): + def visit_Tags(self, node): # noqa: N802 if not node.values: suffix = "" if self.in_keywords else ". Consider using NONE if you want to overwrite the Default Tags" self.report( @@ -459,7 +459,7 @@ def __init__(self): self.in_keywords = False super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.tags_in_keywords = [] self.keyword_tags = set() self.keyword_tags_node = None @@ -481,20 +481,20 @@ def visit_File(self, node): node=report_node, ) - def visit_Keyword(self, node): + def visit_Keyword(self, node): # noqa: N802 self.keywords_count += 1 self.generic_visit(node) - def visit_KeywordTags(self, node): + def visit_KeywordTags(self, node): # noqa: N802 self.keyword_tags = {token.value for token in node.data_tokens[1:]} self.keyword_tags_node = node - def visit_KeywordSection(self, node): + def visit_KeywordSection(self, node): # noqa: N802 self.in_keywords = True self.generic_visit(node) self.in_keywords = False - def visit_Tags(self, node): + def visit_Tags(self, node): # noqa: N802 if self.in_keywords: self.tags_in_keywords.append([tag.value for tag in node.data_tokens[1:]]) for tag in node.data_tokens[1:]: diff --git a/robocop/utils/disablers.py b/robocop/utils/disablers.py index c519fe1bc..9902255f4 100644 --- a/robocop/utils/disablers.py +++ b/robocop/utils/disablers.py @@ -41,7 +41,7 @@ def __init__(self, model): self.rules = defaultdict(DisablersInFile().copy) self.visit(model) - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.file_end = node.end_lineno self.generic_visit(node) @@ -60,36 +60,36 @@ def parse_disablers_in_node(self, node, last_line=None): self.rules[rule_name].lines.update(rule_disabler.lines) self.disablers_in_scope.pop() - def visit_KeywordSection(self, node): + def visit_KeywordSection(self, node): # noqa: N802 self.keyword_or_test_section = True self.parse_disablers_in_node(node) self.keyword_or_test_section = False - visit_TestCaseSection = visit_KeywordSection + visit_TestCaseSection = visit_KeywordSection # noqa: N815 - def visit_Section(self, node): + def visit_Section(self, node): # noqa: N802 self.is_first_comment_section = self.is_first_comment_section and isinstance(node, CommentSection) self.parse_disablers_in_node(node) self.is_first_comment_section = False - visit_TestCase = visit_Keyword = visit_Try = visit_For = visit_ForLoop = visit_While = visit_Section + visit_TestCase = visit_Keyword = visit_Try = visit_For = visit_ForLoop = visit_While = visit_Section # noqa: N815 - def visit_If(self, node): + def visit_If(self, node): # noqa: N802 last_line = node.body[-1].end_lineno if node.body else None self.parse_disablers_in_node(node, last_line) - def visit_Statement(self, node): + def visit_Statement(self, node): # noqa: N802 for comment in node.get_tokens(Token.COMMENT): self.parse_comment_token(comment, is_inline=True) - def visit_TestCaseName(self, node): + def visit_TestCaseName(self, node): # noqa: N802 """Save last test case / keyword header line number to check if comment is standalone.""" self.last_name_header_line = node.lineno self.visit_Statement(node) - visit_KeywordName = visit_TestCaseName + visit_KeywordName = visit_TestCaseName # noqa: N815 - def visit_Comment(self, node): + def visit_Comment(self, node): # noqa: N802 for comment in node.get_tokens(Token.COMMENT): # Comment is only inline if it is next to test/kw name is_inline = comment.lineno == self.last_name_header_line diff --git a/robocop/utils/file_types.py b/robocop/utils/file_types.py index a885b4e8e..e5d553404 100644 --- a/robocop/utils/file_types.py +++ b/robocop/utils/file_types.py @@ -52,7 +52,7 @@ def __init__(self, exec_dir): self.exec_dir = exec_dir self.source = None - def visit_ResourceImport(self, node): + def visit_ResourceImport(self, node): # noqa: N802 """ Check all imports in scanned file. If one of our scanned file is imported somewhere else it means this file is resource type diff --git a/robocop/utils/misc.py b/robocop/utils/misc.py index 8f9b4f0d7..3ddfba072 100644 --- a/robocop/utils/misc.py +++ b/robocop/utils/misc.py @@ -139,19 +139,19 @@ def __init__(self): self.variables_sign_counter = Counter() self.variables_most_common = None - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.generic_visit(node) if len(self.keyword_sign_counter) >= 2: self.keyword_most_common = self.keyword_sign_counter.most_common(1)[0][0] if len(self.variables_sign_counter) >= 2: self.variables_most_common = self.variables_sign_counter.most_common(1)[0][0] - def visit_KeywordCall(self, node): + def visit_KeywordCall(self, node): # noqa: N802 if node.assign: # if keyword returns any value sign = self.get_assignment_sign(node.assign[-1]) self.keyword_sign_counter[sign] += 1 - def visit_VariableSection(self, node): + def visit_VariableSection(self, node): # noqa: N802 for child in node.body: if not isinstance(child, Variable): continue @@ -243,7 +243,7 @@ class TestTemplateFinder(ast.NodeVisitor): def __init__(self): self.templated = False - def visit_TestTemplate(self, node): + def visit_TestTemplate(self, node): # noqa: N802 self.templated = bool(node.value) diff --git a/tests/atest/rules/custom_tests/project_checker/external_project_checker/__init__.py b/tests/atest/rules/custom_tests/project_checker/external_project_checker/__init__.py index c70dabb01..94d1e8805 100644 --- a/tests/atest/rules/custom_tests/project_checker/external_project_checker/__init__.py +++ b/tests/atest/rules/custom_tests/project_checker/external_project_checker/__init__.py @@ -29,11 +29,11 @@ def __init__(self): self.test_count = 0 super().__init__() - def visit_File(self, node): + def visit_File(self, node): # noqa: N802 self.sources.append(node.source) self.generic_visit(node) - def visit_TestCase(self, node): + def visit_TestCase(self, node): # noqa: N802 self.test_count += 1 def scan_project(self) -> List[Message]: diff --git a/tests/test_data/ext_rules/deprecated/deprecated_rules.py b/tests/test_data/ext_rules/deprecated/deprecated_rules.py index a2297ca56..c35b840f2 100644 --- a/tests/test_data/ext_rules/deprecated/deprecated_rules.py +++ b/tests/test_data/ext_rules/deprecated/deprecated_rules.py @@ -17,8 +17,8 @@ class FirstChecker(VisitorChecker): reports = ("not-deprecated", "deprecated") - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("not-deprecated", node=node) - def visit_TestCase(self, node): # noqa + def visit_TestCase(self, node): # noqa: N802 self.report("deprecated", node=node) diff --git a/tests/test_data/ext_rules/disabled_by_default/external_rule.py b/tests/test_data/ext_rules/disabled_by_default/external_rule.py index 7299746a7..df8573ff6 100644 --- a/tests/test_data/ext_rules/disabled_by_default/external_rule.py +++ b/tests/test_data/ext_rules/disabled_by_default/external_rule.py @@ -11,5 +11,5 @@ class SmthChecker(VisitorChecker): reports = ("smth",) - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("smth", node=node) diff --git a/tests/test_data/ext_rules/disabled_by_default/external_rule2.py b/tests/test_data/ext_rules/disabled_by_default/external_rule2.py index efc02f495..b2fe351b2 100644 --- a/tests/test_data/ext_rules/disabled_by_default/external_rule2.py +++ b/tests/test_data/ext_rules/disabled_by_default/external_rule2.py @@ -17,5 +17,5 @@ class SmthChecker(VisitorChecker): reports = ("smth2",) - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("smth", node=node) diff --git a/tests/test_data/ext_rules/ext_rule/external_rule.py b/tests/test_data/ext_rules/ext_rule/external_rule.py index 7299746a7..df8573ff6 100644 --- a/tests/test_data/ext_rules/ext_rule/external_rule.py +++ b/tests/test_data/ext_rules/ext_rule/external_rule.py @@ -11,5 +11,5 @@ class SmthChecker(VisitorChecker): reports = ("smth",) - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("smth", node=node) diff --git a/tests/test_data/ext_rules/ext_rule/external_rule2.py b/tests/test_data/ext_rules/ext_rule/external_rule2.py index d6b598ba6..667deee04 100644 --- a/tests/test_data/ext_rules/ext_rule/external_rule2.py +++ b/tests/test_data/ext_rules/ext_rule/external_rule2.py @@ -11,5 +11,5 @@ class SmthChecker(VisitorChecker): reports = ("smth2",) - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("smth", node=node) diff --git a/tests/test_data/ext_rules/ext_rule_duplicate/external_rule_dup.py b/tests/test_data/ext_rules/ext_rule_duplicate/external_rule_dup.py index b0a56cf67..6d8b5dc2e 100644 --- a/tests/test_data/ext_rules/ext_rule_duplicate/external_rule_dup.py +++ b/tests/test_data/ext_rules/ext_rule_duplicate/external_rule_dup.py @@ -11,5 +11,5 @@ class SmthChecker(VisitorChecker): reports = ("smth",) - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("smth", node=node) diff --git a/tests/test_data/ext_rules/ext_rule_invalid_reports/external_rule.py b/tests/test_data/ext_rules/ext_rule_invalid_reports/external_rule.py index 34757619f..0f97e91cd 100644 --- a/tests/test_data/ext_rules/ext_rule_invalid_reports/external_rule.py +++ b/tests/test_data/ext_rules/ext_rule_invalid_reports/external_rule.py @@ -11,5 +11,5 @@ class SmthChecker(VisitorChecker): reports = ("idontexist",) - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("smth", node=node) diff --git a/tests/test_data/ext_rules/ext_rule_missing_register/external_rule_missing_register.py b/tests/test_data/ext_rules/ext_rule_missing_register/external_rule_missing_register.py index 7299746a7..df8573ff6 100644 --- a/tests/test_data/ext_rules/ext_rule_missing_register/external_rule_missing_register.py +++ b/tests/test_data/ext_rules/ext_rule_missing_register/external_rule_missing_register.py @@ -11,5 +11,5 @@ class SmthChecker(VisitorChecker): reports = ("smth",) - def visit_Keyword(self, node): # noqa + def visit_Keyword(self, node): # noqa: N802 self.report("smth", node=node) diff --git a/tests/test_data/ext_rules/ext_rule_module/RobocopRules/some_rules.py b/tests/test_data/ext_rules/ext_rule_module/RobocopRules/some_rules.py index 4b1d14155..9b5fe9606 100644 --- a/tests/test_data/ext_rules/ext_rule_module/RobocopRules/some_rules.py +++ b/tests/test_data/ext_rules/ext_rule_module/RobocopRules/some_rules.py @@ -6,6 +6,6 @@ class CustomRuleChecker(VisitorChecker): reports = ("external-rule",) - def visit_KeywordCall(self, node): # noqa + def visit_KeywordCall(self, node): # noqa: N802 if node.keyword and "Example" not in node.keyword: self.report("external-rule", node=node) diff --git a/tests/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/some_rules.py b/tests/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/some_rules.py index 0ef994fa6..825efae9f 100644 --- a/tests/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/some_rules.py +++ b/tests/test_data/ext_rules/ext_rule_module/RobocopRules/submodule/some_rules.py @@ -9,6 +9,6 @@ class CustomRuleChecker2(VisitorChecker): reports = ("external-rule2",) - def visit_KeywordCall(self, node): # noqa + def visit_KeywordCall(self, node): # noqa: N802 if node.keyword and "Example" not in node.keyword: self.report("external-rule2", node=node) diff --git a/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/single_rule.py b/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/single_rule.py index 3db19b58b..623026495 100644 --- a/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/single_rule.py +++ b/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/single_rule.py @@ -16,6 +16,6 @@ class CustomRuleChecker(VisitorChecker): reports = ("external-rule",) - def visit_KeywordCall(self, node): # noqa + def visit_KeywordCall(self, node): # noqa: N802 if node.keyword and "Example" not in node.keyword: self.report("external-rule", node=node) diff --git a/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/some_rules.py b/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/some_rules.py index 0ef994fa6..825efae9f 100644 --- a/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/some_rules.py +++ b/tests/test_data/ext_rules/ext_rule_module_simple_import/RobocopRules/submodule/some_rules.py @@ -9,6 +9,6 @@ class CustomRuleChecker2(VisitorChecker): reports = ("external-rule2",) - def visit_KeywordCall(self, node): # noqa + def visit_KeywordCall(self, node): # noqa: N802 if node.keyword and "Example" not in node.keyword: self.report("external-rule2", node=node)