@@ 6105-6198 (lines=94) @@ | ||
6102 | ||
6103 | CheckForNewlineAtEOF(filename, lines, error) |
|
6104 | ||
6105 | def ProcessConfigOverrides(filename): |
|
6106 | """ Loads the configuration files and processes the config overrides. |
|
6107 | ||
6108 | Args: |
|
6109 | filename: The name of the file being processed by the linter. |
|
6110 | ||
6111 | Returns: |
|
6112 | False if the current |filename| should not be processed further. |
|
6113 | """ |
|
6114 | ||
6115 | abs_filename = os.path.abspath(filename) |
|
6116 | cfg_filters = [] |
|
6117 | keep_looking = True |
|
6118 | while keep_looking: |
|
6119 | abs_path, base_name = os.path.split(abs_filename) |
|
6120 | if not base_name: |
|
6121 | break # Reached the root directory. |
|
6122 | ||
6123 | cfg_file = os.path.join(abs_path, "CPPLINT.cfg") |
|
6124 | abs_filename = abs_path |
|
6125 | if not os.path.isfile(cfg_file): |
|
6126 | continue |
|
6127 | ||
6128 | try: |
|
6129 | with open(cfg_file) as file_handle: |
|
6130 | for line in file_handle: |
|
6131 | line, _, _ = line.partition('#') # Remove comments. |
|
6132 | if not line.strip(): |
|
6133 | continue |
|
6134 | ||
6135 | name, _, val = line.partition('=') |
|
6136 | name = name.strip() |
|
6137 | val = val.strip() |
|
6138 | if name == 'set noparent': |
|
6139 | keep_looking = False |
|
6140 | elif name == 'filter': |
|
6141 | cfg_filters.append(val) |
|
6142 | elif name == 'exclude_files': |
|
6143 | # When matching exclude_files pattern, use the base_name of |
|
6144 | # the current file name or the directory name we are processing. |
|
6145 | # For example, if we are checking for lint errors in /foo/bar/baz.cc |
|
6146 | # and we found the .cfg file at /foo/CPPLINT.cfg, then the config |
|
6147 | # file's "exclude_files" filter is meant to be checked against "bar" |
|
6148 | # and not "baz" nor "bar/baz.cc". |
|
6149 | if base_name: |
|
6150 | pattern = re.compile(val) |
|
6151 | if pattern.match(base_name): |
|
6152 | _cpplint_state.PrintInfo('Ignoring "%s": file excluded by ' |
|
6153 | '"%s". File path component "%s" matches pattern "%s"\n' % |
|
6154 | (filename, cfg_file, base_name, val)) |
|
6155 | return False |
|
6156 | elif name == 'linelength': |
|
6157 | global _line_length |
|
6158 | try: |
|
6159 | _line_length = int(val) |
|
6160 | except ValueError: |
|
6161 | _cpplint_state.PrintError('Line length must be numeric.') |
|
6162 | elif name == 'extensions': |
|
6163 | global _valid_extensions |
|
6164 | try: |
|
6165 | extensions = [ext.strip() for ext in val.split(',')] |
|
6166 | _valid_extensions = set(extensions) |
|
6167 | except ValueError: |
|
6168 | sys.stderr.write('Extensions should be a comma-separated list of values;' |
|
6169 | 'for example: extensions=hpp,cpp\n' |
|
6170 | 'This could not be parsed: "%s"' % (val,)) |
|
6171 | elif name == 'headers': |
|
6172 | global _header_extensions |
|
6173 | try: |
|
6174 | extensions = [ext.strip() for ext in val.split(',')] |
|
6175 | _header_extensions = set(extensions) |
|
6176 | except ValueError: |
|
6177 | sys.stderr.write('Extensions should be a comma-separated list of values;' |
|
6178 | 'for example: extensions=hpp,cpp\n' |
|
6179 | 'This could not be parsed: "%s"' % (val,)) |
|
6180 | elif name == 'root': |
|
6181 | global _root |
|
6182 | _root = val |
|
6183 | else: |
|
6184 | _cpplint_state.PrintError( |
|
6185 | 'Invalid configuration option (%s) in file %s\n' % |
|
6186 | (name, cfg_file)) |
|
6187 | ||
6188 | except IOError: |
|
6189 | _cpplint_state.PrintError( |
|
6190 | "Skipping config file '%s': Can't open for reading\n" % cfg_file) |
|
6191 | keep_looking = False |
|
6192 | ||
6193 | # Apply all the accumulated filters in reverse order (top-level directory |
|
6194 | # config options having the least priority). |
|
6195 | for cfg_filter in reversed(cfg_filters): |
|
6196 | _AddFilters(cfg_filter) |
|
6197 | ||
6198 | return True |
|
6199 | ||
6200 | ||
6201 | def ProcessFile(filename, vlevel, extra_check_functions=None): |
@@ 6105-6198 (lines=94) @@ | ||
6102 | ||
6103 | CheckForNewlineAtEOF(filename, lines, error) |
|
6104 | ||
6105 | def ProcessConfigOverrides(filename): |
|
6106 | """ Loads the configuration files and processes the config overrides. |
|
6107 | ||
6108 | Args: |
|
6109 | filename: The name of the file being processed by the linter. |
|
6110 | ||
6111 | Returns: |
|
6112 | False if the current |filename| should not be processed further. |
|
6113 | """ |
|
6114 | ||
6115 | abs_filename = os.path.abspath(filename) |
|
6116 | cfg_filters = [] |
|
6117 | keep_looking = True |
|
6118 | while keep_looking: |
|
6119 | abs_path, base_name = os.path.split(abs_filename) |
|
6120 | if not base_name: |
|
6121 | break # Reached the root directory. |
|
6122 | ||
6123 | cfg_file = os.path.join(abs_path, "CPPLINT.cfg") |
|
6124 | abs_filename = abs_path |
|
6125 | if not os.path.isfile(cfg_file): |
|
6126 | continue |
|
6127 | ||
6128 | try: |
|
6129 | with open(cfg_file) as file_handle: |
|
6130 | for line in file_handle: |
|
6131 | line, _, _ = line.partition('#') # Remove comments. |
|
6132 | if not line.strip(): |
|
6133 | continue |
|
6134 | ||
6135 | name, _, val = line.partition('=') |
|
6136 | name = name.strip() |
|
6137 | val = val.strip() |
|
6138 | if name == 'set noparent': |
|
6139 | keep_looking = False |
|
6140 | elif name == 'filter': |
|
6141 | cfg_filters.append(val) |
|
6142 | elif name == 'exclude_files': |
|
6143 | # When matching exclude_files pattern, use the base_name of |
|
6144 | # the current file name or the directory name we are processing. |
|
6145 | # For example, if we are checking for lint errors in /foo/bar/baz.cc |
|
6146 | # and we found the .cfg file at /foo/CPPLINT.cfg, then the config |
|
6147 | # file's "exclude_files" filter is meant to be checked against "bar" |
|
6148 | # and not "baz" nor "bar/baz.cc". |
|
6149 | if base_name: |
|
6150 | pattern = re.compile(val) |
|
6151 | if pattern.match(base_name): |
|
6152 | _cpplint_state.PrintInfo('Ignoring "%s": file excluded by ' |
|
6153 | '"%s". File path component "%s" matches pattern "%s"\n' % |
|
6154 | (filename, cfg_file, base_name, val)) |
|
6155 | return False |
|
6156 | elif name == 'linelength': |
|
6157 | global _line_length |
|
6158 | try: |
|
6159 | _line_length = int(val) |
|
6160 | except ValueError: |
|
6161 | _cpplint_state.PrintError('Line length must be numeric.') |
|
6162 | elif name == 'extensions': |
|
6163 | global _valid_extensions |
|
6164 | try: |
|
6165 | extensions = [ext.strip() for ext in val.split(',')] |
|
6166 | _valid_extensions = set(extensions) |
|
6167 | except ValueError: |
|
6168 | sys.stderr.write('Extensions should be a comma-separated list of values;' |
|
6169 | 'for example: extensions=hpp,cpp\n' |
|
6170 | 'This could not be parsed: "%s"' % (val,)) |
|
6171 | elif name == 'headers': |
|
6172 | global _header_extensions |
|
6173 | try: |
|
6174 | extensions = [ext.strip() for ext in val.split(',')] |
|
6175 | _header_extensions = set(extensions) |
|
6176 | except ValueError: |
|
6177 | sys.stderr.write('Extensions should be a comma-separated list of values;' |
|
6178 | 'for example: extensions=hpp,cpp\n' |
|
6179 | 'This could not be parsed: "%s"' % (val,)) |
|
6180 | elif name == 'root': |
|
6181 | global _root |
|
6182 | _root = val |
|
6183 | else: |
|
6184 | _cpplint_state.PrintError( |
|
6185 | 'Invalid configuration option (%s) in file %s\n' % |
|
6186 | (name, cfg_file)) |
|
6187 | ||
6188 | except IOError: |
|
6189 | _cpplint_state.PrintError( |
|
6190 | "Skipping config file '%s': Can't open for reading\n" % cfg_file) |
|
6191 | keep_looking = False |
|
6192 | ||
6193 | # Apply all the accumulated filters in reverse order (top-level directory |
|
6194 | # config options having the least priority). |
|
6195 | for cfg_filter in reversed(cfg_filters): |
|
6196 | _AddFilters(cfg_filter) |
|
6197 | ||
6198 | return True |
|
6199 | ||
6200 | ||
6201 | def ProcessFile(filename, vlevel, extra_check_functions=None): |