Commits

Lorenzo Gil Sánchez  committed a0ae692

Simplify the checks for pep8, pyflakes and pyjslint

  • Participants
  • Parent commits 1cd3281

Comments (0)

Files changed (1)

File hghooks/code.py

 
 
 def pep8hook(ui, repo, hooktype, node, pending, **kwargs):
-    if HAS_PEP8:
-        pep8_options = {}
-        options = ['exclude', 'filename', 'select', 'ignore',
-                   'max-line-length']
-        for opt in options:
-            if ui.config('pep8', opt, ''):
-                pep8_options[opt] = ui.config('pep8', opt, '')
-        checker_manager = CheckerManager(ui, repo, node, 'no-pep8')
-        return checker_manager.check(pep8_checker(pep8_options))
-    else:
+    if not HAS_PEP8:
         ui.warn('You need the pep8 python module to use the pep8hook')
-        return 1
+        return True  # Failure
+
+    pep8_options = {}
+    options = ['exclude', 'filename', 'select', 'ignore', 'max-line-length']
+    for opt in options:
+        if ui.config('pep8', opt, ''):
+            pep8_options[opt] = ui.config('pep8', opt, '')
+            
+    checker_manager = CheckerManager(ui, repo, node, 'no-pep8')
+    return checker_manager.check(pep8_checker(pep8_options))
 
 
 pdb_catcher = re.compile(r'^[^#]*pdb\.set_trace\(\)', re_options)
 
 
 def pyflakeshook(ui, repo, hooktype, node, pending, **kwargs):
-    if HAS_PYFLAKES:
-        checker_manager = CheckerManager(ui, repo, node, 'no-pyflakes')
-        return checker_manager.check(pyflakes_checker)
-    else:
+    if not HAS_PYFLAKES:
         ui.warn('You need the pyflakes python module to use the pyflakeshook')
-        return 1
+        return True  # Failure
+
+    checker_manager = CheckerManager(ui, repo, node, 'no-pyflakes')
+    return checker_manager.check(pyflakes_checker)
 
 
 def jslint_check(data, filename):
 
 
 def jslinthook(ui, repo, hooktype, node, pending, **kwargs):
-    if HAS_JSLINT:
-        checker_manager = CheckerManager(ui, repo, node, 'no-jslint',
-                                         extension='.js')
-        return checker_manager.check(jslint_checker)
-    else:
+    if not HAS_JSLINT:
         ui.warn('You need the pyjslint python module to use the jslinthook')
-        return 1
+        return True  # Failure
+
+    checker_manager = CheckerManager(ui, repo, node, 'no-jslint',
+                                     extension='.js')
+    return checker_manager.check(jslint_checker)