]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Detect mixed usage of spaces and tabs.
authorMartin Liska <mliska@suse.cz>
Mon, 19 Nov 2018 08:08:28 +0000 (09:08 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 19 Nov 2018 08:08:28 +0000 (08:08 +0000)
2018-11-19  Martin Liska  <mliska@suse.cz>

* check_GNU_style_lib.py: Detect mixed usage
of spaces and tabs.

From-SVN: r266261

contrib/ChangeLog
contrib/check_GNU_style_lib.py

index 8984c1901e2bbcbd64a0f85b1a16e1d0ce54471e..64dcdfcb76a8e475b7f458bc53959e7e6c47bc84 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-19  Martin Liska  <mliska@suse.cz>
+
+       * check_GNU_style_lib.py: Detect mixed usage
+       of spaces and tabs.
+
 2018-11-14  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * gcc_update (files_and_dependencies): Handle libphobos.
index 63d0538aa572c4ac946fd47eaa7d1a704a97c718..ac3682fb2aff1f375e4aabecf8cad21300c17e11 100755 (executable)
@@ -99,6 +99,18 @@ class SpacesCheck:
                 line.replace(self.expanded_tab, error_string(ws_char * ts)),
                 'blocks of 8 spaces should be replaced with tabs', i)
 
+class SpacesAndTabsMixedCheck:
+    def __init__(self):
+        self.re = re.compile('\ \t')
+
+    def check(self, filename, lineno, line):
+        stripped = line.lstrip()
+        start = line[:len(line) - len(stripped)]
+        if self.re.search(line):
+            return CheckError(filename, lineno,
+                error_string(start.replace('\t', ws_char * ts)) + line[len(start):],
+                'a space should not precede a tab', 0)
+
 class TrailingWhitespaceCheck:
     def __init__(self):
         self.re = re.compile('(\s+)$')
@@ -236,12 +248,27 @@ class TrailingWhitespaceTest(unittest.TestCase):
         r = self.check.check('foo', 123, 'a = 123;\t')
         self.assertIsNotNone(r)
 
+class SpacesAndTabsMixedTest(unittest.TestCase):
+    def setUp(self):
+        self.check = SpacesAndTabsMixedCheck()
+
+    def test_trailing_whitespace_check_basic(self):
+        r = self.check.check('foo', 123, '   \ta = 123;')
+        self.assertEqual('foo', r.filename)
+        self.assertEqual(0, r.column)
+        self.assertIsNotNone(r.console_error)
+        r = self.check.check('foo', 123, '   \t  a = 123;')
+        self.assertIsNotNone(r.console_error)
+        r = self.check.check('foo', 123, '\t  a = 123;')
+        self.assertIsNone(r)
+
 def check_GNU_style_file(file, file_encoding, format):
     checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(),
         SentenceSeparatorCheck(), SentenceEndOfCommentCheck(),
         SentenceDotEndCheck(), FunctionParenthesisCheck(),
         SquareBracketCheck(), ClosingParenthesisCheck(),
-        BracesOnSeparateLineCheck(), TrailinigOperatorCheck()]
+        BracesOnSeparateLineCheck(), TrailinigOperatorCheck(),
+        SpacesAndTabsMixedCheck()]
     errors = []
 
     patch = PatchSet(file, encoding=file_encoding)