comparison contrib/check_GNU_style_lib.py @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
97 if i != -1: 97 if i != -1:
98 return CheckError(filename, lineno, 98 return CheckError(filename, lineno,
99 line.replace(self.expanded_tab, error_string(ws_char * ts)), 99 line.replace(self.expanded_tab, error_string(ws_char * ts)),
100 'blocks of 8 spaces should be replaced with tabs', i) 100 'blocks of 8 spaces should be replaced with tabs', i)
101 101
102 class SpacesAndTabsMixedCheck:
103 def __init__(self):
104 self.re = re.compile('\ \t')
105
106 def check(self, filename, lineno, line):
107 stripped = line.lstrip()
108 start = line[:len(line) - len(stripped)]
109 if self.re.search(line):
110 return CheckError(filename, lineno,
111 error_string(start.replace('\t', ws_char * ts)) + line[len(start):],
112 'a space should not precede a tab', 0)
113
102 class TrailingWhitespaceCheck: 114 class TrailingWhitespaceCheck:
103 def __init__(self): 115 def __init__(self):
104 self.re = re.compile('(\s+)$') 116 self.re = re.compile('(\s+)$')
105 117
106 def check(self, filename, lineno, line): 118 def check(self, filename, lineno, line):
234 r = self.check.check('foo', 123, 'a = 123; ') 246 r = self.check.check('foo', 123, 'a = 123; ')
235 self.assertIsNotNone(r) 247 self.assertIsNotNone(r)
236 r = self.check.check('foo', 123, 'a = 123;\t') 248 r = self.check.check('foo', 123, 'a = 123;\t')
237 self.assertIsNotNone(r) 249 self.assertIsNotNone(r)
238 250
251 class SpacesAndTabsMixedTest(unittest.TestCase):
252 def setUp(self):
253 self.check = SpacesAndTabsMixedCheck()
254
255 def test_trailing_whitespace_check_basic(self):
256 r = self.check.check('foo', 123, ' \ta = 123;')
257 self.assertEqual('foo', r.filename)
258 self.assertEqual(0, r.column)
259 self.assertIsNotNone(r.console_error)
260 r = self.check.check('foo', 123, ' \t a = 123;')
261 self.assertIsNotNone(r.console_error)
262 r = self.check.check('foo', 123, '\t a = 123;')
263 self.assertIsNone(r)
264
239 def check_GNU_style_file(file, file_encoding, format): 265 def check_GNU_style_file(file, file_encoding, format):
240 checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(), 266 checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(),
241 SentenceSeparatorCheck(), SentenceEndOfCommentCheck(), 267 SentenceSeparatorCheck(), SentenceEndOfCommentCheck(),
242 SentenceDotEndCheck(), FunctionParenthesisCheck(), 268 SentenceDotEndCheck(), FunctionParenthesisCheck(),
243 SquareBracketCheck(), ClosingParenthesisCheck(), 269 SquareBracketCheck(), ClosingParenthesisCheck(),
244 BracesOnSeparateLineCheck(), TrailinigOperatorCheck()] 270 BracesOnSeparateLineCheck(), TrailinigOperatorCheck(),
271 SpacesAndTabsMixedCheck()]
245 errors = [] 272 errors = []
246 273
247 patch = PatchSet(file, encoding=file_encoding) 274 patch = PatchSet(file, encoding=file_encoding)
248 275
249 for pfile in patch.added_files + patch.modified_files: 276 for pfile in patch.added_files + patch.modified_files: