Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Unified Diff: PRESUBMIT.py

Issue 2525263002: Presubmit: Warn about useless forward declarations (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index d78629a6d802bea59f45596784536cb99aeb33a9..33d75410d653d3d2a9879cb4339b432783752e47 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1584,6 +1584,34 @@ def _CheckMojoUsesNewWrapperTypes(input_api, output_api):
return []
+def _CheckUselessForwardDeclarations(input_api, output_api):
+ """Checks that affected header files do not contain useless class
+ or struct forward declaration.
+ """
+ results = []
+ class_pattern = input_api.re.compile(r'^class\s+(\w+);$',
+ input_api.re.MULTILINE)
+ struct_pattern = input_api.re.compile(r'^struct\s+(\w+);$',
+ input_api.re.MULTILINE)
+ for f in input_api.AffectedFiles():
+ if not f.LocalPath().endswith('.h'):
+ continue
+
+ contents = input_api.ReadFile(f)
+ fwd_decls = input_api.re.findall(class_pattern, contents)
+ fwd_decls.extend(input_api.re.findall(struct_pattern, contents))
+
+ for decl in fwd_decls:
+ count = sum(1 for _ in input_api.re.finditer(
+ r'\b%s\b' % input_api.re.escape(decl), contents))
+ if count == 1:
+ results.append(output_api.PresubmitPromptWarning(
+ '%s: %s forward declaration seems to be useless' %
+ (f.LocalPath(), decl)))
+
+ return results
+
+
def _CheckAndroidToastUsage(input_api, output_api):
"""Checks that code uses org.chromium.ui.widget.Toast instead of
android.widget.Toast (Chromium Toast doesn't force hardware
@@ -2033,6 +2061,7 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckJavaStyle(input_api, output_api))
results.extend(_CheckIpcOwners(input_api, output_api))
results.extend(_CheckMojoUsesNewWrapperTypes(input_api, output_api))
+ results.extend(_CheckUselessForwardDeclarations(input_api, output_api))
if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698