From 8920b13221a10324ae56c60f75670f4991339692 Mon Sep 17 00:00:00 2001 From: LukeCz Date: Mon, 26 Sep 2016 19:40:47 -0500 Subject: [PATCH] Changes after review --- cpplint/cpplint.py | 7 ++----- cpplint/cpplint_unittest.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index b12d60db6..e98e5729d 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -550,7 +550,7 @@ # Treat all headers starting with 'h' equally: .h, .hpp, .hxx etc. # This is set by --headers flag. -_hpp_headers = None +_hpp_headers = set(['h']) # {str, bool}: a map from error categories to booleans which indicate if the # category should be suppressed for every line. @@ -566,10 +566,7 @@ def ProcessHppHeadersOption(val): PrintUsage('Header extensions must be comma seperated list.') def IsHeaderExtension(file_extension): - if _hpp_headers and file_extension in _hpp_headers: - return True - else: - return file_extension == 'h' + return file_extension in _hpp_headers def ParseNolintSuppressions(filename, raw_line, linenum, error): """Updates the global list of line error-suppressions. diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index d738d99d5..638bbc23f 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -3778,6 +3778,7 @@ def testParseArguments(self): old_error_categories = cpplint._ERROR_CATEGORIES old_output_format = cpplint._cpplint_state.output_format old_verbose_level = cpplint._cpplint_state.verbose_level + old_headers = cpplint._hpp_headers old_filters = cpplint._cpplint_state.filters old_line_length = cpplint._line_length old_valid_extensions = cpplint._valid_extensions @@ -3795,6 +3796,7 @@ def testParseArguments(self): self.assertRaises(SystemExit, cpplint.ParseArguments, ['--filter=foo']) self.assertRaises(SystemExit, cpplint.ParseArguments, ['--filter=+a,b,-c']) + self.assertRaises(SystemExit, cpplint.ParseArguments, ['--headers']) self.assertEquals(['foo.cc'], cpplint.ParseArguments(['foo.cc'])) self.assertEquals(old_output_format, cpplint._cpplint_state.output_format) @@ -3837,6 +3839,13 @@ def testParseArguments(self): self.assertEqual(['foo.h'], cpplint.ParseArguments(['--extensions=hpp,cpp,cpp', 'foo.h'])) self.assertEqual(set(['hpp', 'cpp']), cpplint._valid_extensions) + + self.assertEqual(set(['h']), cpplint._hpp_headers) # Default value + self.assertEqual(['foo.h'], + cpplint.ParseArguments(['--extensions=cpp,cpp', '--headers=hpp,h', 'foo.h'])) + self.assertEqual(set(['hpp', 'h']), cpplint._hpp_headers) + self.assertEqual(set(['hpp', 'h', 'cpp']), cpplint._valid_extensions) + finally: cpplint._USAGE = old_usage cpplint._ERROR_CATEGORIES = old_error_categories @@ -3845,6 +3854,7 @@ def testParseArguments(self): cpplint._cpplint_state.filters = old_filters cpplint._line_length = old_line_length cpplint._valid_extensions = old_valid_extensions + cpplint._hpp_headers = old_headers def testLineLength(self): old_line_length = cpplint._line_length