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)
| 5866 | CheckForNewlineAtEOF(filename, lines, error) |
| 5867 | |
| 5868 | def ProcessConfigOverrides(filename): |
| 5869 | """ Loads the configuration files and processes the config overrides. |
| 5870 | |
| 5871 | Args: |
| 5872 | filename: The name of the file being processed by the linter. |
| 5873 | |
| 5874 | Returns: |
| 5875 | False if the current |filename| should not be processed further. |
| 5876 | """ |
| 5877 | |
| 5878 | abs_filename = os.path.abspath(filename) |
| 5879 | cfg_filters = [] |
| 5880 | keep_looking = True |
| 5881 | while keep_looking: |
| 5882 | abs_path, base_name = os.path.split(abs_filename) |
| 5883 | if not base_name: |
| 5884 | break # Reached the root directory. |
| 5885 | |
| 5886 | cfg_file = os.path.join(abs_path, "CPPLINT.cfg") |
| 5887 | abs_filename = abs_path |
| 5888 | if not os.path.isfile(cfg_file): |
| 5889 | continue |
| 5890 | |
| 5891 | try: |
| 5892 | with open(cfg_file) as file_handle: |
| 5893 | for line in file_handle: |
| 5894 | line, _, _ = line.partition('#') # Remove comments. |
| 5895 | if not line.strip(): |
| 5896 | continue |
| 5897 | |
| 5898 | name, _, val = line.partition('=') |
| 5899 | name = name.strip() |
| 5900 | val = val.strip() |
| 5901 | if name == 'set noparent': |
| 5902 | keep_looking = False |
| 5903 | elif name == 'filter': |
| 5904 | cfg_filters.append(val) |
| 5905 | elif name == 'exclude_files': |
| 5906 | # When matching exclude_files pattern, use the base_name of |
| 5907 | # the current file name or the directory name we are processing. |
| 5908 | # For example, if we are checking for lint errors in /foo/bar/baz.cc |
| 5909 | # and we found the .cfg file at /foo/CPPLINT.cfg, then the config |
| 5910 | # file's "exclude_files" filter is meant to be checked against "bar" |
| 5911 | # and not "baz" nor "bar/baz.cc". |
| 5912 | if base_name: |
| 5913 | pattern = re.compile(val) |
| 5914 | if pattern.match(base_name): |
| 5915 | sys.stderr.write('Ignoring "%s": file excluded by "%s". ' |
| 5916 | 'File path component "%s" matches ' |
| 5917 | 'pattern "%s"\n' % |
| 5918 | (filename, cfg_file, base_name, val)) |
| 5919 | return False |
| 5920 | elif name == 'linelength': |
| 5921 | global _line_length |
| 5922 | try: |
| 5923 | _line_length = int(val) |
| 5924 | except ValueError: |
| 5925 | sys.stderr.write('Line length must be numeric.') |
no test coverage detected