Anonymous avatar Anonymous committed 93ec890

Added check_ignores_trailing_ws option

Comments (0)

Files changed (1)

 ignored_patterns = res/.*
 tab_size = 4
 
+# for check_hook to only check for tabs  (and ignore trailing whitespace) set to True. Default, if not present is False
+check_ignores_trailing_ws = False
+
 # to examine only modified lines from check_hook, use:
 # check_diffs = True
 
         self.fixup_diffs = ui.configbool('checkfiles', 'fixup_diffs')
         self.tab_size = int(ui.config('checkfiles', 'tab_size', default='4'))
         self.use_spaces = ui.configbool('checkfiles', 'use_spaces', True)
+        self.check_ignores_trailing_ws = ui.configbool('checkfiles', 'check_ignores_trailing_ws', False)
 
         if 'tabsize' in opts:
             self.tab_size = int(opts['tabsize'])
         self.ui.debug('checkfiles: check diffs only: %r\n' % self.check_diffs)
         self.ui.debug('checkfiles: use spaces: %r\n' % self.use_spaces)
         self.ui.debug('checkfiles: tab size: %r\n' % self.tab_size)
+        self.ui.debug('checkfiles: ignore trailing ws: %r\n' % self.check_ignores_trailing_ws)
 
         if ctx:
             self.set_changectx(ctx)
                     elif label == 'diff.hunk':
                         hunk = chunk
                     elif file and label == 'diff.trailingwhitespace' and lastlabel == 'diff.inserted' and chunk != '\r':
-                        state.found_ws_end()
-                        self.ui.note('%s: trailing whitespace in %s\n' % (file, hunk))
+                        if self.check_ignores_trailing_ws:
+                            # still check for presence of \t tough
+                            if self.use_spaces and  ('\t' in chunk):
+                                state.found_ws_end()
+                                self.ui.note('%s: trailing tab in %s\n' % (file, hunk))
+                        else:
+                            state.found_ws_end()
+                            self.ui.note('%s: trailing whitespace in %s\n' % (file, hunk))
                     elif file and label == 'diff.inserted' and self.is_ws_before_text(chunk[1:]):
                         state.found_ws_begin()
                         if self.use_spaces:
 
                 for num, line in enumerate(fctx.data().splitlines(), 1):
                     if line.isspace():
-                        state.found_all_ws()
-                        self.ui.note('%s (%i): all whitespace\n' % (file, num))
+                        if self.check_ignores_trailing_ws:
+                            # still check for presence of \t
+                            if self.use_spaces and ('\t' in line):
+                                state.found_all_ws()
+                                self.ui.note('%s (%i): tabs in all whitespace line\n' % (file, num))
+                        else:
+                            state.found_all_ws()
+                            self.ui.note('%s (%i): all whitespace\n' % (file, num))
 
                     elif line.endswith((' ', '\t')):
-                        state.found_ws_end()
-                        self.ui.note('%s (%i): trailing whitespace\n' % (file, num))
+                        if self.check_ignores_trailing_ws:
+                            # still check for presence of \t
+                            if self.use_spaces and ('\t' in line):
+                                state.found_ws_end()
+                                self.ui.note('%s (%i): trailing tabs\n' % (file, num))
+                        else:
+                            state.found_ws_end()
+                            self.ui.note('%s (%i): trailing whitespace\n' % (file, num))
 
                         line = line.expandtabs(self.tab_size)
                         non_ws_len = len(line.rstrip())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.