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)
| 7425 | |
| 7426 | |
| 7427 | def ProcessConfigOverrides(filename): |
| 7428 | """Loads the configuration files and processes the config overrides. |
| 7429 | |
| 7430 | Args: |
| 7431 | filename: The name of the file being processed by the linter. |
| 7432 | |
| 7433 | Returns: |
| 7434 | False if the current |filename| should not be processed further. |
| 7435 | """ |
| 7436 | |
| 7437 | abs_filename = os.path.abspath(filename) |
| 7438 | cfg_filters = [] |
| 7439 | keep_looking = True |
| 7440 | while keep_looking: |
| 7441 | abs_path, base_name = os.path.split(abs_filename) |
| 7442 | if not base_name: |
| 7443 | break # Reached the root directory. |
| 7444 | |
| 7445 | cfg_file = os.path.join(abs_path, _config_filename) |
| 7446 | abs_filename = abs_path |
| 7447 | if not os.path.isfile(cfg_file): |
| 7448 | continue |
| 7449 | |
| 7450 | try: |
| 7451 | with codecs.open(cfg_file, "r", "utf8", "replace") as file_handle: |
| 7452 | for line in file_handle: |
| 7453 | line, _, _ = line.partition("#") # Remove comments. |
| 7454 | if not line.strip(): |
| 7455 | continue |
| 7456 | |
| 7457 | name, _, val = line.partition("=") |
| 7458 | name = name.strip() |
| 7459 | val = val.strip() |
| 7460 | if name == "set noparent": |
| 7461 | keep_looking = False |
| 7462 | elif name == "filter": |
| 7463 | cfg_filters.append(val) |
| 7464 | elif name == "exclude_files": |
| 7465 | # When matching exclude_files pattern, use the base_name of |
| 7466 | # the current file name or the directory name we are processing. |
| 7467 | # For example, if we are checking for lint errors in /foo/bar/baz.cc |
| 7468 | # and we found the .cfg file at /foo/CPPLINT.cfg, then the config |
| 7469 | # file's "exclude_files" filter is meant to be checked against "bar" |
| 7470 | # and not "baz" nor "bar/baz.cc". |
| 7471 | if base_name: |
| 7472 | pattern = re.compile(val) |
| 7473 | if pattern.match(base_name): |
| 7474 | if _cpplint_state.quiet: |
| 7475 | # Suppress "Ignoring file" warning when using --quiet. |
| 7476 | return False |
| 7477 | _cpplint_state.PrintInfo( |
| 7478 | f'Ignoring "{filename}": file excluded by "{cfg_file}". ' |
| 7479 | 'File path component "%s" matches ' |
| 7480 | 'pattern "%s"\n' % (base_name, val) |
| 7481 | ) |
| 7482 | return False |
| 7483 | elif name == "linelength": |
| 7484 | global _line_length |
no test coverage detected