From 636b577e4bba3ce4127f798b2a90e028eae3982c Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Sat, 14 Sep 2024 16:33:03 +0900 Subject: [PATCH] Bring better linting --- nsiqcppstyle_checker.py | 12 ++---- nsiqcppstyle_exe.py | 10 ++--- nsiqcppstyle_lexer.py | 37 ++++++++++--------- nsiqcppstyle_reporter.py | 4 +- nsiqcppstyle_rulehelper.py | 9 ++--- nsiqcppstyle_rulemanager.py | 2 +- pyproject.toml | 2 + ..._bufferoverflow_risky_function_for_unix.py | 4 +- ...fferoverflow_risky_function_for_windows.py | 2 +- ...1_A_do_not_start_filename_with_underbar.py | 2 +- ..._not_use_special_characters_in_filename.py | 2 +- ...presentitive_classname_for_cpp_filename.py | 2 +- ...H_do_not_use_underbars_for_cpp_filename.py | 2 +- ...2_H_do_not_use_uppercase_for_c_filename.py | 2 +- ...on_name_with_is_or_has_when_return_bool.py | 2 +- ...start_function_name_with_lowercase_unix.py | 2 +- ...t_function_name_with_upperrcase_windows.py | 2 +- ...art_private_function_name_with_underbar.py | 2 +- ...1_B_indent_each_enum_item_in_enum_block.py | 2 +- ..._locate_each_enum_item_in_seperate_line.py | 2 +- rules/RULE_4_2_A_A_space_around_operator.py | 8 ++-- rules/RULE_4_2_A_B_space_around_word.py | 2 +- ...nction_should_be_located_in_end_of_line.py | 2 +- ..._4_5_A_indent_blocks_inside_of_function.py | 2 +- ...vide_doxygen_class_comment_on_class_def.py | 2 +- ...ygen_namespace_comment_on_namespace_def.py | 2 +- ...de_doxygen_struct_comment_on_struct_def.py | 2 +- ..._function_comment_on_function_in_header.py | 2 +- ...en_function_comment_on_function_in_impl.py | 2 +- ..._A_do_not_omit_function_parameter_names.py | 4 +- ...t_use_more_than_5_paramters_in_function.py | 2 +- ..._write_less_than_200_lines_for_function.py | 2 +- ...o_not_use_lowercase_for_macro_constants.py | 2 +- ...LE_6_5_B_do_not_use_macro_for_constants.py | 2 +- ..._1_A_do_not_use_hardcorded_include_path.py | 2 +- rules/RULE_9_2_D_use_reentrant_function.py | 2 +- 36 files changed, 70 insertions(+), 74 deletions(-) diff --git a/nsiqcppstyle_checker.py b/nsiqcppstyle_checker.py index 3ceac93..a549000 100644 --- a/nsiqcppstyle_checker.py +++ b/nsiqcppstyle_checker.py @@ -380,7 +380,7 @@ def t_CPPCOMMENT(t): def t_error(t): - console.Out.Verbose("Illegal character '%s'" % t.value[0], t.lexer.lineno) + console.Out.Verbose(f"Illegal character '{t.value[0]}'", t.lexer.lineno) t.lexer.skip(1) @@ -408,7 +408,7 @@ def __init__(self, filename, data=None): except UnicodeDecodeError as ex: console.Out.Ci("[ERROR] UnicodeDecodeError in CppLexerNavigator: " + str(ex)) console.Out.Ci( - "[ERROR] Exception occurred reading file '%s', convert from UTF16LE to UTF8" % (filename), + f"[ERROR] Exception occurred reading file '{filename}', convert from UTF16LE to UTF8", ) raise self.lines = self.data.splitlines() @@ -922,9 +922,7 @@ def HasBody(self): if token_id3 is None and token_id2 is not None: return True - if token_id2 is not None and token_id2.lexpos < token_id3.lexpos: - return True - return False + return bool(token_id2 is not None and token_id2.lexpos < token_id3.lexpos) class Context: @@ -946,9 +944,7 @@ def IsContextEnd(self, token): return token == self.endToken def InScope(self, token): - if token.lexpos >= self.startToken.lexpos and token.lexpos <= self.endToken.lexpos: - return True - return False + return bool(token.lexpos >= self.startToken.lexpos and token.lexpos <= self.endToken.lexpos) class ContextStack: diff --git a/nsiqcppstyle_exe.py b/nsiqcppstyle_exe.py index 9e274cc..66b75de 100755 --- a/nsiqcppstyle_exe.py +++ b/nsiqcppstyle_exe.py @@ -259,7 +259,7 @@ def main(): extLangMapCopy = copy.deepcopy(extLangMap) targetName = targetPath.name console.Out.Ci(console.Separator) - console.Out.Ci("= Analyzing %s " % targetName) + console.Out.Ci(f"= Analyzing {targetName} ") if filterPath != "": filefilterPath = filterPath @@ -281,7 +281,7 @@ def main(): # Load Rule if len(filter.nsiqCppStyleRules) == 0: - ShowMessageAndExit("Error!. Rules must be set in %s" % filefilterPath, False) + ShowMessageAndExit(f"Error!. Rules must be set in {filefilterPath}", False) continue ruleManager.LoadRules(filter.nsiqCppStyleRules) @@ -293,7 +293,7 @@ def main(): console.Out.Info(filter.to_string()) console.Out.Ci(console.Separator) - console.Out.Verbose("* run nsiqcppstyle analysis on %s" % targetName) + console.Out.Verbose(f"* run nsiqcppstyle analysis on {targetName}") # if the target is file, analyze it without condition if targetPath.is_file(): @@ -363,7 +363,7 @@ def GetRealTargetPaths(args): targetPaths.append(realPath) # CheckPathPermission(realPath, "Target directory") if not realPath.exists(): - ShowMessageAndExit("Error!: Target directory %s does not exist" % eachTarget) + ShowMessageAndExit(f"Error!: Target directory {eachTarget} does not exist") return targetPaths @@ -578,7 +578,7 @@ def AddVarMap(self, keyValuePairString, where): def GetCliKeyValueMap(kvList): - if kvList == None: + if kvList is None: return {} varMap = {} diff --git a/nsiqcppstyle_lexer.py b/nsiqcppstyle_lexer.py index d500caa..b2722a9 100644 --- a/nsiqcppstyle_lexer.py +++ b/nsiqcppstyle_lexer.py @@ -186,11 +186,11 @@ def clone(self, object=None): # ------------------------------------------------------------ def _writetab_impl(self, tabfile, tf): tf.write(f"# {tabfile}.py. This file automatically created by PLY (version {__version__}). Don't edit!\n") - tf.write("_tabversion = %s\n" % repr(__version__)) - tf.write("_lextokens = %s\n" % repr(self.lextokens)) - tf.write("_lexreflags = %s\n" % repr(self.lexreflags)) - tf.write("_lexliterals = %s\n" % repr(self.lexliterals)) - tf.write("_lexstateinfo = %s\n" % repr(self.lexstateinfo)) + tf.write(f"_tabversion = {__version__!r}\n") + tf.write(f"_lextokens = {self.lextokens!r}\n") + tf.write(f"_lexreflags = {self.lexreflags!r}\n") + tf.write(f"_lexliterals = {self.lexliterals!r}\n") + tf.write(f"_lexstateinfo = {self.lexstateinfo!r}\n") tabre = {} # Collect all functions in the initial state @@ -207,8 +207,8 @@ def _writetab_impl(self, tabfile, tf): titem.append((self.lexstateretext[key][i], _funcs_to_names(lre[i][1], self.lexstaterenames[key][i]))) tabre[key] = titem - tf.write("_lexstatere = %s\n" % repr(tabre)) - tf.write("_lexstateignore = %s\n" % repr(self.lexstateignore)) + tf.write(f"_lexstatere = {tabre!r}\n") + tf.write(f"_lexstateignore = {self.lexstateignore!r}\n") taberr = {} for key, ef in self.lexstateerrorf.items(): @@ -216,7 +216,7 @@ def _writetab_impl(self, tabfile, tf): taberr[key] = ef.__name__ else: taberr[key] = None - tf.write("_lexstateerrorf = %s\n" % repr(taberr)) + tf.write(f"_lexstateerrorf = {taberr!r}\n") # ------------------------------------------------------------ # writetab() - Write lexer information to a table file @@ -236,10 +236,10 @@ def readtab(self, tabfile, fdict): if isinstance(tabfile, types.ModuleType): lextab = tabfile elif sys.version_info[0] < 3: - exec("import %s as lextab" % tabfile) + exec(f"import {tabfile} as lextab") else: env = {} - exec("import %s as lextab" % tabfile, env, env) + exec(f"import {tabfile} as lextab", env, env) lextab = env["lextab"] if getattr(lextab, "_tabversion", "0.0") != __version__: @@ -414,7 +414,8 @@ def token(self): if lexpos == self.lexpos: # Error method didn't change text position at all. This # is an error. - raise LexError("Scanning error. Illegal character '%s'" % (lexdata[lexpos]), lexdata[lexpos:]) + msg = f"Scanning error. Illegal character '{lexdata[lexpos]}'" + raise LexError(msg, lexdata[lexpos:]) lexpos = self.lexpos if not newtok: continue @@ -656,7 +657,7 @@ def validate_literals(self): continue except TypeError: - self.log.error("Invalid literals specification. literals must be a sequence of characters") + self.log.exception("Invalid literals specification. literals must be a sequence of characters") self.error = 1 def get_states(self): @@ -680,7 +681,7 @@ def get_states(self): self.log.error("State name %s must be a string", repr(name)) self.error = 1 continue - if not (statetype == "inclusive" or statetype == "exclusive"): + if statetype not in ("inclusive", "exclusive"): self.log.error("State type for state %s must be 'inclusive' or 'exclusive'", name) self.error = 1 continue @@ -803,9 +804,9 @@ def validate_rules(self): self.error = 1 except re.error: _etype, e, _etrace = sys.exc_info() - self.log.error("%s:%d: Invalid regular expression for rule '%s'. %s", file, line, f.__name__, e) + self.log.exception("%s:%d: Invalid regular expression for rule '%s'. %s", file, line, f.__name__, e) if "#" in f.__doc__: - self.log.error( + self.log.exception( "%s:%d. Make sure '#' in rule '%s' is escaped with '\\#'", file, line, @@ -833,9 +834,9 @@ def validate_rules(self): self.error = 1 except re.error: _etype, e, _etrace = sys.exc_info() - self.log.error("Invalid regular expression for rule '%s'. %s", name, e) + self.log.exception("Invalid regular expression for rule '%s'. %s", name, e) if "#" in r: - self.log.error("Make sure '#' in rule '%s' is escaped with '\\#'", name) + self.log.exception("Make sure '#' in rule '%s' is escaped with '\\#'", name) self.error = 1 if not self.funcsym[state] and not self.strsym[state]: @@ -883,7 +884,7 @@ def validate_file(self, filename): lines = f.readlines() except UnicodeDecodeError as ex: console.Out.Ci("[ERROR] UnicodeDecodeError in validate_file: " + str(ex)) - console.Out.Ci("[ERROR] Exception occurred reading file '%s', convert from UTF16LE to UTF8" % (filename)) + console.Out.Ci(f"[ERROR] Exception occurred reading file '{filename}', convert from UTF16LE to UTF8") raise except OSError: return # Couldn't find the file. Don't worry about it diff --git a/nsiqcppstyle_reporter.py b/nsiqcppstyle_reporter.py index 19692c8..3aceb9f 100644 --- a/nsiqcppstyle_reporter.py +++ b/nsiqcppstyle_reporter.py @@ -75,7 +75,7 @@ def ReportSummaryToScreen(analyzedFiles, nsiqcppstyle_state, filter): console.Out.Ci(" ** Total Errors Occurs : %d" % nsiqcppstyle_state.error_count) console.Out.Ci(" ** Total Analyzed Files : %d" % len(analyzedFiles)) console.Out.Ci(" ** Total Violated Files Count: %d" % violatedFileCount) - console.Out.Ci(" ** Build Quality : %.2f%%" % buildQuality) + console.Out.Ci(f" ** Build Quality : {buildQuality:.2f}%") if console.IsLevelDisplayed(console.Level.Info): console.Out.Info("\n================================ Violated Rule Details ===============================") for checker in nsiqcppstyle_state.errorPerChecker: @@ -159,7 +159,7 @@ def EndTarget(): def StartFile(dirname, filename): if _nsiqcppstyle_state.output_format == "xml": - writer.write("\n" % (os.path.join(target, dirname[1:], filename))) + writer.write(f"\n") def EndFile(): diff --git a/nsiqcppstyle_rulehelper.py b/nsiqcppstyle_rulehelper.py index 9f53c03..3e9b2ea 100644 --- a/nsiqcppstyle_rulehelper.py +++ b/nsiqcppstyle_rulehelper.py @@ -83,9 +83,8 @@ def GetIndentation(token): def IsConstructor(value, fullName, context): """Check if the passed value is the constructor or destructor""" - if "::" in value and "::" in fullName: - if value == fullName: - return True + if "::" in value and "::" in fullName and value == fullName: + return True value = value.replace("~", "").split("::")[-1] # remove class and dtor if needed fullName = fullName.replace("~", "") names = fullName.split("::") @@ -108,6 +107,4 @@ def IsOperator(value): operator_type = value.removeprefix("operator") if operator_type == "": return True - if operator_type[0].isalnum(): - return False - return True + return not operator_type[0].isalnum() diff --git a/nsiqcppstyle_rulemanager.py b/nsiqcppstyle_rulemanager.py index 2af38c8..71b6eb6 100644 --- a/nsiqcppstyle_rulemanager.py +++ b/nsiqcppstyle_rulemanager.py @@ -85,7 +85,7 @@ def LoadRules(self, checkingRuleNames): for ruleName in checkingRuleNames: count = self.availRuleNames.count(ruleName) if count == 0: - console.Out.Error("%s does not exist or incompatible." % ruleName) + console.Out.Error(f"{ruleName} does not exist or incompatible.") continue console.Out.Info(" - ", ruleName, "is applied.") ruleModule = __import__("rules." + ruleName) diff --git a/pyproject.toml b/pyproject.toml index b0b1266..960e3a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,6 +168,8 @@ ignore = [ "PLR0912", "PLR0913", "PLR0915", + # Print is used heavily + "T201", ] unfixable = [ # Don't touch unused imports diff --git a/rules/RULE_10_1_A_do_not_use_bufferoverflow_risky_function_for_unix.py b/rules/RULE_10_1_A_do_not_use_bufferoverflow_risky_function_for_unix.py index 752ea8a..2213a5c 100644 --- a/rules/RULE_10_1_A_do_not_use_bufferoverflow_risky_function_for_unix.py +++ b/rules/RULE_10_1_A_do_not_use_bufferoverflow_risky_function_for_unix.py @@ -66,12 +66,12 @@ def RunRule(lexer, contextStack): unsafe_alternative = True # elif unknown namespace => unknown safety if unsafe_alternative: - nsiqcppstyle_reporter.Error(t, __name__, "Do not use bufferoverflow risky function(%s)" % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Do not use bufferoverflow risky function({t.value})") elif not safe_alternative: nsiqcppstyle_reporter.Error( t, __name__, - "Caution: Uknown imlementation of a bufferoverflow risky function(%s)" % t.value, + f"Caution: Uknown imlementation of a bufferoverflow risky function({t.value})", ) diff --git a/rules/RULE_10_1_B_do_not_use_bufferoverflow_risky_function_for_windows.py b/rules/RULE_10_1_B_do_not_use_bufferoverflow_risky_function_for_windows.py index cbb2adc..b9b2591 100644 --- a/rules/RULE_10_1_B_do_not_use_bufferoverflow_risky_function_for_windows.py +++ b/rules/RULE_10_1_B_do_not_use_bufferoverflow_risky_function_for_windows.py @@ -92,7 +92,7 @@ def RunRule(lexer, contextStack): if t2 is not None and t2.type == "LPAREN": t3 = lexer.PeekPrevTokenSkipWhiteSpaceAndComment() if t3 is None or t3.type != "PERIOD": - nsiqcppstyle_reporter.Error(t, __name__, "Do not use burfferoverflow risky function(%s)" % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Do not use buffer-overflow risky function({t.value})") ruleManager.AddFunctionScopeRule(RunRule) diff --git a/rules/RULE_3_1_A_do_not_start_filename_with_underbar.py b/rules/RULE_3_1_A_do_not_start_filename_with_underbar.py index 7bee11c..746e991 100644 --- a/rules/RULE_3_1_A_do_not_start_filename_with_underbar.py +++ b/rules/RULE_3_1_A_do_not_start_filename_with_underbar.py @@ -22,7 +22,7 @@ def RunRule(lexer, filename, dirname): nsiqcppstyle_reporter.Error( nsiqcppstyle_reporter.DummyToken(lexer.filename, "", 0, 0), __name__, - "File name(%s) should not start with underbar." % filename, + f"File name({filename}) should not start with underbar.", ) diff --git a/rules/RULE_3_2_CD_do_not_use_special_characters_in_filename.py b/rules/RULE_3_2_CD_do_not_use_special_characters_in_filename.py index 766a445..66ae8fd 100644 --- a/rules/RULE_3_2_CD_do_not_use_special_characters_in_filename.py +++ b/rules/RULE_3_2_CD_do_not_use_special_characters_in_filename.py @@ -24,7 +24,7 @@ def RunRule(lexer, filename, dirname): nsiqcppstyle_reporter.Error( DummyToken(lexer.filename, "", 0, 0), __name__, - "Do not use special characters in file name (%s)." % filename, + f"Do not use special characters in file name ({filename}).", ) diff --git a/rules/RULE_3_2_F_use_representitive_classname_for_cpp_filename.py b/rules/RULE_3_2_F_use_representitive_classname_for_cpp_filename.py index 1c7710c..884ab3a 100644 --- a/rules/RULE_3_2_F_use_representitive_classname_for_cpp_filename.py +++ b/rules/RULE_3_2_F_use_representitive_classname_for_cpp_filename.py @@ -76,7 +76,7 @@ def RunFileEndRule(lexer, filename, dirname): nsiqcppstyle_reporter.Error( DummyToken(lexer.filename, "", 0, 0), __name__, - "The filename does not represent the classnames (%s)" % (classname), + f"The filename does not represent the classnames ({classname})", ) diff --git a/rules/RULE_3_2_H_do_not_use_underbars_for_cpp_filename.py b/rules/RULE_3_2_H_do_not_use_underbars_for_cpp_filename.py index 58d37c8..ac146fd 100644 --- a/rules/RULE_3_2_H_do_not_use_underbars_for_cpp_filename.py +++ b/rules/RULE_3_2_H_do_not_use_underbars_for_cpp_filename.py @@ -30,7 +30,7 @@ def RunRule(lexer, filename, dirname): nsiqcppstyle_reporter.Error( DummyToken(lexer.filename, "", 0, 0), __name__, - "Do not use underbar for cpp file name (%s)." % filename, + f"Do not use underbar for cpp file name ({filename}).", ) diff --git a/rules/RULE_3_2_H_do_not_use_uppercase_for_c_filename.py b/rules/RULE_3_2_H_do_not_use_uppercase_for_c_filename.py index 5d59147..541f5ba 100644 --- a/rules/RULE_3_2_H_do_not_use_uppercase_for_c_filename.py +++ b/rules/RULE_3_2_H_do_not_use_uppercase_for_c_filename.py @@ -24,7 +24,7 @@ def RunRule(lexer, filename, dirname): nsiqcppstyle_reporter.Error( DummyToken(lexer.filename, "", 0, 0), __name__, - "Do not use uppercase for c file name (%s)." % filename, + f"Do not use uppercase for c file name ({filename}).", ) diff --git a/rules/RULE_3_3_A_start_function_name_with_is_or_has_when_return_bool.py b/rules/RULE_3_3_A_start_function_name_with_is_or_has_when_return_bool.py index bd4f8c0..f945d60 100644 --- a/rules/RULE_3_3_A_start_function_name_with_is_or_has_when_return_bool.py +++ b/rules/RULE_3_3_A_start_function_name_with_is_or_has_when_return_bool.py @@ -40,7 +40,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( t, __name__, - "The function name(%s) should start with has or is when returinning bool" % fullName, + f"The function name({fullName}) should start with has or is when returinning bool", ) break k += 1 diff --git a/rules/RULE_3_3_A_start_function_name_with_lowercase_unix.py b/rules/RULE_3_3_A_start_function_name_with_lowercase_unix.py index 2932fb9..f4b6993 100644 --- a/rules/RULE_3_3_A_start_function_name_with_lowercase_unix.py +++ b/rules/RULE_3_3_A_start_function_name_with_lowercase_unix.py @@ -38,7 +38,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): return if IsOperator(value): return - nsiqcppstyle_reporter.Error(t, __name__, "Do not start function name(%s) with uppercase" % fullName) + nsiqcppstyle_reporter.Error(t, __name__, f"Do not start function name({fullName}) with uppercase") ruleManager.AddFunctionNameRule(RunRule) diff --git a/rules/RULE_3_3_A_start_function_name_with_upperrcase_windows.py b/rules/RULE_3_3_A_start_function_name_with_upperrcase_windows.py index 74acbcb..48c1738 100644 --- a/rules/RULE_3_3_A_start_function_name_with_upperrcase_windows.py +++ b/rules/RULE_3_3_A_start_function_name_with_upperrcase_windows.py @@ -42,7 +42,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): if value.startswith("~"): value = value[1:] if Search("^[a-z]", value) and not IsOperator(value) and t.value not in keywords: - nsiqcppstyle_reporter.Error(t, __name__, "Do not start function name(%s) with lowercase" % fullName) + nsiqcppstyle_reporter.Error(t, __name__, f"Do not start function name({fullName}) with lowercase") ruleManager.AddFunctionNameRule(RunRule) diff --git a/rules/RULE_3_3_B_start_private_function_name_with_underbar.py b/rules/RULE_3_3_B_start_private_function_name_with_underbar.py index 4bbba32..86a8ede 100644 --- a/rules/RULE_3_3_B_start_private_function_name_with_underbar.py +++ b/rules/RULE_3_3_B_start_private_function_name_with_underbar.py @@ -36,7 +36,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): if IsOperator(value): return if upperBlock is not None and upperBlock.additional == "PRIVATE" and not value.startswith("_"): - nsiqcppstyle_reporter.Error(t, __name__, "Start private function name(%s) with underbar" % fullName) + nsiqcppstyle_reporter.Error(t, __name__, f"Start private function name({fullName}) with underbar") def RunTypeScopeRule(lexer, contextStack): diff --git a/rules/RULE_4_1_B_indent_each_enum_item_in_enum_block.py b/rules/RULE_4_1_B_indent_each_enum_item_in_enum_block.py index f603a52..326348e 100644 --- a/rules/RULE_4_1_B_indent_each_enum_item_in_enum_block.py +++ b/rules/RULE_4_1_B_indent_each_enum_item_in_enum_block.py @@ -37,7 +37,7 @@ def RunRule(lexer, typeName, typeFullName, decl, contextStack, typeContext): nsiqcppstyle_reporter.Error( t, __name__, - "Enum block should be indented. But the token(%s) seems to be unindented" % t.value, + f"Enum block should be indented. But the token({t.value}) seems to be unindented", ) diff --git a/rules/RULE_4_1_B_locate_each_enum_item_in_seperate_line.py b/rules/RULE_4_1_B_locate_each_enum_item_in_seperate_line.py index ec8171e..89f867c 100644 --- a/rules/RULE_4_1_B_locate_each_enum_item_in_seperate_line.py +++ b/rules/RULE_4_1_B_locate_each_enum_item_in_seperate_line.py @@ -40,7 +40,7 @@ def RunRule(lexer, typeName, typeFullName, decl, contextStack, typeContext): nsiqcppstyle_reporter.Error( nt2, __name__, - "Each enum item(%s) should be located in the different line" % nt2.value, + f"Each enum item({nt2.value}) should be located in the different line", ) diff --git a/rules/RULE_4_2_A_A_space_around_operator.py b/rules/RULE_4_2_A_A_space_around_operator.py index 6198d4e..cb14a0c 100644 --- a/rules/RULE_4_2_A_A_space_around_operator.py +++ b/rules/RULE_4_2_A_A_space_around_operator.py @@ -79,7 +79,7 @@ def RunRule(lexer, contextStack): if t2.type not in ["SPACE", "LINEFEED", "PREPROCESSORNEXT"] or t3.type not in ["SPACE", "LINEFEED"]: t3 = lexer.GetPrevTokenSkipWhiteSpaceAndComment() if t3 is not None and t3.type != "OPERATOR" and not Match(r"^\w*#include", t.line): - nsiqcppstyle_reporter.Error(t, __name__, "Provide spaces b/w operator '%s'" % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Provide spaces b/w operator '{t.value}'") elif t.type in nextoperator: t2 = lexer.PeekNextToken() if ( @@ -87,7 +87,7 @@ def RunRule(lexer, contextStack): and t2.type not in ["SPACE", "LINEFEED", "PREPROCESSORNEXT"] and not Match(r"^\w*#include", t.line) ): - nsiqcppstyle_reporter.Error(t, __name__, "Provide spaces after operator '%s'" % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Provide spaces after operator '{t.value}'") elif t.type in unaryoperator: t2 = lexer.PeekPrevToken() t3 = lexer.PeekNextToken() @@ -109,7 +109,7 @@ def RunRule(lexer, contextStack): ] and t3.type not in ["SEMI", "SPACE", "LINEFEED", "RBRACE", "RPAREN", "RBRACKET"] ): - nsiqcppstyle_reporter.Error(t, __name__, "Provide spaces before operator '%s'" % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Provide spaces before operator '{t.value}'") if ( t2 is not None @@ -126,7 +126,7 @@ def RunRule(lexer, contextStack): ] and t3.type not in ["SEMI", "SPACE", "LINEFEED", "RBRACE", "RPAREN", "RBRACKET"] ): - nsiqcppstyle_reporter.Error(t, __name__, "Provide spaces after operator '%s'" % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Provide spaces after operator '{t.value}'") ruleManager.AddRule(RunRule) diff --git a/rules/RULE_4_2_A_B_space_around_word.py b/rules/RULE_4_2_A_B_space_around_word.py index 59bfbc8..72d79a3 100644 --- a/rules/RULE_4_2_A_B_space_around_word.py +++ b/rules/RULE_4_2_A_B_space_around_word.py @@ -48,7 +48,7 @@ def RunRule(lexer, contextStack): if t2 is not None and t3 is not None: if t2.type not in ["SPACE", "LINEFEED", "PREPROCESSORNEXT"] or t3.type not in ["SPACE", "LINEFEED"]: if not Search("^[ ]*#[ ]*include", t.line): - nsiqcppstyle_reporter.Error(t, __name__, "Put space before/after word '%s'." % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Put space before/after word '{t.value}'.") ruleManager.AddFunctionScopeRule(RunRule) diff --git a/rules/RULE_4_5_A_braces_inside_of_function_should_be_located_in_end_of_line.py b/rules/RULE_4_5_A_braces_inside_of_function_should_be_located_in_end_of_line.py index 8c16940..1b0195f 100644 --- a/rules/RULE_4_5_A_braces_inside_of_function_should_be_located_in_end_of_line.py +++ b/rules/RULE_4_5_A_braces_inside_of_function_should_be_located_in_end_of_line.py @@ -45,7 +45,7 @@ def RunRule(lexer, contextStack): nsiqcppstyle_reporter.Error( t, __name__, - "Braces inside of function should be located in the next of previous token(%s)" % prevToken.value, + f"Braces inside of function should be located in the next of previous token({prevToken.value})", ) diff --git a/rules/RULE_4_5_A_indent_blocks_inside_of_function.py b/rules/RULE_4_5_A_indent_blocks_inside_of_function.py index ba5fbfc..81251d0 100644 --- a/rules/RULE_4_5_A_indent_blocks_inside_of_function.py +++ b/rules/RULE_4_5_A_indent_blocks_inside_of_function.py @@ -60,7 +60,7 @@ def RunRule(lexer, contextStack): nsiqcppstyle_reporter.Error( nt, __name__, - "Indent in the block. token(%s) seems to be located left column of previsous brace" % nt.value, + f"Indent in the block. token({nt.value}) seems to be located left column of previsous brace", ) diff --git a/rules/RULE_5_2_C_provide_doxygen_class_comment_on_class_def.py b/rules/RULE_5_2_C_provide_doxygen_class_comment_on_class_def.py index 782e50a..39f2fcb 100644 --- a/rules/RULE_5_2_C_provide_doxygen_class_comment_on_class_def.py +++ b/rules/RULE_5_2_C_provide_doxygen_class_comment_on_class_def.py @@ -44,7 +44,7 @@ def RunRule(lexer, currentType, fullName, decl, contextStack, typeContext): nsiqcppstyle_reporter.Error( t, __name__, - "Doxygen Comment should be provided in front of class def(%s)." % fullName, + f"Doxygen Comment should be provided in front of class def({fullName}).", ) diff --git a/rules/RULE_5_2_C_provide_doxygen_namespace_comment_on_namespace_def.py b/rules/RULE_5_2_C_provide_doxygen_namespace_comment_on_namespace_def.py index cb9847e..8c7607f 100644 --- a/rules/RULE_5_2_C_provide_doxygen_namespace_comment_on_namespace_def.py +++ b/rules/RULE_5_2_C_provide_doxygen_namespace_comment_on_namespace_def.py @@ -46,7 +46,7 @@ def RunRule(lexer, currentType, fullName, decl, contextStack, typeContext): nsiqcppstyle_reporter.Error( t, __name__, - "Doxygen Comment should be provided in front of namespace def(%s)." % fullName, + f"Doxygen Comment should be provided in front of namespace def({fullName}).", ) diff --git a/rules/RULE_5_2_C_provide_doxygen_struct_comment_on_struct_def.py b/rules/RULE_5_2_C_provide_doxygen_struct_comment_on_struct_def.py index b526294..cd2f112 100644 --- a/rules/RULE_5_2_C_provide_doxygen_struct_comment_on_struct_def.py +++ b/rules/RULE_5_2_C_provide_doxygen_struct_comment_on_struct_def.py @@ -44,7 +44,7 @@ def RunRule(lexer, currentType, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( t, __name__, - "Doxygen Comment should be provided in front of struct/union def(%s)." % fullName, + f"Doxygen Comment should be provided in front of struct/union def({fullName}).", ) diff --git a/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_header.py b/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_header.py index 59dd7d1..e533590 100644 --- a/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_header.py +++ b/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_header.py @@ -65,7 +65,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( t, __name__, - "Doxygen Comment should be provided in front of function (%s) in header." % fullName, + f"Doxygen Comment should be provided in front of function ({fullName}) in header.", ) diff --git a/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_impl.py b/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_impl.py index c5a3521..f1bc180 100644 --- a/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_impl.py +++ b/rules/RULE_5_3_A_provide_doxygen_function_comment_on_function_in_impl.py @@ -83,7 +83,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( t, __name__, - "Doxygen Comment should be provided in front of function (%s) in impl file." % fullName, + f"Doxygen Comment should be provided in front of function ({fullName}) in impl file.", ) diff --git a/rules/RULE_6_1_A_do_not_omit_function_parameter_names.py b/rules/RULE_6_1_A_do_not_omit_function_parameter_names.py index 46e12d5..1e9093a 100644 --- a/rules/RULE_6_1_A_do_not_omit_function_parameter_names.py +++ b/rules/RULE_6_1_A_do_not_omit_function_parameter_names.py @@ -49,7 +49,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( t2, __name__, - "function (%s) has non named parameter. use named parameter." % fullName, + f"function ({fullName}) has non named parameter. use named parameter.", ) break count = 0 @@ -57,7 +57,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( t2, __name__, - "function (%s) has non named parameter. use named parameter." % fullName, + f"function ({fullName}) has non named parameter. use named parameter.", ) break diff --git a/rules/RULE_6_1_E_do_not_use_more_than_5_paramters_in_function.py b/rules/RULE_6_1_E_do_not_use_more_than_5_paramters_in_function.py index 73dddad..69de564 100644 --- a/rules/RULE_6_1_E_do_not_use_more_than_5_paramters_in_function.py +++ b/rules/RULE_6_1_E_do_not_use_more_than_5_paramters_in_function.py @@ -44,7 +44,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( t, __name__, - "function (%s) has more than 5 parameters. please use struct instead." % fullName, + f"function ({fullName}) has more than 5 parameters. please use struct instead.", ) break diff --git a/rules/RULE_6_1_G_write_less_than_200_lines_for_function.py b/rules/RULE_6_1_G_write_less_than_200_lines_for_function.py index 9aefe60..b585cd8 100644 --- a/rules/RULE_6_1_G_write_less_than_200_lines_for_function.py +++ b/rules/RULE_6_1_G_write_less_than_200_lines_for_function.py @@ -35,7 +35,7 @@ def RunRule(lexer, fullName, decl, contextStack, context): nsiqcppstyle_reporter.Error( context.startToken, __name__, - "Do not write function over non blank 200 lines(%s)." % fullName, + f"Do not write function over non blank 200 lines({fullName}).", ) diff --git a/rules/RULE_6_5_B_do_not_use_lowercase_for_macro_constants.py b/rules/RULE_6_5_B_do_not_use_lowercase_for_macro_constants.py index 12ce1f4..e8fa3d2 100644 --- a/rules/RULE_6_5_B_do_not_use_lowercase_for_macro_constants.py +++ b/rules/RULE_6_5_B_do_not_use_lowercase_for_macro_constants.py @@ -27,7 +27,7 @@ def RunRule(lexer, contextStack): k2 = lexer.GetNextTokenSkipWhiteSpaceAndComment() if d.type == "ID" and k2 is not None and k2.type in ["NUMBER", "STRING", "CHARACTOR"] and d.lineno == k2.lineno: if Search("[a-z]", d.value): - nsiqcppstyle_reporter.Error(d, __name__, "Do not use lower case (%s) for macro value" % d.value) + nsiqcppstyle_reporter.Error(d, __name__, f"Do not use lower case ({d.value}) for macro value") ruleManager.AddPreprocessRule(RunRule) diff --git a/rules/RULE_6_5_B_do_not_use_macro_for_constants.py b/rules/RULE_6_5_B_do_not_use_macro_for_constants.py index 3400953..2ab9fdd 100644 --- a/rules/RULE_6_5_B_do_not_use_macro_for_constants.py +++ b/rules/RULE_6_5_B_do_not_use_macro_for_constants.py @@ -33,7 +33,7 @@ def RunRule(lexer, contextStack): k2 = lexer.GetNextTokenSkipWhiteSpaceAndComment() if d.type == "ID" and k2 is not None and k2.type in ["NUMBER", "STRING", "CHARACTOR"] and d.lineno == k2.lineno: if not Search("^_", d.value): - nsiqcppstyle_reporter.Error(d, __name__, "Do not use macro(%s) for constant" % d.value) + nsiqcppstyle_reporter.Error(d, __name__, f"Do not use macro({d.value}) for constant") ruleManager.AddPreprocessRule(RunRule) diff --git a/rules/RULE_9_1_A_do_not_use_hardcorded_include_path.py b/rules/RULE_9_1_A_do_not_use_hardcorded_include_path.py index 7c02243..19e3886 100644 --- a/rules/RULE_9_1_A_do_not_use_hardcorded_include_path.py +++ b/rules/RULE_9_1_A_do_not_use_hardcorded_include_path.py @@ -25,7 +25,7 @@ def RunRule(lexer, contextStack): if d is not None and d.type == "STRING": value = d.value if value.startswith('"/') or Search(r"^\"[a-zA-Z]:", value): - nsiqcppstyle_reporter.Error(d, __name__, "Do not use absolute path(%s) in the include path" % value) + nsiqcppstyle_reporter.Error(d, __name__, f"Do not use absolute path({value}) in the include path") ruleManager.AddPreprocessRule(RunRule) diff --git a/rules/RULE_9_2_D_use_reentrant_function.py b/rules/RULE_9_2_D_use_reentrant_function.py index 8849a02..36251ab 100644 --- a/rules/RULE_9_2_D_use_reentrant_function.py +++ b/rules/RULE_9_2_D_use_reentrant_function.py @@ -45,7 +45,7 @@ def RunRule(lexer, contextStack): and nsiqcppstyle_state._nsiqcppstyle_state.GetVar("ignore_toupper", "false") == "true" ): return - nsiqcppstyle_reporter.Error(t, __name__, "Do not use not reentrant function(%s)." % t.value) + nsiqcppstyle_reporter.Error(t, __name__, f"Do not use not reentrant function({t.value}).") ruleManager.AddFunctionScopeRule(RunRule)