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

Ruff N802,N815: Fix mixed case issues #1133

Merged
merged 2 commits into from
Oct 28, 2024
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
6 changes: 3 additions & 3 deletions docs/external_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/releasenotes/5.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion robocop/checkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions robocop/checkers/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions robocop/checkers/community_rules/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions robocop/checkers/community_rules/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
16 changes: 8 additions & 8 deletions robocop/checkers/community_rules/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions robocop/checkers/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions robocop/checkers/duplications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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, "${}@&"))
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading