Files
react-native-devtools-frontend/scripts/test/run_lint_check.py
T
Tim van der Lippe 399a956776 Reland "Use typescript-eslint instead of tslint"
This reverts commit 72da1a51cb.

Reason for revert: Buildbots in Chromium no longer run the linter checks.

Original change's description:
> Revert "Use typescript-eslint instead of tslint"
> 
> This reverts commit d0e22da4db.
> 
> Reason for revert: https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8891272266464063200/+/steps/devtools_lint_check__with_patch_/0/stdout
> 
> Original change's description:
> > Use typescript-eslint instead of tslint
> >
> > This will update our eslint configuration to use @typescript-eslint to
> > parse and lint TypeScript files. It integrates with the existing
> > infrastructure to lint our files
> >
> > Fixed: 1041811
> > Change-Id: I29f49a57229e3ee17524045b3905b9cc835271ab
> > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1998771
> > Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
> > Reviewed-by: Paul Lewis <aerotwist@chromium.org>
> 
> TBR=aerotwist@chromium.org,tvanderlippe@chromium.org
> 
> Change-Id: Ic0dfc585cd0ac08f1f4a72ce19d0bebc74f9cdb5
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2000795
> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>

TBR=aerotwist@chromium.org,tvanderlippe@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I623c9b873ac0af3157ff3b73c91e006f7db58e1e
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2003315
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2020-01-16 10:58:49 +00:00

100 lines
2.7 KiB
Python
Executable File

#!/usr/bin/env python
#
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os.path as path
import re
import subprocess
import sys
scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
sys.path.append(scripts_path)
import devtools_paths
files_to_lint = None
if len(sys.argv) >= 2:
if sys.argv[1] == '--help':
print('Usage: %s [file|dir|glob]*' % path.basename(sys.argv[0]))
print
print(' [file|dir|glob]* Path or glob to run eslint on.')
print(' If absent, the entire frontend will be checked.')
sys.exit(0)
else:
print('Linting only these files:\n %s' % sys.argv[1:])
files_to_lint = sys.argv[1:]
is_cygwin = sys.platform == 'cygwin'
def popen(arguments, cwd=None):
return subprocess.Popen(arguments, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def to_platform_path(filepath):
if not is_cygwin:
return filepath
return re.sub(r'^/cygdrive/(\w)', '\\1:', filepath)
def to_platform_path_exact(filepath):
if not is_cygwin:
return filepath
output, _ = popen(['cygpath', '-w', filepath]).communicate()
# pylint: disable=E1103
return output.strip().replace('\\', '\\\\')
devtools_path = devtools_paths.devtools_root_path()
devtools_frontend_path = path.join(devtools_path, 'front_end')
unittests_path = path.join(devtools_path, 'test', 'unittests')
print('Linting JavaScript with eslint...\n')
def js_lint(files_list=None):
eslint_errors_found = False
if files_list is None:
files_list = [devtools_frontend_path, unittests_path]
files_list = [file_name for file_name in files_list if not file_name.endswith('.eslintrc.js')]
eslintconfig_path = path.join(devtools_path, '.eslintrc.js')
eslintignore_path = path.join(devtools_path, '.eslintignore')
exec_command = [
devtools_paths.node_path(),
devtools_paths.eslint_path(),
'--config',
to_platform_path_exact(eslintconfig_path),
'--ignore-path',
to_platform_path_exact(eslintignore_path),
'--ext',
'.js,.ts',
'--fix',
] + files_list
eslint_proc = popen(exec_command, cwd=devtools_path)
(eslint_proc_out, _) = eslint_proc.communicate()
if eslint_proc.returncode != 0:
eslint_errors_found = True
else:
print('eslint exited successfully')
print(eslint_proc_out)
return eslint_errors_found
def main():
errors_found = js_lint(files_to_lint)
if errors_found:
print('ERRORS DETECTED')
sys.exit(1)
if __name__ == '__main__':
main()