Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import os | |
| 8 import os.path as path | 7 import os.path as path |
| 9 import re | 8 import re |
| 10 import subprocess | 9 import subprocess |
| 11 import sys | 10 import sys |
| 12 | 11 |
| 13 files_to_lint = None | 12 files_to_lint = None |
| 14 | 13 |
| 15 if len(sys.argv) >= 2: | 14 if len(sys.argv) >= 2: |
| 16 if sys.argv[1] == "--help": | 15 if sys.argv[1] == "--help": |
| 17 print("Usage: %s [file|dir|glob]*" % path.basename(sys.argv[0])) | 16 print("Usage: %s [file|dir|glob]*" % path.basename(sys.argv[0])) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 41 def to_platform_path_exact(filepath): | 40 def to_platform_path_exact(filepath): |
| 42 if not is_cygwin: | 41 if not is_cygwin: |
| 43 return filepath | 42 return filepath |
| 44 output, _ = popen(["cygpath", "-w", filepath]).communicate() | 43 output, _ = popen(["cygpath", "-w", filepath]).communicate() |
| 45 # pylint: disable=E1103 | 44 # pylint: disable=E1103 |
| 46 return output.strip().replace("\\", "\\\\") | 45 return output.strip().replace("\\", "\\\\") |
| 47 | 46 |
| 48 scripts_path = path.dirname(path.abspath(__file__)) | 47 scripts_path = path.dirname(path.abspath(__file__)) |
| 49 devtools_path = path.dirname(scripts_path) | 48 devtools_path = path.dirname(scripts_path) |
| 50 devtools_frontend_path = path.join(devtools_path, "front_end") | 49 devtools_frontend_path = path.join(devtools_path, "front_end") |
| 51 | 50 eslint_path = path.join(devtools_path, "node_modules", ".bin", "eslint") |
| 52 | |
| 53 # Based on http://stackoverflow.com/questions/377017/test-if-executable-exists-i n-python. | |
| 54 def which(program): | |
| 55 def is_exe(fpath): | |
| 56 return path.isfile(fpath) and os.access(fpath, os.X_OK) | |
| 57 | |
| 58 fpath, fname = path.split(program) | |
| 59 if fpath: | |
| 60 if is_exe(program): | |
| 61 return program | |
| 62 else: | |
| 63 for part in os.environ["PATH"].split(os.pathsep): | |
| 64 part = part.strip("\"") | |
| 65 exe_file = path.join(part, program) | |
| 66 if is_exe(exe_file): | |
| 67 return exe_file | |
| 68 return None | |
| 69 | |
| 70 | 51 |
| 71 print("Linting JavaScript with eslint...\n") | 52 print("Linting JavaScript with eslint...\n") |
| 72 | 53 |
| 73 | 54 |
| 74 def js_lint(files_list=None): | 55 def js_lint(files_list=None): |
| 75 eslint_errors_found = False | 56 eslint_errors_found = False |
| 76 | 57 if not path.isfile(eslint_path): |
| 77 eslint_path = which("eslint") | 58 print("!! NOTE: Javascript linting is mandatory") |
|
dgozman
2016/09/14 16:37:41
Replace this with "Failed to run eslint, run ./scr
chenwilliam
2016/09/15 00:40:11
Done.
| |
| 78 if not eslint_path: | 59 print("!! Run ./scripts/node.py to install eslint") |
| 79 print("!! NOTE: Skipping JavaScript linting because eslint is not instal led.") | 60 eslint_errors_found = True |
| 80 print("!! npm install -g eslint") | |
| 81 eslint_errors_found = False # Linting is opt-in for now, so this is a s oft failure | |
| 82 return eslint_errors_found | 61 return eslint_errors_found |
| 83 | 62 |
| 84 if files_list is None: | 63 if files_list is None: |
| 85 files_list = [devtools_frontend_path] | 64 files_list = [devtools_frontend_path] |
| 86 files_list = [file_name for file_name in files_list if not file_name.endswit h(".eslintrc.js")] | 65 files_list = [file_name for file_name in files_list if not file_name.endswit h(".eslintrc.js")] |
| 87 | 66 |
| 88 eslintconfig_path = path.join(devtools_path, "front_end/.eslintrc.js") | 67 eslintconfig_path = path.join(devtools_path, "front_end/.eslintrc.js") |
| 89 eslintignore_path = path.join(devtools_path, "front_end/.eslintignore") | 68 eslintignore_path = path.join(devtools_path, "front_end/.eslintignore") |
| 90 exec_command = [ | 69 exec_command = [ |
| 91 eslint_path, | 70 eslint_path, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 104 return eslint_errors_found | 83 return eslint_errors_found |
| 105 | 84 |
| 106 | 85 |
| 107 errors_found = js_lint(files_to_lint) | 86 errors_found = js_lint(files_to_lint) |
| 108 | 87 |
| 109 if errors_found: | 88 if errors_found: |
| 110 print("ERRORS DETECTED") | 89 print("ERRORS DETECTED") |
| 111 sys.exit(1) | 90 sys.exit(1) |
| 112 else: | 91 else: |
| 113 print("OK") | 92 print("OK") |
| OLD | NEW |