mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 01:07:01 +08:00
The new devtools_paths.py detects whether the frontend code is hosted in the Chromium repository, in an external repository during standalone build, or in an external repository during integrated build. R=aerotwist@chromium.org Change-Id: I800ab63f985d203359e387f9c81df9270929b437 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1839791 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#703014} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: dd36b0f6b3fdbaa069facb239773596ae816febb
91 lines
2.4 KiB
Python
Executable File
91 lines
2.4 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
|
|
|
|
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("\\", "\\\\")
|
|
|
|
|
|
scripts_path = path.dirname(path.abspath(__file__))
|
|
devtools_path = path.dirname(scripts_path)
|
|
devtools_frontend_path = path.join(devtools_path, "front_end")
|
|
|
|
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]
|
|
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),
|
|
"--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
|
|
|
|
|
|
errors_found = js_lint(files_to_lint)
|
|
|
|
if errors_found:
|
|
print("ERRORS DETECTED")
|
|
sys.exit(1)
|