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

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

Issue 1992383002: DevTools: add eslint as presubmit hook (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
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 7 import os
8 import os.path as path 8 import os.path as path
9 import re 9 import re
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 12
13 files_to_lint = None 13 files_to_lint = None
14 14
15 if len(sys.argv) == 2: 15 if len(sys.argv) >= 2:
16 if sys.argv[1] == "--help": 16 if sys.argv[1] == "--help":
17 print("Usage: %s [file|dir|glob]*" % path.basename(sys.argv[0])) 17 print("Usage: %s [file|dir|glob]*" % path.basename(sys.argv[0]))
18 print 18 print
19 print(" [file|dir|glob]* Path or glob to run eslint on.") 19 print(" [file|dir|glob]* Path or glob to run eslint on.")
20 print(" If absent, the entire frontend will be checked .") 20 print(" If absent, the entire frontend will be checked .")
21 sys.exit(0) 21 sys.exit(0)
22 22
23 else: 23 else:
24 print "Linting only this path:\n %s" % sys.argv[1:] 24 print("Linting only these files:\n %s" % sys.argv[1:])
25 files_to_lint = sys.argv[1:] 25 files_to_lint = sys.argv[1:]
26 26
27 27
28 is_cygwin = sys.platform == "cygwin" 28 is_cygwin = sys.platform == "cygwin"
29 29
30 30
31 def popen(arguments): 31 def popen(arguments):
32 return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess .STDOUT) 32 return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess .STDOUT)
33 33
34 34
(...skipping 26 matching lines...) Expand all
61 return program 61 return program
62 else: 62 else:
63 for part in os.environ["PATH"].split(os.pathsep): 63 for part in os.environ["PATH"].split(os.pathsep):
64 part = part.strip("\"") 64 part = part.strip("\"")
65 exe_file = path.join(part, program) 65 exe_file = path.join(part, program)
66 if is_exe(exe_file): 66 if is_exe(exe_file):
67 return exe_file 67 return exe_file
68 return None 68 return None
69 69
70 70
71 print "Linting JavaScript with eslint...\n" 71 print("Linting JavaScript with eslint...\n")
72 72
73 73
74 def js_lint(files_list=None): 74 def js_lint(files_list=None):
75 eslint_errors_found = False 75 eslint_errors_found = False
76 76
77 eslint_path = which("eslint") 77 eslint_path = which("eslint")
78 if not eslint_path: 78 if not eslint_path:
79 print "!! Skipping JavaScript linting because eslint is not installed." 79 print("!! NOTE: Skipping JavaScript linting because eslint is not instal led.")
80 print "!! npm install -g eslint" 80 print("!! npm install -g eslint")
81 eslint_errors_found = False # Linting is opt-in for now, so this is a s oft failure 81 eslint_errors_found = False # Linting is opt-in for now, so this is a s oft failure
82 return eslint_errors_found 82 return eslint_errors_found
83 83
84 if files_list is None: 84 if files_list is None:
85 files_list = [devtools_frontend_path] 85 files_list = [devtools_frontend_path]
86 files_list = [file_name for file_name in files_list if not file_name.endswit h(".eslintrc.js")]
86 87
87 eslintconfig_path = path.join(devtools_path, "front_end/.eslintrc.js") 88 eslintconfig_path = path.join(devtools_path, "front_end/.eslintrc.js")
88 eslintignore_path = path.join(devtools_path, "front_end/.eslintignore") 89 eslintignore_path = path.join(devtools_path, "front_end/.eslintignore")
89 exec_command = [ 90 exec_command = [
90 eslint_path, 91 eslint_path,
91 "--config", to_platform_path_exact(eslintconfig_path), 92 "--config", to_platform_path_exact(eslintconfig_path),
92 "--ignore-path", to_platform_path_exact(eslintignore_path), 93 "--ignore-path", to_platform_path_exact(eslintignore_path),
93 " ".join(files_list) 94 ] + files_list
94 ]
95 95
96 eslint_proc = popen(exec_command) 96 eslint_proc = popen(exec_command)
97 (eslint_proc_out, _) = eslint_proc.communicate() 97 (eslint_proc_out, _) = eslint_proc.communicate()
98 if eslint_proc.returncode != 0: 98 if eslint_proc.returncode != 0:
99 eslint_errors_found = True 99 eslint_errors_found = True
100 else: 100 else:
101 print "eslint exited successfully" 101 print("eslint exited successfully")
102 102
103 print eslint_proc_out 103 print(eslint_proc_out)
104 return eslint_errors_found
paulirish 2016/05/20 20:26:22 Thanks. Not sure why it was missing.
lushnikov 2016/05/20 20:54:56 Acknowledged.
104 105
105 106
106 errors_found = js_lint(files_to_lint) 107 errors_found = js_lint(files_to_lint)
107 108
108 if errors_found: 109 if errors_found:
109 print "ERRORS DETECTED" 110 print("ERRORS DETECTED")
110 sys.exit(1) 111 sys.exit(1)
111 else: 112 else:
112 print "OK" 113 print("OK")
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698