Commit b1c91dc3 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Update ios/chrome/browser/web/resources/PRESUBMIT.py formatted JS check.

Update the presubmit check to use clang-format instead of gjslint
which is deprecated.

Bug: None
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I13b58f6d3c72a67fc58ee52c351a196b68953742
Reviewed-on: https://chromium-review.googlesource.com/c/1261720
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596761}
parent f4a839a2
......@@ -2,85 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Makes sure that injected JavaScript is gjslint clean."""
# Regular expression patterns for JavaScript source files.
INCLUDE_JS_FILES_ONLY = (
r'.*\.js$',
)
# List of standard locations where gjslint may be installed.
GJSLINT_PATHS = (
'/usr/local/bin/gjslint',
'/usr/bin/gjslint',
)
def CheckChangeJsLintsClean(input_api, output_api):
"""Checks for JavaScript lint errors."""
# Gets the list of modified files.
source_file_filter = lambda x: input_api.FilterSourceFile(
x, white_list=INCLUDE_JS_FILES_ONLY)
files = [f.AbsoluteLocalPath()
for f in input_api.AffectedSourceFiles(source_file_filter)]
results = []
# Run gjslint only if there are JavaScript files changed.
if files:
# Finds out where gjslint is installed, and warns user
# gently about this missing utility. Then treats it as
# if there are no JavaScript lint errors.
gjslint_path = None
for path in GJSLINT_PATHS:
if input_api.os_path.exists(path):
gjslint_path = path
break
if not gjslint_path:
# Early return if gjslint is not available.
return [ output_api.PresubmitNotifyResult(
'** WARNING ** gjslint is not installed in your environment.',
GJSLINT_PATHS,
('Please see http://code.google.com/'
'closure/utilities/docs/linter_howto.html '
'for installation instructions.\n'
'You are strongly encouraged to install gjslint '
'because a kitten dies every time you submit code '
'without gjslint :)')) ]
# Found gjslint, run it over modified JavaScript files.
for file_name in files:
lint_error = RunJsLint(input_api, output_api, gjslint_path, file_name)
if lint_error is not None:
results.append(lint_error)
return results
def RunJsLint(input_api, output_api, gjslint_path, file_name):
"""Runs gjslint on a file.
Returns: None if there are no lint errors, or an object of type
output_api.Presubmit{Error,PromptWarning} if lint errors are found.
"""
# Do not hinder users from uploading incomplete patches.
if input_api.is_committing:
message_type = output_api.PresubmitError
else:
message_type = output_api.PresubmitPromptWarning
result = None
cmd = [ gjslint_path, file_name ];
try:
if input_api.verbose:
input_api.subprocess.check_call(cmd, cwd=input_api.PresubmitLocalPath())
else:
input_api.subprocess.check_output(
cmd,
stderr=input_api.subprocess.STDOUT,
cwd=input_api.PresubmitLocalPath())
except (OSError, input_api.subprocess.CalledProcessError), e:
result = message_type('%s failed.\n%s' % (' '.join(cmd), e))
return result
"""Makes sure that injected JavaScript is clang-format clean."""
def CheckChangeOnUpload(input_api, output_api):
"""Special Top level function called by git_cl."""
return CheckChangeJsLintsClean(input_api, output_api)
return input_api.canned_checks.CheckPatchFormatted(
input_api, output_api, check_js=True)
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