Browse Source

Don't run prettier in ci (#5254)

Ben Vinegar 8 years ago
parent
commit
4f232207a0
2 changed files with 31 additions and 26 deletions
  1. 28 1
      config/hooks/pre-commit
  2. 3 25
      src/sentry/lint/engine.py

+ 28 - 1
config/hooks/pre-commit

@@ -5,8 +5,9 @@ import os
 import sys
 
 from glob import glob
+from subprocess import Popen
 
-from sentry.lint.engine import check_files
+from sentry.lint.engine import check_files, get_js_files
 
 text_type = type(u'')
 
@@ -18,6 +19,29 @@ if 'VIRTUAL_ENV' in os.environ:
     sys.path.insert(0, site_packages)
 
 
+def js_format(file_list=None):
+    """
+    We only format JavaScript code as part of this pre-commit hook. It is not part
+    of the lint engine.
+    """
+    project_root = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)
+    prettier_path = os.path.join(project_root, 'node_modules', '.bin', 'prettier')
+
+    if not os.path.exists(prettier_path):
+        from click import echo
+        echo('!! Skipping JavaScript formatting because prettier is not installed.')
+        return False
+
+    js_file_list = get_js_files(file_list)
+
+    has_errors = False
+    if file_list:
+        status = Popen([prettier_path, '--write', '--single-quote', '--bracket-spacing=false', '--print-width=90']
+                       + js_file_list).wait()
+        has_errors = status != 0
+
+    return has_errors
+
 def main():
     from flake8.hooks import run
 
@@ -31,6 +55,9 @@ def main():
         if os.path.exists(f)
     ]
 
+    # Prettier formatting must take place before linting
+    js_format(files_modified)
+
     return check_files(files_modified)
 
 

+ 3 - 25
src/sentry/lint/engine.py

@@ -68,7 +68,7 @@ def py_lint(file_list):
     return report.total_errors != 0
 
 
-def get_js_file_list(file_list=None):
+def get_js_files(file_list=None):
     if file_list is None:
         file_list = ['tests/js', 'src/sentry/static/sentry/app']
     file_list = get_files_for_list(file_list)
@@ -79,27 +79,6 @@ def get_js_file_list(file_list=None):
     return file_list
 
 
-def js_beautify(file_list=None):
-    project_root = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
-                                os.pardir)
-    prettier_path = os.path.join(project_root, 'node_modules', '.bin', 'prettier')
-
-    if not os.path.exists(prettier_path):
-        from click import echo
-        echo('!! Skipping JavaScript beautification because eslint is not installed.')
-        return False
-
-    file_list = get_js_file_list(file_list)
-
-    has_errors = False
-    if file_list:
-        status = Popen([prettier_path, '--write', '--single-quote', '--bracket-spacing=false', '--print-width=90']
-                       + file_list).wait()
-        has_errors = status != 0
-
-    return has_errors
-
-
 def js_lint(file_list=None):
 
     project_root = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
@@ -112,12 +91,12 @@ def js_lint(file_list=None):
         return False
 
     eslint_config = os.path.join(project_root, '.eslintrc')
-    file_list = get_js_file_list(file_list)
+    js_file_list = get_js_files(file_list)
 
     has_errors = False
     if file_list:
         status = Popen([eslint_path, '--config', eslint_config, '--ext', '.jsx', '--fix']
-                       + file_list).wait()
+                       + js_file_list).wait()
         has_errors = status != 0
 
     return has_errors
@@ -134,7 +113,6 @@ def check_files(file_list=None, js=True, py=True):
     if py:
         linters.append(py_lint(file_list))
     if js:
-        linters.append(js_beautify(file_list))
         linters.append(js_lint(file_list))
 
     try: