|
@@ -51,12 +51,19 @@ import sre_compile
|
|
import string
|
|
import string
|
|
import sys
|
|
import sys
|
|
import unicodedata
|
|
import unicodedata
|
|
|
|
+import sysconfig
|
|
|
|
+
|
|
|
|
+try:
|
|
|
|
+ xrange # Python 2
|
|
|
|
+except NameError:
|
|
|
|
+ xrange = range # Python 3
|
|
|
|
|
|
|
|
|
|
_USAGE = """
|
|
_USAGE = """
|
|
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
|
|
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
|
|
[--counting=total|toplevel|detailed] [--root=subdir]
|
|
[--counting=total|toplevel|detailed] [--root=subdir]
|
|
[--linelength=digits] [--headers=x,y,...]
|
|
[--linelength=digits] [--headers=x,y,...]
|
|
|
|
+ [--quiet]
|
|
<file> [file] ...
|
|
<file> [file] ...
|
|
|
|
|
|
The style guidelines this tries to follow are those in
|
|
The style guidelines this tries to follow are those in
|
|
@@ -83,6 +90,9 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
|
|
verbose=#
|
|
verbose=#
|
|
Specify a number 0-5 to restrict errors to certain verbosity levels.
|
|
Specify a number 0-5 to restrict errors to certain verbosity levels.
|
|
|
|
|
|
|
|
+ quiet
|
|
|
|
+ Don't print anything if no errors are found.
|
|
|
|
+
|
|
filter=-x,+y,...
|
|
filter=-x,+y,...
|
|
Specify a comma-separated list of category-filters to apply: only
|
|
Specify a comma-separated list of category-filters to apply: only
|
|
error messages whose category names pass the filters will be printed.
|
|
error messages whose category names pass the filters will be printed.
|
|
@@ -114,12 +124,13 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
|
|
ignored.
|
|
ignored.
|
|
|
|
|
|
Examples:
|
|
Examples:
|
|
- Assuming that src/.git exists, the header guard CPP variables for
|
|
|
|
- src/chrome/browser/ui/browser.h are:
|
|
|
|
|
|
+ Assuming that top/src/.git exists (and cwd=top/src), the header guard
|
|
|
|
+ CPP variables for top/src/chrome/browser/ui/browser.h are:
|
|
|
|
|
|
No flag => CHROME_BROWSER_UI_BROWSER_H_
|
|
No flag => CHROME_BROWSER_UI_BROWSER_H_
|
|
--root=chrome => BROWSER_UI_BROWSER_H_
|
|
--root=chrome => BROWSER_UI_BROWSER_H_
|
|
--root=chrome/browser => UI_BROWSER_H_
|
|
--root=chrome/browser => UI_BROWSER_H_
|
|
|
|
+ --root=.. => SRC_CHROME_BROWSER_UI_BROWSER_H_
|
|
|
|
|
|
linelength=digits
|
|
linelength=digits
|
|
This is the allowed line length for the project. The default value is
|
|
This is the allowed line length for the project. The default value is
|
|
@@ -168,9 +179,9 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
|
|
"linelength" allows to specify the allowed line length for the project.
|
|
"linelength" allows to specify the allowed line length for the project.
|
|
|
|
|
|
The "root" option is similar in function to the --root flag (see example
|
|
The "root" option is similar in function to the --root flag (see example
|
|
- above).
|
|
|
|
-
|
|
|
|
- The "headers" option is similar in function to the --headers flag
|
|
|
|
|
|
+ above). Paths are relative to the directory of the CPPLINT.cfg.
|
|
|
|
+
|
|
|
|
+ The "headers" option is similar in function to the --headers flag
|
|
(see example above).
|
|
(see example above).
|
|
|
|
|
|
CPPLINT.cfg has an effect on files in the same directory and all
|
|
CPPLINT.cfg has an effect on files in the same directory and all
|
|
@@ -539,6 +550,7 @@ _error_suppressions = {}
|
|
# The root directory used for deriving header guard CPP variable.
|
|
# The root directory used for deriving header guard CPP variable.
|
|
# This is set by --root flag.
|
|
# This is set by --root flag.
|
|
_root = None
|
|
_root = None
|
|
|
|
+_root_debug = False
|
|
|
|
|
|
# The allowed line length of files.
|
|
# The allowed line length of files.
|
|
# This is set by --linelength flag.
|
|
# This is set by --linelength flag.
|
|
@@ -563,7 +575,7 @@ def ProcessHppHeadersOption(val):
|
|
# Automatically append to extensions list so it does not have to be set 2 times
|
|
# Automatically append to extensions list so it does not have to be set 2 times
|
|
_valid_extensions.update(_hpp_headers)
|
|
_valid_extensions.update(_hpp_headers)
|
|
except ValueError:
|
|
except ValueError:
|
|
- PrintUsage('Header extensions must be comma seperated list.')
|
|
|
|
|
|
+ PrintUsage('Header extensions must be comma separated list.')
|
|
|
|
|
|
def IsHeaderExtension(file_extension):
|
|
def IsHeaderExtension(file_extension):
|
|
return file_extension in _hpp_headers
|
|
return file_extension in _hpp_headers
|
|
@@ -859,6 +871,7 @@ class _CppLintState(object):
|
|
self._filters_backup = self.filters[:]
|
|
self._filters_backup = self.filters[:]
|
|
self.counting = 'total' # In what way are we counting errors?
|
|
self.counting = 'total' # In what way are we counting errors?
|
|
self.errors_by_category = {} # string to int dict storing error counts
|
|
self.errors_by_category = {} # string to int dict storing error counts
|
|
|
|
+ self.quiet = False # Suppress non-error messagess?
|
|
|
|
|
|
# output format:
|
|
# output format:
|
|
# "emacs" - format that emacs can parse (default)
|
|
# "emacs" - format that emacs can parse (default)
|
|
@@ -869,6 +882,12 @@ class _CppLintState(object):
|
|
"""Sets the output format for errors."""
|
|
"""Sets the output format for errors."""
|
|
self.output_format = output_format
|
|
self.output_format = output_format
|
|
|
|
|
|
|
|
+ def SetQuiet(self, quiet):
|
|
|
|
+ """Sets the module's quiet settings, and returns the previous setting."""
|
|
|
|
+ last_quiet = self.quiet
|
|
|
|
+ self.quiet = quiet
|
|
|
|
+ return last_quiet
|
|
|
|
+
|
|
def SetVerboseLevel(self, level):
|
|
def SetVerboseLevel(self, level):
|
|
"""Sets the module's verbosity, and returns the previous setting."""
|
|
"""Sets the module's verbosity, and returns the previous setting."""
|
|
last_verbose_level = self.verbose_level
|
|
last_verbose_level = self.verbose_level
|
|
@@ -950,6 +969,14 @@ def _SetOutputFormat(output_format):
|
|
"""Sets the module's output format."""
|
|
"""Sets the module's output format."""
|
|
_cpplint_state.SetOutputFormat(output_format)
|
|
_cpplint_state.SetOutputFormat(output_format)
|
|
|
|
|
|
|
|
+def _Quiet():
|
|
|
|
+ """Return's the module's quiet setting."""
|
|
|
|
+ return _cpplint_state.quiet
|
|
|
|
+
|
|
|
|
+def _SetQuiet(quiet):
|
|
|
|
+ """Set the module's quiet status, and return previous setting."""
|
|
|
|
+ return _cpplint_state.SetQuiet(quiet)
|
|
|
|
+
|
|
|
|
|
|
def _VerboseLevel():
|
|
def _VerboseLevel():
|
|
"""Returns the module's verbosity setting."""
|
|
"""Returns the module's verbosity setting."""
|
|
@@ -1356,7 +1383,7 @@ def FindNextMultiLineCommentEnd(lines, lineix):
|
|
|
|
|
|
def RemoveMultiLineCommentsFromRange(lines, begin, end):
|
|
def RemoveMultiLineCommentsFromRange(lines, begin, end):
|
|
"""Clears a range of lines for multi-line comments."""
|
|
"""Clears a range of lines for multi-line comments."""
|
|
- # Having // dummy comments makes the lines non-empty, so we will not get
|
|
|
|
|
|
+ # Having // <empty> comments makes the lines non-empty, so we will not get
|
|
# unnecessary blank line warnings later in the code.
|
|
# unnecessary blank line warnings later in the code.
|
|
for i in range(begin, end):
|
|
for i in range(begin, end):
|
|
lines[i] = '/**/'
|
|
lines[i] = '/**/'
|
|
@@ -1730,7 +1757,7 @@ def CheckForCopyright(filename, lines, error):
|
|
"""Logs an error if no Copyright message appears at the top of the file."""
|
|
"""Logs an error if no Copyright message appears at the top of the file."""
|
|
|
|
|
|
# We'll say it should occur by line 10. Don't forget there's a
|
|
# We'll say it should occur by line 10. Don't forget there's a
|
|
- # dummy line at the front.
|
|
|
|
|
|
+ # placeholder line at the front.
|
|
for line in xrange(1, min(len(lines), 11)):
|
|
for line in xrange(1, min(len(lines), 11)):
|
|
if re.search(r'Copyright', lines[line], re.I): break
|
|
if re.search(r'Copyright', lines[line], re.I): break
|
|
else: # means no copyright line was found
|
|
else: # means no copyright line was found
|
|
@@ -1754,6 +1781,30 @@ def GetIndentLevel(line):
|
|
else:
|
|
else:
|
|
return 0
|
|
return 0
|
|
|
|
|
|
|
|
+def PathSplitToList(path):
|
|
|
|
+ """Returns the path split into a list by the separator.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ path: An absolute or relative path (e.g. '/a/b/c/' or '../a')
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ A list of path components (e.g. ['a', 'b', 'c]).
|
|
|
|
+ """
|
|
|
|
+ lst = []
|
|
|
|
+ while True:
|
|
|
|
+ (head, tail) = os.path.split(path)
|
|
|
|
+ if head == path: # absolute paths end
|
|
|
|
+ lst.append(head)
|
|
|
|
+ break
|
|
|
|
+ if tail == path: # relative paths end
|
|
|
|
+ lst.append(tail)
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ path = head
|
|
|
|
+ lst.append(tail)
|
|
|
|
+
|
|
|
|
+ lst.reverse()
|
|
|
|
+ return lst
|
|
|
|
|
|
def GetHeaderGuardCPPVariable(filename):
|
|
def GetHeaderGuardCPPVariable(filename):
|
|
"""Returns the CPP variable that should be used as a header guard.
|
|
"""Returns the CPP variable that should be used as a header guard.
|
|
@@ -1776,13 +1827,58 @@ def GetHeaderGuardCPPVariable(filename):
|
|
|
|
|
|
fileinfo = FileInfo(filename)
|
|
fileinfo = FileInfo(filename)
|
|
file_path_from_root = fileinfo.RepositoryName()
|
|
file_path_from_root = fileinfo.RepositoryName()
|
|
- if _root:
|
|
|
|
- suffix = os.sep
|
|
|
|
- # On Windows using directory separator will leave us with
|
|
|
|
- # "bogus escape error" unless we properly escape regex.
|
|
|
|
- if suffix == '\\':
|
|
|
|
- suffix += '\\'
|
|
|
|
- file_path_from_root = re.sub('^' + _root + suffix, '', file_path_from_root)
|
|
|
|
|
|
+
|
|
|
|
+ def FixupPathFromRoot():
|
|
|
|
+ if _root_debug:
|
|
|
|
+ sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
|
|
|
|
+ %(_root, fileinfo.RepositoryName()))
|
|
|
|
+
|
|
|
|
+ # Process the file path with the --root flag if it was set.
|
|
|
|
+ if not _root:
|
|
|
|
+ if _root_debug:
|
|
|
|
+ sys.stderr.write("_root unspecified\n")
|
|
|
|
+ return file_path_from_root
|
|
|
|
+
|
|
|
|
+ def StripListPrefix(lst, prefix):
|
|
|
|
+ # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
|
|
|
|
+ if lst[:len(prefix)] != prefix:
|
|
|
|
+ return None
|
|
|
|
+ # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
|
|
|
|
+ return lst[(len(prefix)):]
|
|
|
|
+
|
|
|
|
+ # root behavior:
|
|
|
|
+ # --root=subdir , lstrips subdir from the header guard
|
|
|
|
+ maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
|
|
|
|
+ PathSplitToList(_root))
|
|
|
|
+
|
|
|
|
+ if _root_debug:
|
|
|
|
+ sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
|
|
|
|
+ " _root=%s)\n") %(maybe_path, file_path_from_root, _root))
|
|
|
|
+
|
|
|
|
+ if maybe_path:
|
|
|
|
+ return os.path.join(*maybe_path)
|
|
|
|
+
|
|
|
|
+ # --root=.. , will prepend the outer directory to the header guard
|
|
|
|
+ full_path = fileinfo.FullName()
|
|
|
|
+ root_abspath = os.path.abspath(_root)
|
|
|
|
+
|
|
|
|
+ maybe_path = StripListPrefix(PathSplitToList(full_path),
|
|
|
|
+ PathSplitToList(root_abspath))
|
|
|
|
+
|
|
|
|
+ if _root_debug:
|
|
|
|
+ sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " +
|
|
|
|
+ "root_abspath=%s)\n") %(maybe_path, full_path, root_abspath))
|
|
|
|
+
|
|
|
|
+ if maybe_path:
|
|
|
|
+ return os.path.join(*maybe_path)
|
|
|
|
+
|
|
|
|
+ if _root_debug:
|
|
|
|
+ sys.stderr.write("_root ignore, returning %s\n" %(file_path_from_root))
|
|
|
|
+
|
|
|
|
+ # --root=FAKE_DIR is ignored
|
|
|
|
+ return file_path_from_root
|
|
|
|
+
|
|
|
|
+ file_path_from_root = FixupPathFromRoot()
|
|
return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'
|
|
return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'
|
|
|
|
|
|
|
|
|
|
@@ -3187,8 +3283,8 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
|
|
line = clean_lines.elided[linenum]
|
|
line = clean_lines.elided[linenum]
|
|
|
|
|
|
# You shouldn't have spaces before your brackets, except maybe after
|
|
# You shouldn't have spaces before your brackets, except maybe after
|
|
- # 'delete []' or 'return []() {};'
|
|
|
|
- if Search(r'\w\s+\[', line) and not Search(r'(?:delete|return)\s+\[', line):
|
|
|
|
|
|
+ # 'delete []', 'return []() {};', or 'auto [abc, ...] = ...;'.
|
|
|
|
+ if Search(r'\w\s+\[', line) and not Search(r'(?:auto&?|delete|return)\s+\[', line):
|
|
error(filename, linenum, 'whitespace/braces', 5,
|
|
error(filename, linenum, 'whitespace/braces', 5,
|
|
'Extra space before [')
|
|
'Extra space before [')
|
|
|
|
|
|
@@ -3770,9 +3866,9 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error):
|
|
|
|
|
|
# Block bodies should not be followed by a semicolon. Due to C++11
|
|
# Block bodies should not be followed by a semicolon. Due to C++11
|
|
# brace initialization, there are more places where semicolons are
|
|
# brace initialization, there are more places where semicolons are
|
|
- # required than not, so we use a whitelist approach to check these
|
|
|
|
- # rather than a blacklist. These are the places where "};" should
|
|
|
|
- # be replaced by just "}":
|
|
|
|
|
|
+ # required than not, so we explicitly list the allowed rules rather
|
|
|
|
+ # than listing the disallowed ones. These are the places where "};"
|
|
|
|
+ # should be replaced by just "}":
|
|
# 1. Some flavor of block following closing parenthesis:
|
|
# 1. Some flavor of block following closing parenthesis:
|
|
# for (;;) {};
|
|
# for (;;) {};
|
|
# while (...) {};
|
|
# while (...) {};
|
|
@@ -3828,11 +3924,11 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error):
|
|
# - INTERFACE_DEF
|
|
# - INTERFACE_DEF
|
|
# - EXCLUSIVE_LOCKS_REQUIRED, SHARED_LOCKS_REQUIRED, LOCKS_EXCLUDED:
|
|
# - EXCLUSIVE_LOCKS_REQUIRED, SHARED_LOCKS_REQUIRED, LOCKS_EXCLUDED:
|
|
#
|
|
#
|
|
- # We implement a whitelist of safe macros instead of a blacklist of
|
|
|
|
|
|
+ # We implement a list of safe macros instead of a list of
|
|
# unsafe macros, even though the latter appears less frequently in
|
|
# unsafe macros, even though the latter appears less frequently in
|
|
# google code and would have been easier to implement. This is because
|
|
# google code and would have been easier to implement. This is because
|
|
- # the downside for getting the whitelist wrong means some extra
|
|
|
|
- # semicolons, while the downside for getting the blacklist wrong
|
|
|
|
|
|
+ # the downside for getting the allowed checks wrong means some extra
|
|
|
|
+ # semicolons, while the downside for getting disallowed checks wrong
|
|
# would result in compile errors.
|
|
# would result in compile errors.
|
|
#
|
|
#
|
|
# In addition to macros, we also don't want to warn on
|
|
# In addition to macros, we also don't want to warn on
|
|
@@ -4196,6 +4292,16 @@ def GetLineWidth(line):
|
|
if unicodedata.east_asian_width(uc) in ('W', 'F'):
|
|
if unicodedata.east_asian_width(uc) in ('W', 'F'):
|
|
width += 2
|
|
width += 2
|
|
elif not unicodedata.combining(uc):
|
|
elif not unicodedata.combining(uc):
|
|
|
|
+ # Issue 337
|
|
|
|
+ # https://mail.python.org/pipermail/python-list/2012-August/628809.html
|
|
|
|
+ if (sys.version_info.major, sys.version_info.minor) <= (3, 2):
|
|
|
|
+ # https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h#L81
|
|
|
|
+ is_wide_build = sysconfig.get_config_var("Py_UNICODE_SIZE") >= 4
|
|
|
|
+ # https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L564
|
|
|
|
+ is_low_surrogate = 0xDC00 <= ord(uc) <= 0xDFFF
|
|
|
|
+ if not is_wide_build and is_low_surrogate:
|
|
|
|
+ width -= 1
|
|
|
|
+
|
|
width += 1
|
|
width += 1
|
|
return width
|
|
return width
|
|
else:
|
|
else:
|
|
@@ -5018,19 +5124,19 @@ def CheckForNonConstReference(filename, clean_lines, linenum,
|
|
#
|
|
#
|
|
# We also accept & in static_assert, which looks like a function but
|
|
# We also accept & in static_assert, which looks like a function but
|
|
# it's actually a declaration expression.
|
|
# it's actually a declaration expression.
|
|
- whitelisted_functions = (r'(?:[sS]wap(?:<\w:+>)?|'
|
|
|
|
|
|
+ allowed_functions = (r'(?:[sS]wap(?:<\w:+>)?|'
|
|
r'operator\s*[<>][<>]|'
|
|
r'operator\s*[<>][<>]|'
|
|
r'static_assert|COMPILE_ASSERT'
|
|
r'static_assert|COMPILE_ASSERT'
|
|
r')\s*\(')
|
|
r')\s*\(')
|
|
- if Search(whitelisted_functions, line):
|
|
|
|
|
|
+ if Search(allowed_functions, line):
|
|
return
|
|
return
|
|
elif not Search(r'\S+\([^)]*$', line):
|
|
elif not Search(r'\S+\([^)]*$', line):
|
|
- # Don't see a whitelisted function on this line. Actually we
|
|
|
|
|
|
+ # Don't see an allowed function on this line. Actually we
|
|
# didn't see any function name on this line, so this is likely a
|
|
# didn't see any function name on this line, so this is likely a
|
|
# multi-line parameter list. Try a bit harder to catch this case.
|
|
# multi-line parameter list. Try a bit harder to catch this case.
|
|
for i in xrange(2):
|
|
for i in xrange(2):
|
|
if (linenum > i and
|
|
if (linenum > i and
|
|
- Search(whitelisted_functions, clean_lines.elided[linenum - i - 1])):
|
|
|
|
|
|
+ Search(allowed_functions, clean_lines.elided[linenum - i - 1])):
|
|
return
|
|
return
|
|
|
|
|
|
decls = ReplaceAll(r'{[^}]*}', ' ', line) # exclude function body
|
|
decls = ReplaceAll(r'{[^}]*}', ' ', line) # exclude function body
|
|
@@ -5884,6 +5990,9 @@ def ProcessConfigOverrides(filename):
|
|
if base_name:
|
|
if base_name:
|
|
pattern = re.compile(val)
|
|
pattern = re.compile(val)
|
|
if pattern.match(base_name):
|
|
if pattern.match(base_name):
|
|
|
|
+ if _cpplint_state.quiet:
|
|
|
|
+ # Suppress "Ignoring file" warning when using --quiet.
|
|
|
|
+ return False
|
|
sys.stderr.write('Ignoring "%s": file excluded by "%s". '
|
|
sys.stderr.write('Ignoring "%s": file excluded by "%s". '
|
|
'File path component "%s" matches '
|
|
'File path component "%s" matches '
|
|
'pattern "%s"\n' %
|
|
'pattern "%s"\n' %
|
|
@@ -5897,7 +6006,8 @@ def ProcessConfigOverrides(filename):
|
|
sys.stderr.write('Line length must be numeric.')
|
|
sys.stderr.write('Line length must be numeric.')
|
|
elif name == 'root':
|
|
elif name == 'root':
|
|
global _root
|
|
global _root
|
|
- _root = val
|
|
|
|
|
|
+ # root directories are specified relative to CPPLINT.cfg dir.
|
|
|
|
+ _root = os.path.join(os.path.dirname(cfg_file), val)
|
|
elif name == 'headers':
|
|
elif name == 'headers':
|
|
ProcessHppHeadersOption(val)
|
|
ProcessHppHeadersOption(val)
|
|
else:
|
|
else:
|
|
@@ -5934,6 +6044,7 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
|
|
|
|
|
|
_SetVerboseLevel(vlevel)
|
|
_SetVerboseLevel(vlevel)
|
|
_BackupFilters()
|
|
_BackupFilters()
|
|
|
|
+ old_errors = _cpplint_state.error_count
|
|
|
|
|
|
if not ProcessConfigOverrides(filename):
|
|
if not ProcessConfigOverrides(filename):
|
|
_RestoreFilters()
|
|
_RestoreFilters()
|
|
@@ -6002,7 +6113,10 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
|
|
Error(filename, linenum, 'whitespace/newline', 1,
|
|
Error(filename, linenum, 'whitespace/newline', 1,
|
|
'Unexpected \\r (^M) found; better to use only \\n')
|
|
'Unexpected \\r (^M) found; better to use only \\n')
|
|
|
|
|
|
- sys.stdout.write('Done processing %s\n' % filename)
|
|
|
|
|
|
+ # 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:
|
|
|
|
+ sys.stdout.write('Done processing %s\n' % filename)
|
|
_RestoreFilters()
|
|
_RestoreFilters()
|
|
|
|
|
|
|
|
|
|
@@ -6046,13 +6160,15 @@ def ParseArguments(args):
|
|
'root=',
|
|
'root=',
|
|
'linelength=',
|
|
'linelength=',
|
|
'extensions=',
|
|
'extensions=',
|
|
- 'headers='])
|
|
|
|
|
|
+ 'headers=',
|
|
|
|
+ 'quiet'])
|
|
except getopt.GetoptError:
|
|
except getopt.GetoptError:
|
|
PrintUsage('Invalid arguments.')
|
|
PrintUsage('Invalid arguments.')
|
|
|
|
|
|
verbosity = _VerboseLevel()
|
|
verbosity = _VerboseLevel()
|
|
output_format = _OutputFormat()
|
|
output_format = _OutputFormat()
|
|
filters = ''
|
|
filters = ''
|
|
|
|
+ quiet = _Quiet()
|
|
counting_style = ''
|
|
counting_style = ''
|
|
|
|
|
|
for (opt, val) in opts:
|
|
for (opt, val) in opts:
|
|
@@ -6062,6 +6178,8 @@ def ParseArguments(args):
|
|
if val not in ('emacs', 'vs7', 'eclipse'):
|
|
if val not in ('emacs', 'vs7', 'eclipse'):
|
|
PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.')
|
|
PrintUsage('The only allowed output formats are emacs, vs7 and eclipse.')
|
|
output_format = val
|
|
output_format = val
|
|
|
|
+ elif opt == '--quiet':
|
|
|
|
+ quiet = True
|
|
elif opt == '--verbose':
|
|
elif opt == '--verbose':
|
|
verbosity = int(val)
|
|
verbosity = int(val)
|
|
elif opt == '--filter':
|
|
elif opt == '--filter':
|
|
@@ -6086,7 +6204,7 @@ def ParseArguments(args):
|
|
try:
|
|
try:
|
|
_valid_extensions = set(val.split(','))
|
|
_valid_extensions = set(val.split(','))
|
|
except ValueError:
|
|
except ValueError:
|
|
- PrintUsage('Extensions must be comma seperated list.')
|
|
|
|
|
|
+ PrintUsage('Extensions must be comma separated list.')
|
|
elif opt == '--headers':
|
|
elif opt == '--headers':
|
|
ProcessHppHeadersOption(val)
|
|
ProcessHppHeadersOption(val)
|
|
|
|
|
|
@@ -6094,6 +6212,7 @@ def ParseArguments(args):
|
|
PrintUsage('No files were specified.')
|
|
PrintUsage('No files were specified.')
|
|
|
|
|
|
_SetOutputFormat(output_format)
|
|
_SetOutputFormat(output_format)
|
|
|
|
+ _SetQuiet(quiet)
|
|
_SetVerboseLevel(verbosity)
|
|
_SetVerboseLevel(verbosity)
|
|
_SetFilters(filters)
|
|
_SetFilters(filters)
|
|
_SetCountingStyle(counting_style)
|
|
_SetCountingStyle(counting_style)
|
|
@@ -6114,7 +6233,9 @@ def main():
|
|
_cpplint_state.ResetErrorCounts()
|
|
_cpplint_state.ResetErrorCounts()
|
|
for filename in filenames:
|
|
for filename in filenames:
|
|
ProcessFile(filename, _cpplint_state.verbose_level)
|
|
ProcessFile(filename, _cpplint_state.verbose_level)
|
|
- _cpplint_state.PrintErrorCounts()
|
|
|
|
|
|
+ # If --quiet is passed, suppress printing error count unless there are errors.
|
|
|
|
+ if not _cpplint_state.quiet or _cpplint_state.error_count > 0:
|
|
|
|
+ _cpplint_state.PrintErrorCounts()
|
|
|
|
|
|
sys.exit(_cpplint_state.error_count > 0)
|
|
sys.exit(_cpplint_state.error_count > 0)
|
|
|
|
|