Browse Source

ci: Add lint results to Zeus

David Cramer 7 years ago
parent
commit
3b4d153e39
4 changed files with 44 additions and 25 deletions
  1. 5 1
      .travis.yml
  2. 2 2
      Makefile
  3. 24 15
      bin/lint
  4. 13 7
      src/sentry/lint/engine.py

+ 5 - 1
.travis.yml

@@ -43,12 +43,16 @@ after_success:
   - zeus upload -t "text/xml+xunit" junit.xml
   - zeus upload -t "text/xml+coverage" coverage.xml
   - zeus upload -t "text/html+pytest" pytest.html
+  - zeus upload -t "text/plain+pycodestyle" flake8.pycodestyle.log
+  - zeus upload -t "text/xml+checkstyle" eslint.checkstyle.xml
 after_failure:
-  - dmesg | tail -n 100
+  - codecov -e TEST_SUITE
   - npm install -g @zeus-ci/cli
   - zeus upload -t "text/xml+xunit" junit.xml
   - zeus upload -t "text/xml+coverage" coverage.xml
   - zeus upload -t "text/html+pytest" pytest.html
+  - zeus upload -t "text/plain+pycodestyle" flake8.pycodestyle.log
+  - zeus upload -t "text/xml+checkstyle" eslint.checkstyle.xml
 # each attribute in the matrix will override the global attribute
 matrix:
   fast_finish: true

+ 2 - 2
Makefile

@@ -163,12 +163,12 @@ lint: lint-python lint-js
 
 lint-python:
 	@echo "--> Linting python"
-	bin/lint --python
+	bin/lint --python --parseable | tee flake8.pycodestyle.log
 	@echo ""
 
 lint-js:
 	@echo "--> Linting javascript"
-	bin/lint --js
+	bin/lint --js --parseable | tee eslint.codestyle.xml
 	@echo ""
 
 coverage: develop

+ 24 - 15
bin/lint

@@ -1,29 +1,38 @@
 #!/usr/bin/env python
 from __future__ import absolute_import
 
+import click
 import os
 import sys
 
 # This is to avoid needing to have the `sentry` package explicitly installed.
 sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, 'src'))
 
-from sentry.lint.engine import run
 
-offset = 1
-js = True
-py = True
+@click.command()
+@click.argument('files', nargs=-1)
+@click.option('--js', default=None, is_flag=True)
+@click.option('--python', default=None, is_flag=True)
+@click.option('--format', default=False, is_flag=True)
+@click.option('--parseable', default=False, is_flag=True)
+def run(files, js, python, format, parseable):
+    from sentry.lint import engine
 
-# Allow passing a flag for --js or --python only
-if len(sys.argv) > 1:
-    if sys.argv[1] == '--js':
-        offset = 2
-        py = False
-    elif sys.argv[1] == '--python':
-        offset = 2
+    if js and not python:
+        python = False
+    elif python and not js:
         js = False
+    else:
+        js = True
+        python = True
 
-file_list = sys.argv[offset:]
-if not file_list:
-    file_list = None
+    if not files:
+        files = None
 
-sys.exit(run(file_list, js=js, py=py, format=False))
+    results = engine.run(files, js=js, py=python, format=format, parseable=parseable)
+    if results:
+        raise click.Abort
+
+
+if __name__ == '__main__':
+    run()

+ 13 - 7
src/sentry/lint/engine.py

@@ -103,7 +103,8 @@ def get_python_files(file_list=None):
     ]
 
 
-def py_lint(file_list):
+# parseable is a no-op
+def py_lint(file_list, parseable=False):
     from flake8.engine import get_style_guide
 
     file_list = get_python_files(file_list)
@@ -113,7 +114,7 @@ def py_lint(file_list):
     return report.total_errors != 0
 
 
-def js_lint(file_list=None):
+def js_lint(file_list=None, parseable=False, format=False):
 
     project_root = get_project_root()
     eslint_path = get_node_modules_bin('eslint')
@@ -128,8 +129,12 @@ def js_lint(file_list=None):
 
     has_errors = False
     if js_file_list:
-        status = Popen([eslint_path, '--config', eslint_config, '--ext', '.jsx', '--fix']
-                       + js_file_list).wait()
+        cmd = [eslint_path, '--config', eslint_config, '--ext', '.jsx']
+        if format:
+            cmd.append('--fix')
+        if parseable:
+            cmd.append('--format=checkstyle')
+        status = Popen(cmd + js_file_list).wait()
         has_errors = status != 0
 
     return has_errors
@@ -297,7 +302,8 @@ def run_formatter(cmd, file_list, prompt_on_changes=True):
     return has_errors
 
 
-def run(file_list=None, format=True, lint=True, js=True, py=True, less=True, yarn=True, test=False):
+def run(file_list=None, format=True, lint=True, js=True, py=True,
+        less=True, yarn=True, test=False, parseable=False):
     # pep8.py uses sys.argv to find setup.cfg
     old_sysargv = sys.argv
 
@@ -330,9 +336,9 @@ def run(file_list=None, format=True, lint=True, js=True, py=True, less=True, yar
 
         if lint:
             if py:
-                results.append(py_lint(file_list))
+                results.append(py_lint(file_list, parseable=True))
             if js:
-                results.append(js_lint(file_list))
+                results.append(js_lint(file_list, parseable=True, format=format))
 
         if test:
             if js: