Loads the configuration files and processes the config overrides. Args: filename: The name of the file being processed by the linter. Returns: False if the current |filename| should not be processed further.
(filename)
| 6208 | CheckForNewlineAtEOF(filename, lines, error) |
| 6209 | |
| 6210 | def ProcessConfigOverrides(filename): |
| 6211 | """ Loads the configuration files and processes the config overrides. |
| 6212 | |
| 6213 | Args: |
| 6214 | filename: The name of the file being processed by the linter. |
| 6215 | |
| 6216 | Returns: |
| 6217 | False if the current |filename| should not be processed further. |
| 6218 | """ |
| 6219 | |
| 6220 | abs_filename = os.path.abspath(filename) |
| 6221 | cfg_filters = [] |
| 6222 | keep_looking = True |
| 6223 | while keep_looking: |
| 6224 | abs_path, base_name = os.path.split(abs_filename) |
| 6225 | if not base_name: |
| 6226 | break # Reached the root directory. |
| 6227 | |
| 6228 | cfg_file = os.path.join(abs_path, "CPPLINT.cfg") |
| 6229 | abs_filename = abs_path |
| 6230 | if not os.path.isfile(cfg_file): |
| 6231 | continue |
| 6232 | |
| 6233 | try: |
| 6234 | with open(cfg_file) as file_handle: |
| 6235 | for line in file_handle: |
| 6236 | line, _, _ = line.partition('#') # Remove comments. |
| 6237 | if not line.strip(): |
| 6238 | continue |
| 6239 | |
| 6240 | name, _, val = line.partition('=') |
| 6241 | name = name.strip() |
| 6242 | val = val.strip() |
| 6243 | if name == 'set noparent': |
| 6244 | keep_looking = False |
| 6245 | elif name == 'filter': |
| 6246 | cfg_filters.append(val) |
| 6247 | elif name == 'exclude_files': |
| 6248 | # When matching exclude_files pattern, use the base_name of |
| 6249 | # the current file name or the directory name we are processing. |
| 6250 | # For example, if we are checking for lint errors in /foo/bar/baz.cc |
| 6251 | # and we found the .cfg file at /foo/CPPLINT.cfg, then the config |
| 6252 | # file's "exclude_files" filter is meant to be checked against "bar" |
| 6253 | # and not "baz" nor "bar/baz.cc". |
| 6254 | if base_name: |
| 6255 | pattern = re.compile(val) |
| 6256 | if pattern.match(base_name): |
| 6257 | if _cpplint_state.quiet: |
| 6258 | # Suppress "Ignoring file" warning when using --quiet. |
| 6259 | return False |
| 6260 | _cpplint_state.PrintInfo('Ignoring "%s": file excluded by "%s". ' |
| 6261 | 'File path component "%s" matches ' |
| 6262 | 'pattern "%s"\n' % |
| 6263 | (filename, cfg_file, base_name, val)) |
| 6264 | return False |
| 6265 | elif name == 'linelength': |
| 6266 | global _line_length |
| 6267 | try: |
no test coverage detected