|
56 | 56 | _USAGE = """
|
57 | 57 | Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
|
58 | 58 | [--counting=total|toplevel|detailed] [--root=subdir]
|
59 |
| - [--linelength=digits] |
| 59 | + [--linelength=digits] [--headers=x,y,...] |
60 | 60 | <file> [file] ...
|
61 | 61 |
|
62 | 62 | The style guidelines this tries to follow are those in
|
|
134 | 134 | Examples:
|
135 | 135 | --extensions=hpp,cpp
|
136 | 136 |
|
| 137 | + headers=x,y,... |
| 138 | + The header extensions that cpplint will treat as .h in checks. Values are |
| 139 | + automatically added to --extensions list. |
| 140 | +
|
| 141 | + Examples: |
| 142 | + --headers=hpp,hxx |
| 143 | + --headers=hpp |
| 144 | +
|
137 | 145 | cpplint.py supports per-directory configurations specified in CPPLINT.cfg
|
138 | 146 | files. CPPLINT.cfg file can contain a number of key=value pairs.
|
139 | 147 | Currently the following options are supported:
|
|
143 | 151 | exclude_files=regex
|
144 | 152 | linelength=80
|
145 | 153 | root=subdir
|
| 154 | + headers=x,y,... |
146 | 155 |
|
147 | 156 | "set noparent" option prevents cpplint from traversing directory tree
|
148 | 157 | upwards looking for more .cfg files in parent directories. This option
|
|
160 | 169 |
|
161 | 170 | The "root" option is similar in function to the --root flag (see example
|
162 | 171 | above).
|
| 172 | + |
| 173 | + The "headers" option is similar in function to the --headers flag |
| 174 | + (see example above). |
163 | 175 |
|
164 | 176 | CPPLINT.cfg has an effect on files in the same directory and all
|
165 | 177 | sub-directories, unless overridden by a nested configuration file.
|
|
536 | 548 | # This is set by --extensions flag.
|
537 | 549 | _valid_extensions = set(['cc', 'h', 'cpp', 'cu', 'cuh'])
|
538 | 550 |
|
| 551 | +# Treat all headers starting with 'h' equally: .h, .hpp, .hxx etc. |
| 552 | +# This is set by --headers flag. |
| 553 | +_hpp_headers = set(['h']) |
| 554 | + |
539 | 555 | # {str, bool}: a map from error categories to booleans which indicate if the
|
540 | 556 | # category should be suppressed for every line.
|
541 | 557 | _global_error_suppressions = {}
|
542 | 558 |
|
| 559 | +def ProcessHppHeadersOption(val): |
| 560 | + global _hpp_headers |
| 561 | + try: |
| 562 | + _hpp_headers = set(val.split(',')) |
| 563 | + # Automatically append to extensions list so it does not have to be set 2 times |
| 564 | + _valid_extensions.update(_hpp_headers) |
| 565 | + except ValueError: |
| 566 | + PrintUsage('Header extensions must be comma seperated list.') |
| 567 | + |
| 568 | +def IsHeaderExtension(file_extension): |
| 569 | + return file_extension in _hpp_headers |
543 | 570 |
|
544 | 571 | def ParseNolintSuppressions(filename, raw_line, linenum, error):
|
545 | 572 | """Updates the global list of line error-suppressions.
|
@@ -4272,7 +4299,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
|
4272 | 4299 |
|
4273 | 4300 | # Check if the line is a header guard.
|
4274 | 4301 | is_header_guard = False
|
4275 |
| - if file_extension == 'h': |
| 4302 | + if IsHeaderExtension(file_extension): |
4276 | 4303 | cppvar = GetHeaderGuardCPPVariable(filename)
|
4277 | 4304 | if (line.startswith('#ifndef %s' % cppvar) or
|
4278 | 4305 | line.startswith('#define %s' % cppvar) or
|
@@ -4622,7 +4649,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
|
4622 | 4649 | CheckGlobalStatic(filename, clean_lines, linenum, error)
|
4623 | 4650 | CheckPrintf(filename, clean_lines, linenum, error)
|
4624 | 4651 |
|
4625 |
| - if file_extension == 'h': |
| 4652 | + if IsHeaderExtension(file_extension): |
4626 | 4653 | # TODO(unknown): check that 1-arg constructors are explicit.
|
4627 | 4654 | # How to tell it's a constructor?
|
4628 | 4655 | # (handled in CheckForNonStandardConstructs for now)
|
@@ -4729,7 +4756,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
|
4729 | 4756 | # Check for use of unnamed namespaces in header files. Registration
|
4730 | 4757 | # macros are typically OK, so we allow use of "namespace {" on lines
|
4731 | 4758 | # that end with backslashes.
|
4732 |
| - if (file_extension == 'h' |
| 4759 | + if (IsHeaderExtension(file_extension) |
4733 | 4760 | and Search(r'\bnamespace\s*{', line)
|
4734 | 4761 | and line[-1] != '\\'):
|
4735 | 4762 | error(filename, linenum, 'build/namespaces', 4,
|
@@ -5819,7 +5846,7 @@ def ProcessFileData(filename, file_extension, lines, error,
|
5819 | 5846 | RemoveMultiLineComments(filename, lines, error)
|
5820 | 5847 | clean_lines = CleansedLines(lines)
|
5821 | 5848 |
|
5822 |
| - if file_extension == 'h': |
| 5849 | + if IsHeaderExtension(file_extension): |
5823 | 5850 | CheckForHeaderGuard(filename, clean_lines, error)
|
5824 | 5851 |
|
5825 | 5852 | for line in xrange(clean_lines.NumLines()):
|
@@ -5902,6 +5929,8 @@ def ProcessConfigOverrides(filename):
|
5902 | 5929 | elif name == 'root':
|
5903 | 5930 | global _root
|
5904 | 5931 | _root = val
|
| 5932 | + elif name == 'headers': |
| 5933 | + ProcessHppHeadersOption(val) |
5905 | 5934 | else:
|
5906 | 5935 | sys.stderr.write(
|
5907 | 5936 | 'Invalid configuration option (%s) in file %s\n' %
|
@@ -6047,7 +6076,8 @@ def ParseArguments(args):
|
6047 | 6076 | 'filter=',
|
6048 | 6077 | 'root=',
|
6049 | 6078 | 'linelength=',
|
6050 |
| - 'extensions=']) |
| 6079 | + 'extensions=', |
| 6080 | + 'headers=']) |
6051 | 6081 | except getopt.GetoptError:
|
6052 | 6082 | PrintUsage('Invalid arguments.')
|
6053 | 6083 |
|
@@ -6088,6 +6118,8 @@ def ParseArguments(args):
|
6088 | 6118 | _valid_extensions = set(val.split(','))
|
6089 | 6119 | except ValueError:
|
6090 | 6120 | PrintUsage('Extensions must be comma seperated list.')
|
| 6121 | + elif opt == '--headers': |
| 6122 | + ProcessHppHeadersOption(val) |
6091 | 6123 |
|
6092 | 6124 | if not filenames:
|
6093 | 6125 | PrintUsage('No files were specified.')
|
|
0 commit comments