Fix breaking changes introduced by Eslint v7

Change-Id: I84c3f4c333e9bbe0087738746e879494b90445f1
This commit is contained in:
Dmitrii Filippov
2020-12-22 17:38:50 +01:00
parent 624a4765f0
commit 3b3d3ab64e
3 changed files with 34 additions and 2 deletions

View File

@@ -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
View 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);
}

View File

@@ -57,9 +57,11 @@ def eslint(name, plugins, srcs, config, ignore, extensions = [".js"], data = [])
config,
ignore,
"//tools/js/eslint-rules:eslint-rules-srcs",
"//tools/js:eslint-chdir.js",
eslint_rules_toplevel_file,
] + plugins + data
common_templated_args = [
"--node_options=--require=$$(rlocation $(rootpath //tools/js:eslint-chdir.js))",
"--ext",
",".join(extensions),
"-c",
@@ -85,7 +87,7 @@ def eslint(name, plugins, srcs, config, ignore, extensions = [".js"], data = [])
"*_test_require_patch.js",
"--ignore-pattern",
"*_test_loader.js",
native.package_name(),
"./", # Relative to the config file location
],
# Should not run sandboxed.
tags = [