57
57
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
58
58
[--counting=total|toplevel|detailed] [--root=subdir]
59
59
[--linelength=digits] [--headers=x,y,...]
60
+ [--quiet]
60
61
<file> [file] ...
61
62
62
63
The style guidelines this tries to follow are those in
83
84
verbose=#
84
85
Specify a number 0-5 to restrict errors to certain verbosity levels.
85
86
87
+ quiet
88
+ Don't print anything if no errors are found.
89
+
86
90
filter=-x,+y,...
87
91
Specify a comma-separated list of category-filters to apply: only
88
92
error messages whose category names pass the filters will be printed.
@@ -861,6 +865,7 @@ def __init__(self):
861
865
self ._filters_backup = self .filters [:]
862
866
self .counting = 'total' # In what way are we counting errors?
863
867
self .errors_by_category = {} # string to int dict storing error counts
868
+ self .quiet = False # Suppress non-error messagess?
864
869
865
870
# output format:
866
871
# "emacs" - format that emacs can parse (default)
@@ -871,6 +876,12 @@ def SetOutputFormat(self, output_format):
871
876
"""Sets the output format for errors."""
872
877
self .output_format = output_format
873
878
879
+ def SetQuiet (self , quiet ):
880
+ """Sets the module's quiet settings, and returns the previous setting."""
881
+ last_quiet = self .quiet
882
+ self .quiet = quiet
883
+ return last_quiet
884
+
874
885
def SetVerboseLevel (self , level ):
875
886
"""Sets the module's verbosity, and returns the previous setting."""
876
887
last_verbose_level = self .verbose_level
@@ -952,6 +963,14 @@ def _SetOutputFormat(output_format):
952
963
"""Sets the module's output format."""
953
964
_cpplint_state .SetOutputFormat (output_format )
954
965
966
+ def _Quiet ():
967
+ """Return's the module's quiet setting."""
968
+ return _cpplint_state .quiet
969
+
970
+ def _SetQuiet (quiet ):
971
+ """Set the module's quiet status, and return previous setting."""
972
+ return _cpplint_state .SetQuiet (quiet )
973
+
955
974
956
975
def _VerboseLevel ():
957
976
"""Returns the module's verbosity setting."""
@@ -5955,6 +5974,9 @@ def ProcessConfigOverrides(filename):
5955
5974
if base_name :
5956
5975
pattern = re .compile (val )
5957
5976
if pattern .match (base_name ):
5977
+ if _cpplint_state .quiet :
5978
+ # Suppress "Ignoring file" warning when using --quiet.
5979
+ return False
5958
5980
sys .stderr .write ('Ignoring "%s": file excluded by "%s". '
5959
5981
'File path component "%s" matches '
5960
5982
'pattern "%s"\n ' %
@@ -6006,6 +6028,7 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
6006
6028
6007
6029
_SetVerboseLevel (vlevel )
6008
6030
_BackupFilters ()
6031
+ old_errors = _cpplint_state .error_count
6009
6032
6010
6033
if not ProcessConfigOverrides (filename ):
6011
6034
_RestoreFilters ()
@@ -6074,7 +6097,10 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
6074
6097
Error (filename , linenum , 'whitespace/newline' , 1 ,
6075
6098
'Unexpected \\ r (^M) found; better to use only \\ n' )
6076
6099
6077
- sys .stdout .write ('Done processing %s\n ' % filename )
6100
+ # Suppress printing anything if --quiet was passed unless the error
6101
+ # count has increased after processing this file.
6102
+ if not _cpplint_state .quiet or old_errors != _cpplint_state .error_count :
6103
+ sys .stdout .write ('Done processing %s\n ' % filename )
6078
6104
_RestoreFilters ()
6079
6105
6080
6106
@@ -6118,13 +6144,15 @@ def ParseArguments(args):
6118
6144
'root=' ,
6119
6145
'linelength=' ,
6120
6146
'extensions=' ,
6121
- 'headers=' ])
6147
+ 'headers=' ,
6148
+ 'quiet' ])
6122
6149
except getopt .GetoptError :
6123
6150
PrintUsage ('Invalid arguments.' )
6124
6151
6125
6152
verbosity = _VerboseLevel ()
6126
6153
output_format = _OutputFormat ()
6127
6154
filters = ''
6155
+ quiet = _Quiet ()
6128
6156
counting_style = ''
6129
6157
6130
6158
for (opt , val ) in opts :
@@ -6134,6 +6162,8 @@ def ParseArguments(args):
6134
6162
if val not in ('emacs' , 'vs7' , 'eclipse' ):
6135
6163
PrintUsage ('The only allowed output formats are emacs, vs7 and eclipse.' )
6136
6164
output_format = val
6165
+ elif opt == '--quiet' :
6166
+ quiet = True
6137
6167
elif opt == '--verbose' :
6138
6168
verbosity = int (val )
6139
6169
elif opt == '--filter' :
@@ -6166,6 +6196,7 @@ def ParseArguments(args):
6166
6196
PrintUsage ('No files were specified.' )
6167
6197
6168
6198
_SetOutputFormat (output_format )
6199
+ _SetQuiet (quiet )
6169
6200
_SetVerboseLevel (verbosity )
6170
6201
_SetFilters (filters )
6171
6202
_SetCountingStyle (counting_style )
@@ -6186,7 +6217,9 @@ def main():
6186
6217
_cpplint_state .ResetErrorCounts ()
6187
6218
for filename in filenames :
6188
6219
ProcessFile (filename , _cpplint_state .verbose_level )
6189
- _cpplint_state .PrintErrorCounts ()
6220
+ # If --quiet is passed, suppress printing error count unless there are errors.
6221
+ if not _cpplint_state .quiet or _cpplint_state .error_count > 0 :
6222
+ _cpplint_state .PrintErrorCounts ()
6190
6223
6191
6224
sys .exit (_cpplint_state .error_count > 0 )
6192
6225
0 commit comments