Skip to content

Commit 981bb48

Browse files
gsathyaCommit Bot
authored andcommitted
[tools] Format JS files in system-analyzer/ if they're unformatted
Instead of just warning, let's try to format the files as well Bug: v8:10670 Change-Id: I0dfbdc0ed4a96af7f2a2a472f1d0d3d332d39c90 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2523193 Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Camillo Bruni <cbruni@chromium.org> Reviewed-by: Michael Achenbach <machenbach@chromium.org> Auto-Submit: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#71076}
1 parent a9252d7 commit 981bb48

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

PRESUBMIT.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def FilterTorqueFile(affected_file):
9999
def FilterJSFile(affected_file):
100100
return input_api.FilterSourceFile(
101101
affected_file,
102-
white_list=(r'.+\.m?js'))
102+
files_to_check=(r'.+\.m?js'))
103103

104104
results = []
105105
if not CppLintProcessor().RunOnFiles(

tools/v8_presubmit.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,37 @@ def TorqueLintWorker(command):
132132
process.kill()
133133

134134
def JSLintWorker(command):
135-
try:
136-
file_name = command[-1]
137-
with open(file_name, "r") as file_handle:
138-
contents = file_handle.read()
135+
def format_file(command):
136+
try:
137+
file_name = command[-1]
138+
with open(file_name, "r") as file_handle:
139+
contents = file_handle.read()
139140

140-
process = subprocess.Popen(command, stdout=PIPE, stderr=subprocess.PIPE)
141-
output, err = process.communicate()
142-
rc = process.returncode
143-
if rc != 0:
144-
sys.stdout.write("error code " + str(rc) + " running clang-format.\n")
145-
return rc
141+
process = subprocess.Popen(command, stdout=PIPE, stderr=subprocess.PIPE)
142+
output, err = process.communicate()
143+
rc = process.returncode
144+
if rc != 0:
145+
sys.stdout.write("error code " + str(rc) + " running clang-format.\n")
146+
return rc
146147

147-
if output != contents:
148-
sys.stdout.write(file_name + " requires formatting.\n")
149-
return 1
148+
if output != contents:
149+
return 1
150150

151-
return 0
152-
except KeyboardInterrupt:
153-
process.kill()
154-
except Exception:
155-
print('Error running clang-format. Please make sure you have depot_tools' +
156-
' in your $PATH. Lint check skipped.')
157-
process.kill()
151+
return 0
152+
except KeyboardInterrupt:
153+
process.kill()
154+
except Exception:
155+
print('Error running clang-format. Please make sure you have depot_tools' +
156+
' in your $PATH. Lint check skipped.')
157+
process.kill()
158+
159+
rc = format_file(command)
160+
if rc == 1:
161+
# There are files that need to be formatted, let's format them in place.
162+
file_name = command[-1]
163+
sys.stdout.write("Formatting %s.\n" % (file_name))
164+
rc = format_file(command[:-1] + ["-i", file_name])
165+
return rc
158166

159167
class FileContentsCache(object):
160168

0 commit comments

Comments
 (0)