Browse Source

Various fixes for linter checks (not registered)

David Cramer 8 years ago
parent
commit
0764106df5
2 changed files with 17 additions and 11 deletions
  1. 2 1
      setup.py
  2. 15 10
      src/sentry/lint/engine.py

+ 2 - 1
setup.py

@@ -68,7 +68,8 @@ IS_LIGHT_BUILD = os.environ.get('SENTRY_LIGHT_BUILD') == '1'
 
 dev_requires = [
     'Babel',
-    'flake8>=2.0,<2.1',
+    'flake8>=2.1,<2.2',
+    'pycodestyle>=2.0,<2.1',
     'isort>=4.2.2,<4.3.0',
 ]
 

+ 15 - 10
src/sentry/lint/engine.py

@@ -20,19 +20,21 @@ os.environ['PYFLAKES_NODOCTEST'] = '1'
 
 
 def register_checks():
-    import pep8
+    import pycodestyle
     from sentry.lint.absolute_import_check import AbsoluteImportCheck
     from sentry.lint.mock_check import MockCheck
 
-    pep8.register_check(MockCheck, codes=[MockCheck.code])
-    pep8.register_check(AbsoluteImportCheck, codes=[AbsoluteImportCheck.code])
+    pycodestyle.register_check(MockCheck, codes=[MockCheck.code])
+    pycodestyle.register_check(AbsoluteImportCheck, codes=[AbsoluteImportCheck.code])
+
+register_checks()
 
 
 def get_files(path):
     results = []
     for root, _, files in os.walk(path):
         for name in files:
-            results.append(os.path.join(root, name))
+            results.append(os.path.abspath(os.path.join(root, name)))
     return results
 
 
@@ -46,12 +48,11 @@ def get_files_for_list(file_list):
             if os.path.isdir(path):
                 files_to_check.extend(get_files(path))
             else:
-                files_to_check.append(path)
+                files_to_check.append(os.path.abspath(path))
     return files_to_check
 
 
 def py_lint(file_list):
-    from flake8.main import DEFAULT_CONFIG
     from flake8.engine import get_style_guide
 
     if file_list is None:
@@ -61,7 +62,7 @@ def py_lint(file_list):
     # remove non-py files and files which no longer exist
     file_list = filter(lambda x: x.endswith('.py'), file_list)
 
-    flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
+    flake8_style = get_style_guide(parse_argv=True)
     report = flake8_style.check_files(file_list)
 
     return report.total_errors != 0
@@ -73,7 +74,7 @@ def js_lint(file_list=None):
     eslint_path = os.path.join(project_root, 'node_modules', '.bin', 'eslint')
 
     if not os.path.exists(eslint_path):
-        print '!! Skipping JavaScript linting because eslint is not installed.'
+        print('!! Skipping JavaScript linting because eslint is not installed.')
         return False
 
     if file_list is None:
@@ -83,10 +84,14 @@ def js_lint(file_list=None):
     eslint_config = os.path.join(project_root, '.eslintrc')
 
     has_errors = False
-    file_list = filter(lambda x: x.endswith(('.js', '.jsx')), file_list)
+    file_list = [
+        x for x in file_list
+        if x.endswith(('.js', '.jsx'))
+    ]
+
     if file_list:
         status = Popen([eslint_path, '--config', eslint_config, '--ext', '.jsx']
-                       + list(file_list)).wait()
+                       + file_list).wait()
         has_errors = status != 0
 
     return has_errors