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

Unified Diff: git_cl.py

Issue 134223010: Implement git cl lint. (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: rebase Created 6 years, 9 months 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 | tests/git_cl_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
===================================================================
--- git_cl.py (revision 256001)
+++ git_cl.py (working copy)
@@ -51,6 +51,10 @@
GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingGit'
CHANGE_ID = 'Change-Id:'
+# Valid extensions for files we want to lint.
+DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)"
+DEFAULT_LINT_IGNORE_REGEX = r"$^"
+
# Shortcut since it quickly becomes redundant.
Fore = colorama.Fore
@@ -423,6 +427,14 @@
self.git_editor = self._GetConfig('core.editor', error_ok=True)
return self.git_editor or None
+ def GetLintRegex(self):
+ return (self._GetRietveldConfig('cpplint-regex', error_ok=True) or
+ DEFAULT_LINT_REGEX)
+
+ def GetLintIgnoreRegex(self):
+ return (self._GetRietveldConfig('cpplint-ignore-regex', error_ok=True) or
+ DEFAULT_LINT_IGNORE_REGEX)
+
def _GetRietveldConfig(self, param, **kwargs):
return self._GetConfig('rietveld.' + param, **kwargs)
@@ -1044,6 +1056,8 @@
SetProperty('tree-status-url', 'STATUS', unset_error_ok=True)
SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True)
SetProperty('bug-prefix', 'BUG_PREFIX', unset_error_ok=True)
+ SetProperty('cpplint-regex', 'LINT_REGEX', unset_error_ok=True)
+ SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True)
if 'GERRIT_HOST' in keyvals:
RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']])
@@ -1366,6 +1380,51 @@
return RunGit(['log', '--pretty=format:%s\n\n%b'] + log_args)
+def CMDlint(parser, args):
+ """Runs cpplint on the current changelist."""
+ _, args = parser.parse_args(args)
+
+ # Access to a protected member _XX of a client class
+ # pylint: disable=W0212
+ try:
+ import cpplint
+ import cpplint_chromium
+ except ImportError:
+ print "Your depot_tools is missing cpplint.py and/or cpplint_chromium.py."
+ return 1
+
+ # Change the current working directory before calling lint so that it
+ # shows the correct base.
+ previous_cwd = os.getcwd()
+ os.chdir(settings.GetRoot())
+ try:
+ cl = Changelist()
+ change = cl.GetChange(cl.GetCommonAncestorWithUpstream(), None)
+ files = [f.LocalPath() for f in change.AffectedFiles()]
+
+ # Process cpplints arguments if any.
+ filenames = cpplint.ParseArguments(args + files)
+
+ white_regex = re.compile(settings.GetLintRegex())
+ black_regex = re.compile(settings.GetLintIgnoreRegex())
+ extra_check_functions = [cpplint_chromium.CheckPointerDeclarationWhitespace]
+ for filename in filenames:
+ if white_regex.match(filename):
+ if black_regex.match(filename):
+ print "Ignoring file %s" % filename
+ else:
+ cpplint.ProcessFile(filename, cpplint._cpplint_state.verbose_level,
+ extra_check_functions)
+ else:
+ print "Skipping file %s" % filename
+ finally:
+ os.chdir(previous_cwd)
+ print "Total errors found: %d\n" % cpplint._cpplint_state.error_count
+ if cpplint._cpplint_state.error_count != 0:
+ return 1
+ return 0
+
+
def CMDpresubmit(parser, args):
"""Runs presubmit tests on the current changelist."""
parser.add_option('-u', '--upload', action='store_true',
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698