Commits

Marcus Lindblom Sonestedt  committed 66d93b7

checkfiles: Add ignored_exts option. Fixes #3

  • Participants
  • Parent commits 4fd3978

Comments (0)

Files changed (1)

File checkfiles.py

 precommit.checkfiles = python:/path/to/checkfiles.py:fixup_hook
 
 [checkfiles]
-# default is any text file
+# default is all text files
 checked_exts = .c .h .cpp .xml .cs .html .js .css .txt .py .nsi .java .aspx .asp .bat .cmd .glsl
+# default is .sln .suo .vcproj .csproj .ui
+ignored_exts = .xslt
 ignored_files = foo/contains_tabs.txt bar/contains_trailing_ws.txt
 tab_size = 4
 # to examine only modified lines from check_hook (no effect on fixup_hook or command), use:
 
         self.checked_exts = ui.configlist('checkfiles', 'checked_exts',
             default='""')
+        self.ignored_exts = ui.configlist('checkfiles', 'ignored_exts',
+            default='.sln .suo .vcproj .csproj .ui') # some common autogenerated filetypes
         self.ignored_files = ui.configlist('checkfiles', 'ignored_files')
         self.check_diffs = ui.configbool('checkfiles', 'check_diffs')
         self.tab_size = int(ui.config('checkfiles', 'tab_size', default='4'))
 
-        self.ui.debug('checkfiles: checked extensions: %s\n' % ' '.join(self.checked_exts))
+        if self.checked_exts == '""':
+            self.ui.debug('checkfiles: checked extensions: %s\n' % ' '.join(self.checked_exts))
+        else:
+            self.ui.debug('checkfiles: checked extensions: (all text files)\n')
+
+        self.ui.debug('checkfiles: ignored extensions: %s\n' % ' '.join(self.ignored_exts))
         self.ui.debug('checkfiles: ignored files: %s\n' % ' '.join(self.ignored_files))
 
     def is_relevant(self, file):
             self.ui.debug('checkfiles: ignoring %s (explicit ignore)\n' % file)
             return False
 
+        if any(map(lambda e:file.endswith(e), self.ignored_exts)):
+            self.ui.debug('checkfiles: ignoring %s (ignored extension)\n' % file)
+            return False
+
         if not any(map(lambda e:file.endswith(e), self.checked_exts)):
             self.ui.debug('checkfiles: ignoring %s (non-checked extension)\n' % file)
             return False