Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/lint_javascript.py

Issue 1907353005: DevTools: Add lint_javascript.py to drive eslint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: closure of errors_found n all that Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/.eslintignore ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6
7 import os
8 import os.path as path
9 import re
10 import subprocess
11 import sys
12
13 files_to_lint = None
14
15 if len(sys.argv) == 2:
16 if sys.argv[1] == "--help":
17 print("Usage: %s [file|dir|glob]*" % path.basename(sys.argv[0]))
18 print
19 print(" [file|dir|glob]* Path or glob to run eslint on.")
20 print(" If absent, the entire frontend will be checked .")
21 sys.exit(0)
22
23 else:
24 print "Linting only this path:\n %s" % sys.argv[1:]
25 files_to_lint = sys.argv[1:]
26
27
28 is_cygwin = sys.platform == "cygwin"
29
30
31 def popen(arguments):
32 return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess .STDOUT)
33
34
35 def to_platform_path(filepath):
36 if not is_cygwin:
37 return filepath
38 return re.sub(r"^/cygdrive/(\w)", "\\1:", filepath)
39
40
41 def to_platform_path_exact(filepath):
42 if not is_cygwin:
43 return filepath
44 output, _ = popen(["cygpath", "-w", filepath]).communicate()
45 # pylint: disable=E1103
46 return output.strip().replace("\\", "\\\\")
47
48 scripts_path = path.dirname(path.abspath(__file__))
49 devtools_path = path.dirname(scripts_path)
50 devtools_frontend_path = path.join(devtools_path, "front_end")
51
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
71 print "Linting JavaScript with eslint...\n"
72
73
74 def js_lint(files_list=None):
75 eslint_errors_found = False
76
77 eslint_path = which("eslint")
78 if not eslint_path:
79 print "!! Skipping JavaScript linting because eslint is not installed."
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
83
84 if files_list is None:
85 files_list = [devtools_frontend_path]
86
87 eslintconfig_path = path.join(devtools_path, "front_end/.eslintrc.js")
88 eslintignore_path = path.join(devtools_path, "front_end/.eslintignore")
89 exec_command = [
90 eslint_path,
91 "--config", to_platform_path_exact(eslintconfig_path),
92 "--ignore-path", to_platform_path_exact(eslintignore_path),
93 " ".join(files_list)
94 ]
95
96 eslint_proc = popen(exec_command)
97 (eslint_proc_out, _) = eslint_proc.communicate()
98 if eslint_proc.returncode != 0:
99 eslint_errors_found = True
100 else:
101 print "eslint exited successfully"
102
103 print eslint_proc_out
104
105
106 errors_found = js_lint(files_to_lint)
107
108 if errors_found:
109 print "ERRORS DETECTED"
110 sys.exit(1)
111 else:
112 print "OK"
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/.eslintignore ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698