Commit 981bb48d authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[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: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Auto-Submit: Sathya Gunasekaran  <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71076}
parent a9252d70
......@@ -99,7 +99,7 @@ def _V8PresubmitChecks(input_api, output_api):
def FilterJSFile(affected_file):
return input_api.FilterSourceFile(
affected_file,
white_list=(r'.+\.m?js'))
files_to_check=(r'.+\.m?js'))
results = []
if not CppLintProcessor().RunOnFiles(
......
......@@ -132,29 +132,37 @@ def TorqueLintWorker(command):
process.kill()
def JSLintWorker(command):
try:
file_name = command[-1]
with open(file_name, "r") as file_handle:
contents = file_handle.read()
def format_file(command):
try:
file_name = command[-1]
with open(file_name, "r") as file_handle:
contents = file_handle.read()
process = subprocess.Popen(command, stdout=PIPE, stderr=subprocess.PIPE)
output, err = process.communicate()
rc = process.returncode
if rc != 0:
sys.stdout.write("error code " + str(rc) + " running clang-format.\n")
return rc
process = subprocess.Popen(command, stdout=PIPE, stderr=subprocess.PIPE)
output, err = process.communicate()
rc = process.returncode
if rc != 0:
sys.stdout.write("error code " + str(rc) + " running clang-format.\n")
return rc
if output != contents:
sys.stdout.write(file_name + " requires formatting.\n")
return 1
if output != contents:
return 1
return 0
except KeyboardInterrupt:
process.kill()
except Exception:
print('Error running clang-format. Please make sure you have depot_tools' +
' in your $PATH. Lint check skipped.')
process.kill()
return 0
except KeyboardInterrupt:
process.kill()
except Exception:
print('Error running clang-format. Please make sure you have depot_tools' +
' in your $PATH. Lint check skipped.')
process.kill()
rc = format_file(command)
if rc == 1:
# There are files that need to be formatted, let's format them in place.
file_name = command[-1]
sys.stdout.write("Formatting %s.\n" % (file_name))
rc = format_file(command[:-1] + ["-i", file_name])
return rc
class FileContentsCache(object):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment