Fix breaking changes introduced by Eslint v7
Change-Id: I84c3f4c333e9bbe0087738746e879494b90445f1
This commit is contained in:
@@ -1 +1 @@
|
|||||||
exports_files(["run_npm_binary.py"])
|
exports_files(["run_npm_binary.py", "eslint-chdir.js"])
|
||||||
|
|||||||
30
tools/js/eslint-chdir.js
Normal file
30
tools/js/eslint-chdir.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Eslint 7 introduced a breaking change - it uses the current workdir instead
|
||||||
|
// of the configuration file directory for resolving relative paths:
|
||||||
|
// https://eslint.org/docs/user-guide/migrating-to-7.0.0#base-path-change
|
||||||
|
// This file is loaded before the eslint and sets the current directory
|
||||||
|
// back to the location of configuration file.
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const configParamIndex =
|
||||||
|
process.argv.findIndex(arg => arg === '-c' || arg === '---config');
|
||||||
|
if (configParamIndex >= 0 && configParamIndex + 1 < process.argv.length) {
|
||||||
|
const dirName = path.dirname(process.argv[configParamIndex + 1]);
|
||||||
|
process.chdir(dirName);
|
||||||
|
}
|
||||||
@@ -57,9 +57,11 @@ def eslint(name, plugins, srcs, config, ignore, extensions = [".js"], data = [])
|
|||||||
config,
|
config,
|
||||||
ignore,
|
ignore,
|
||||||
"//tools/js/eslint-rules:eslint-rules-srcs",
|
"//tools/js/eslint-rules:eslint-rules-srcs",
|
||||||
|
"//tools/js:eslint-chdir.js",
|
||||||
eslint_rules_toplevel_file,
|
eslint_rules_toplevel_file,
|
||||||
] + plugins + data
|
] + plugins + data
|
||||||
common_templated_args = [
|
common_templated_args = [
|
||||||
|
"--node_options=--require=$$(rlocation $(rootpath //tools/js:eslint-chdir.js))",
|
||||||
"--ext",
|
"--ext",
|
||||||
",".join(extensions),
|
",".join(extensions),
|
||||||
"-c",
|
"-c",
|
||||||
@@ -85,7 +87,7 @@ def eslint(name, plugins, srcs, config, ignore, extensions = [".js"], data = [])
|
|||||||
"*_test_require_patch.js",
|
"*_test_require_patch.js",
|
||||||
"--ignore-pattern",
|
"--ignore-pattern",
|
||||||
"*_test_loader.js",
|
"*_test_loader.js",
|
||||||
native.package_name(),
|
"./", # Relative to the config file location
|
||||||
],
|
],
|
||||||
# Should not run sandboxed.
|
# Should not run sandboxed.
|
||||||
tags = [
|
tags = [
|
||||||
|
|||||||
Reference in New Issue
Block a user