From 4cc0092c48722506b2585bd779a59a6013e74d75 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 30 Mar 2025 10:49:55 +0200 Subject: [PATCH 1/2] All TODOs should have a username --- cpplint.py | 6 +++--- cpplint_clitest.py | 2 +- pyproject.toml | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cpplint.py b/cpplint.py index 26707968..2705f871 100755 --- a/cpplint.py +++ b/cpplint.py @@ -4245,7 +4245,7 @@ def CheckOperatorSpacing(filename, clean_lines, linenum, error): # many false positives due to RValue references. match = re.search(r"[^<>=!\s](==|!=|<=|>=|\|\|)[^<>=!\s,;\)]", line) if match: - # TODO: support alternate operators + # TODO(unknown): support alternate operators error( filename, linenum, "whitespace/operators", 3, f"Missing spaces around {match.group(1)}" ) @@ -4767,7 +4767,7 @@ def CheckBraces(filename, clean_lines, linenum, error): " should be on a separate line", ) - # TODO: Err on if...else and do...while statements without braces; + # TODO(unknown): Err on if...else and do...while statements without braces; # style guide has changed since the below comment was written # Check single-line if/else bodies. The style guide says 'curly braces are not @@ -7457,7 +7457,7 @@ def ProcessFile(filename, vlevel, extra_check_functions=None): lf_lines.append(linenum + 1) except OSError: - # TODO: Maybe make this have an exit code of 2 after all is done + # TODO(unknown): Maybe make this have an exit code of 2 after all is done _cpplint_state.PrintError(f"Skipping input '{filename}': Can't open for reading\n") _RestoreFilters() return diff --git a/cpplint_clitest.py b/cpplint_clitest.py index 1ada03eb..8b1d3884 100755 --- a/cpplint_clitest.py +++ b/cpplint_clitest.py @@ -63,7 +63,7 @@ def run_shell_command(cmd: str, args: str, cwd: str = ".") -> tuple[int, bytes, # Make output system-agnostic, aka support Windows if os.sep == "\\": - # TODO: Support scenario with multiple input names + # TODO(unknown): Support scenario with multiple input names # We currently only support the last arguments as the input name # to prevent accidentally replacing sed tests. # Fixing would likely need coding an internal "replace slashes" option for cpplint itself. diff --git a/pyproject.toml b/pyproject.toml index a701d4ca..f028050b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,6 +105,7 @@ lint.select = [ "SLOT", # flake8-slots "T10", # flake8-debugger "TC", # flake8-type-checking + "TD", # flake8-todos "TID", # flake8-tidy-imports "TRY", # tryceratops "UP", # pyupgrade @@ -122,13 +123,13 @@ lint.select = [ # "S", # flake8-bandit # "SLF", # flake8-self # "T20", # flake8-print - # "TD", # flake8-todos ] lint.ignore = [ "FBT003", # flake8-boolean-trap "FIX002", # flake8-fixme "ISC003", # flake8-implicit-str-concat "PIE790", # Unnecessary `pass` statement + "TD003", # flake8-todos ] lint.per-file-ignores."cpplint.py" = [ "ICN001", From 377f2c29aea5fb0a2eeb8798e98fc0fa9f295655 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Mon, 31 Mar 2025 18:36:37 +0000 Subject: [PATCH 2/2] actually add usernames to todos --- cpplint.py | 48 +++++++++++++++++++++++----------------------- cpplint_clitest.py | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cpplint.py b/cpplint.py index 2705f871..9a032f80 100755 --- a/cpplint.py +++ b/cpplint.py @@ -2004,7 +2004,7 @@ def CleanseRawStrings(raw_lines): lines_without_raw_strings.append(line) - # TODO(unknown): if delimiter is not None here, we might want to + # TODO(google): if delimiter is not None here, we might want to # emit a warning for unterminated string. return lines_without_raw_strings @@ -2276,7 +2276,7 @@ def CloseExpression(clean_lines, linenum, pos): If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the linenum/pos that correspond to the closing of the expression. - TODO(unknown): cpplint spends a fair bit of time matching parentheses. + TODO(google): cpplint spends a fair bit of time matching parentheses. Ideally we would want to index all opening and closing parentheses once and have CloseExpression be just a simple lookup, but due to preprocessor tricks, this is not so easy. @@ -3115,7 +3115,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error): # lines. However, do apply checks if there is already an end of # namespace comment and it's incorrect. # - # TODO(unknown): We always want to check end of namespace comments + # TODO(google): We always want to check end of namespace comments # if a namespace is large, but sometimes we also want to apply the # check if a short namespace contained nontrivial things (something # other than forward declarations). There is currently no logic on @@ -3353,7 +3353,7 @@ def UpdatePreprocessor(self, line): # Restore the stack to how it was before the #if self.stack = copy.deepcopy(self.pp_stack[-1].stack_before_if) else: - # TODO(unknown): unexpected #else, issue warning? + # TODO(google): unexpected #else, issue warning? pass elif re.match(r"^\s*#\s*endif\b", line): # End of #if or #else blocks. @@ -3368,10 +3368,10 @@ def UpdatePreprocessor(self, line): # Drop the corresponding #if self.pp_stack.pop() else: - # TODO(unknown): unexpected #endif, issue warning? + # TODO(google): unexpected #endif, issue warning? pass - # TODO(unknown): Update() is too long, but we will refactor later. + # TODO(google): Update() is too long, but we will refactor later. def Update(self, filename, clean_lines, linenum, error): """Update nesting state with current line. @@ -3667,7 +3667,7 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum, nesting_state, ) if re.search(r"^\s*const\s*string\s*&\s*\w+\s*;", line): - # TODO(unknown): Could it be expanded safely to arbitrary references, + # TODO(google): Could it be expanded safely to arbitrary references, # without triggering too many false positives? The first # attempt triggered 5 warnings for mostly benign code in the regtest, hence # the restriction. @@ -3845,7 +3845,7 @@ def CheckSpacingForFunctionCall(filename, clean_lines, linenum, error): and not re.search(r"\w\s+\((\w+::)*\*\w+\)\(", fncall) and not re.search(r"\bcase\s+\(", fncall) ): - # TODO(unknown): Space after an operator function seem to be a common + # TODO(google): Space after an operator function seem to be a common # error, silence those for now by restricting them to highest verbosity. if re.search(r"\boperator_*\b", line): error( @@ -4096,7 +4096,7 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error): elided = clean_lines.elided prev_line = elided[linenum - 1] prevbrace = prev_line.rfind("{") - # TODO(unknown): Don't complain if line before blank line, and line after, + # TODO(google): Don't complain if line before blank line, and line after, # both start with alnums and are indented the same amount. # This ignores whitespace at the start of a namespace block # because those are not usually indented. @@ -4230,7 +4230,7 @@ def CheckOperatorSpacing(filename, clean_lines, linenum, error): # It's ok not to have spaces around binary operators like + - * /, but if # there's too little whitespace, we get concerned. It's hard to tell, - # though, so we punt on this one for now. TODO. + # though, so we punt on this one for now. TODO(google). # You should always have whitespace around binary operators. # @@ -4245,7 +4245,7 @@ def CheckOperatorSpacing(filename, clean_lines, linenum, error): # many false positives due to RValue references. match = re.search(r"[^<>=!\s](==|!=|<=|>=|\|\|)[^<>=!\s,;\)]", line) if match: - # TODO(unknown): support alternate operators + # TODO(google): support alternate operators error( filename, linenum, "whitespace/operators", 3, f"Missing spaces around {match.group(1)}" ) @@ -4392,7 +4392,7 @@ def CheckCommaSpacing(filename, clean_lines, linenum, error): # You should always have a space after a semicolon # except for few corner cases - # TODO(unknown): clarify if 'if (1) { return 1;}' is requires one more + # TODO(google): clarify if 'if (1) { return 1;}' is requires one more # space after ; if re.search(r";[^\s};\\)/]", line): error(filename, linenum, "whitespace/semicolon", 3, "Missing space after ;") @@ -4767,7 +4767,7 @@ def CheckBraces(filename, clean_lines, linenum, error): " should be on a separate line", ) - # TODO(unknown): Err on if...else and do...while statements without braces; + # TODO(aaronliu0130): Err on if...else and do...while statements without braces; # style guide has changed since the below comment was written # Check single-line if/else bodies. The style guide says 'curly braces are not @@ -5288,7 +5288,7 @@ def CheckAltTokens(filename, clean_lines, linenum, error): # it provides a way to workaround this warning for people who use # multi-line comments in preprocessor macros. # - # TODO(unknown): remove this once cpplint has better support for + # TODO(google): remove this once cpplint has better support for # multi-line comments. if line.find("/*") >= 0 or line.find("*/") >= 0: return @@ -5740,7 +5740,7 @@ def _GetTextInside(text, start_pattern): The extracted text. None if either the opening string or ending punctuation could not be found. """ - # TODO(unknown): Audit cpplint.py to see what places could be profitably + # TODO(google): Audit cpplint.py to see what places could be profitably # rewritten to use _GetTextInside (and use inferior regexp matching today). # Give opening punctuation to get the matching close-punctuation. @@ -5853,10 +5853,10 @@ def CheckLanguage( CheckPrintf(filename, clean_lines, linenum, error) if IsHeaderExtension(file_extension): - # TODO(unknown): check that 1-arg constructors are explicit. + # TODO(google): check that 1-arg constructors are explicit. # How to tell it's a constructor? # (handled in CheckForNonStandardConstructs for now) - # TODO(unknown): check that classes declare or disable copy/assign + # TODO(google): check that classes declare or disable copy/assign # (level 1 error) pass @@ -5879,7 +5879,7 @@ def CheckLanguage( ) # Check if some verboten operator overloading is going on - # TODO(unknown): catch out-of-line unary operator&: + # TODO(google): catch out-of-line unary operator&: # class X {}; # int operator&(const X& x) { return 42; } // unary operator& # The trick is it's hard to tell apart from binary operator&: @@ -5907,7 +5907,7 @@ def CheckLanguage( # Check for potential format string bugs like printf(foo). # We constrain the pattern not to pick things like DocidForPrintf(foo). # Not perfect but it can catch printf(foo.c_str()) and printf(foo->c_str()) - # TODO(unknown): Catch the following case. Need to change the calling + # TODO(google): Catch the following case. Need to change the calling # convention of the whole function to process multiple line to handle it. # printf( # boy_this_is_a_really_long_variable_that_cannot_fit_on_the_prev_line); @@ -6047,8 +6047,8 @@ def CheckGlobalStatic(filename, clean_lines, linenum, error): # This is dangerous because the C++ language does not guarantee that # globals with constructors are initialized before the first access, and # also because globals can be destroyed when some threads are still running. - # TODO(unknown): Generalize this to also find static unique_ptr instances. - # TODO(unknown): File bugs for clang-tidy to find these. + # TODO(google): Generalize this to also find static unique_ptr instances. + # TODO(google): File bugs for clang-tidy to find these. match = re.match( r"((?:|static +)(?:|const +))(?::*std::)?string( +const)? +" r"([a-zA-Z0-9_:]+)\b(.*)", @@ -6303,7 +6303,7 @@ def CheckForNonConstReference(filename, clean_lines, linenum, nesting_state, err # inside declarators: reference parameter # We will exclude the first two cases by checking that we are not inside a # function body, including one that was just introduced by a trailing '{'. - # TODO(unknown): Doesn't account for 'catch(Exception& e)' [rare]. + # TODO(google): Doesn't account for 'catch(Exception& e)' [rare]. if nesting_state.previous_stack_top and not ( isinstance(nesting_state.previous_stack_top, (_ClassInfo, _NamespaceInfo)) ): @@ -7010,7 +7010,7 @@ def CheckRedundantVirtual(filename, clean_lines, linenum, error): # Look for the next opening parenthesis. This is the start of the # parameter list (possibly on the next line shortly after virtual). - # TODO(unknown): doesn't work if there are virtual functions with + # TODO(google): doesn't work if there are virtual functions with # decltype() or other things that use parentheses, but csearch suggests # that this is rare. end_col = -1 @@ -7457,7 +7457,7 @@ def ProcessFile(filename, vlevel, extra_check_functions=None): lf_lines.append(linenum + 1) except OSError: - # TODO(unknown): Maybe make this have an exit code of 2 after all is done + # TODO(aaronliu0130): Maybe make this have an exit code of 2 after all is done _cpplint_state.PrintError(f"Skipping input '{filename}': Can't open for reading\n") _RestoreFilters() return diff --git a/cpplint_clitest.py b/cpplint_clitest.py index 8b1d3884..26947129 100755 --- a/cpplint_clitest.py +++ b/cpplint_clitest.py @@ -63,7 +63,7 @@ def run_shell_command(cmd: str, args: str, cwd: str = ".") -> tuple[int, bytes, # Make output system-agnostic, aka support Windows if os.sep == "\\": - # TODO(unknown): Support scenario with multiple input names + # TODO(aaronliu0130): Support scenario with multiple input names # We currently only support the last arguments as the input name # to prevent accidentally replacing sed tests. # Fixing would likely need coding an internal "replace slashes" option for cpplint itself.