Add --quiet command line argument

Quiet makes output quiet unless errors occurs.

Mainly used by automation tools when parsing huge amount of files.
In those cases actual error might get lost in the pile of other stats
prints.

This argument is also handy for build system integration, so it's
possible to add automated lint target to a project and invoke it
via build system and have no pollution of terminals or IDE.

For example when hooking cmakelint to a Ninja project without this
argument one will have screen filled with "Total Errors: 0" messages,
which defeats all the idea of clean Ninja output.
This commit is contained in:
Sergey Sharybin 2016-07-07 23:00:33 +02:00
parent f15e633de5
commit 528974d8ce

26
cpplint/cpplint.py vendored
View File

@ -56,7 +56,7 @@ import unicodedata
_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] [--linelength=digits] [--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
@ -128,6 +128,15 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
Examples: Examples:
--linelength=120 --linelength=120
quiet makes output quiet unless errors occurs
Mainly used by automation tools when parsing huge amount of files.
In those cases actual error might get lost in the pile of other stats
prints.
This argument is also handy for build system integration, so it's
possible to add automated lint target to a project and invoke it
via build system and have no pollution of terminals or IDE.
extensions=extension,extension,... extensions=extension,extension,...
The allowed file extensions that cpplint will check The allowed file extensions that cpplint will check
@ -143,6 +152,7 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
exclude_files=regex exclude_files=regex
linelength=80 linelength=80
root=subdir root=subdir
quiet
"set noparent" option prevents cpplint from traversing directory tree "set noparent" option prevents cpplint from traversing directory tree
upwards looking for more .cfg files in parent directories. This option upwards looking for more .cfg files in parent directories. This option
@ -161,6 +171,8 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
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). above).
The "quiet" option is similar in function to the --quiet.
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
sub-directories, unless overridden by a nested configuration file. sub-directories, unless overridden by a nested configuration file.
@ -532,6 +544,9 @@ _root = None
# This is set by --linelength flag. # This is set by --linelength flag.
_line_length = 80 _line_length = 80
# Supress messages unless error occurs.
_quiet = False
# The allowed extensions for file names # The allowed extensions for file names
# This is set by --extensions flag. # This is set by --extensions flag.
_valid_extensions = set(['cc', 'h', 'cpp', 'cu', 'cuh']) _valid_extensions = set(['cc', 'h', 'cpp', 'cu', 'cuh'])
@ -909,6 +924,7 @@ class _CppLintState(object):
for category, count in self.errors_by_category.iteritems(): for category, count in self.errors_by_category.iteritems():
sys.stderr.write('Category \'%s\' errors found: %d\n' % sys.stderr.write('Category \'%s\' errors found: %d\n' %
(category, count)) (category, count))
if self.error_count > 0 or not _quiet:
sys.stderr.write('Total errors found: %d\n' % self.error_count) sys.stderr.write('Total errors found: %d\n' % self.error_count)
_cpplint_state = _CppLintState() _cpplint_state = _CppLintState()
@ -5893,6 +5909,8 @@ def ProcessConfigOverrides(filename):
elif name == 'root': elif name == 'root':
global _root global _root
_root = val _root = val
elif name == 'quiet':
_quiet = True
else: else:
sys.stderr.write( sys.stderr.write(
'Invalid configuration option (%s) in file %s\n' % 'Invalid configuration option (%s) in file %s\n' %
@ -5995,6 +6013,7 @@ 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')
if not _quiet:
sys.stderr.write('Done processing %s\n' % filename) sys.stderr.write('Done processing %s\n' % filename)
_RestoreFilters() _RestoreFilters()
@ -6038,7 +6057,7 @@ def ParseArguments(args):
'filter=', 'filter=',
'root=', 'root=',
'linelength=', 'linelength=',
'extensions=']) 'extensions=', 'quiet'])
except getopt.GetoptError: except getopt.GetoptError:
PrintUsage('Invalid arguments.') PrintUsage('Invalid arguments.')
@ -6079,6 +6098,9 @@ def ParseArguments(args):
_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 seperated list.')
elif opt == '--quiet':
global _quiet
_quiet = True
if not filenames: if not filenames:
PrintUsage('No files were specified.') PrintUsage('No files were specified.')