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

Migrate to newer cpplint.py fork #286

Merged
merged 1 commit into from
Sep 21, 2024

Conversation

calcmogul
Copy link
Member

https://github.com/cpplint/cpplint has bugfixes and is actually maintained.

@calcmogul
Copy link
Member Author

calcmogul commented Sep 20, 2024

Here's the manual edits I made on top of the upstream version:

diff --git a/tmp/cpplint/cpplint.py b/tmp/styleguide/wpiformat/wpiformat/cpplint.py
old mode 100755
new mode 100644
index aa31357..a144bb1
--- a/tmp/cpplint/cpplint.py
+++ b/tmp/styleguide/wpiformat/wpiformat/cpplint.py
@@ -1438,8 +1438,6 @@ class _CppLintState(object):
     """Print a summary of errors by category, and the total."""
     for category, count in sorted(dict.items(self.errors_by_category)):
       self.PrintInfo(f'Category \'{category}\' errors found: {count}\n')
-    if self.error_count > 0:
-      self.PrintInfo(f'Total errors found: {self.error_count}\n')
 
   def PrintInfo(self, message):
     # _quiet does not represent --quiet flag.
@@ -4364,8 +4362,8 @@ def CheckBraces(filename, clean_lines, linenum, error):
 
   # If braces come on one side of an else, they should be on both.
   # However, we have to worry about "else if" that spans multiple lines!
-  if re.search(r'else if\s*\(', line):       # could be multi-line if
-    brace_on_left = bool(re.search(r'}\s*else if\s*\(', line))
+  if re.search(r'else if(\s+constexpr)?\s*\(', line):  # could be multi-line if
+    brace_on_left = bool(re.search(r'}\s*else if(\s+constexpr)?\s*\(', line))
     # find the ( after the if
     pos = line.find('else if')
     pos = line.find('(', pos)
@@ -6687,39 +6685,32 @@ def ProcessFile(filename, vlevel, extra_check_functions=None):
     return
 
   # Note, if no dot is found, this will give the entire filename as the ext.
-  file_extension = filename[filename.rfind('.') + 1:]
+  basename = os.path.basename(filename)
+  file_extension = basename[basename.rfind('.') + 1:]
 
   # When reading from stdin, the extension is unknown, so no cpplint tests
   # should rely on the extension.
-  if filename != '-' and file_extension not in GetAllExtensions():
-    _cpplint_state.PrintError(f'Ignoring {filename}; not a valid file name'
-                              f' ({(", ".join(GetAllExtensions()))})\n')
-  else:
-    ProcessFileData(filename, file_extension, lines, Error,
-                    extra_check_functions)
+  ProcessFileData(filename, file_extension, lines, Error,
+                  extra_check_functions)
+
+  # If end-of-line sequences are a mix of LF and CR-LF, issue
+  # warnings on the lines with CR.
+  #
+  # Don't issue any warnings if all lines are uniformly LF or CR-LF,
+  # since critique can handle these just fine, and the style guide
+  # doesn't dictate a particular end of line sequence.
+  #
+  # We can't depend on os.linesep to determine what the desired
+  # end-of-line sequence should be, since that will return the
+  # server-side end-of-line sequence.
+  if lf_lines and crlf_lines:
+    # Warn on every line with CR.  An alternative approach might be to
+    # check whether the file is mostly CRLF or just LF, and warn on the
+    # minority, we bias toward LF here since most tools prefer LF.
+    for linenum in crlf_lines:
+      Error(filename, linenum, 'whitespace/newline', 1,
+            'Unexpected \\r (^M) found; better to use only \\n')
 
-    # If end-of-line sequences are a mix of LF and CR-LF, issue
-    # warnings on the lines with CR.
-    #
-    # Don't issue any warnings if all lines are uniformly LF or CR-LF,
-    # since critique can handle these just fine, and the style guide
-    # doesn't dictate a particular end of line sequence.
-    #
-    # We can't depend on os.linesep to determine what the desired
-    # end-of-line sequence should be, since that will return the
-    # server-side end-of-line sequence.
-    if lf_lines and crlf_lines:
-      # Warn on every line with CR.  An alternative approach might be to
-      # check whether the file is mostly CRLF or just LF, and warn on the
-      # minority, we bias toward LF here since most tools prefer LF.
-      for linenum in crlf_lines:
-        Error(filename, linenum, 'whitespace/newline', 1,
-              'Unexpected \\r (^M) found; better to use only \\n')
-
-  # Suppress printing anything if --quiet was passed unless the error
-  # count has increased after processing this file.
-  if not _cpplint_state.quiet or old_errors != _cpplint_state.error_count:
-    _cpplint_state.PrintInfo(f'Done processing {filename}\n')
   _RestoreFilters()
 
 

@calcmogul calcmogul merged commit 4afef78 into wpilibsuite:main Sep 21, 2024
14 checks passed
@calcmogul calcmogul deleted the migrate-to-newer-cpplint-fork branch September 21, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant