Revert "[cleanup] Remove dead code"

This reverts commit 26bc275ce1.

Reason for revert: used in devtools-internal so breaks the roll

Original change's description:
> [cleanup] Remove dead code
>
> The infra now all uses `npm run lint` for linting.
> Moves a common function to the only place it's used.
>
> Bug: none
> Change-Id: Ibcf86daa95e33d8b313efe76a6173436769786d5
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6070376
> Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
> Auto-Submit: Nikolay Vitkov <nvitkov@chromium.org>
> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>

Bug: none
Change-Id: I090c1750ec1ada53df22c443253922162f41e271
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6072803
Reviewed-by: Simon Zünd <szuend@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
Alex Rudenko
2024-12-05 07:06:18 +00:00
committed by Devtools-frontend LUCI CQ
parent 8c4fd43555
commit 789751e321
8 changed files with 254 additions and 14 deletions
+4 -1
View File
@@ -7,5 +7,8 @@ import("../build/ninja/copy.gni")
copy_to_gen("component_server") {
sources = [ "server.js" ]
deps = [ "../../front_end/ui/legacy:copy_stylesheets_for_server" ]
deps = [
"../../front_end/ui/legacy:copy_stylesheets_for_server",
"../test",
]
}
+2 -13
View File
@@ -8,22 +8,11 @@ const path = require('path');
const parseURL = require('url').parse;
const {argv} = require('yargs');
const {getTestRunnerConfigSetting} = require('../test/test_config_helpers.js');
const tracesMode = argv.traces || false;
const serverPort = parseInt(process.env.PORT, 10) || (tracesMode ? 11010 : 8090);
function getTestRunnerConfig() {
try {
return JSON.parse(process.env.TEST_RUNNER_JSON_CONFIG);
} catch {
// Return an empty object so any lookups return undefined
return {};
}
}
function getTestRunnerConfigSetting(settingKey, fallbackValue) {
const config = getTestRunnerConfig();
return config[settingKey] === undefined ? fallbackValue : config[settingKey];
}
/**
* When you run npm run components-server we run the script as is from scripts/,
* but when this server is run as part of a test suite it's run from
+9
View File
@@ -0,0 +1,9 @@
# Copyright 2021 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("../build/ninja/copy.gni")
copy_to_gen("test") {
sources = [ "test_config_helpers.js" ]
}
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env vpython3
#
# 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.
# TODO(1083142): remove this file in favor of run_lint_check_js.py once
# infra has been updated.
import sys
from os import path
from subprocess import Popen
scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
sys.path.append(scripts_path)
import devtools_paths
CURRENT_DIRECTORY = path.dirname(path.abspath(__file__))
ROOT_DIRECTORY = path.normpath(path.join(CURRENT_DIRECTORY, '..', '..'))
def main():
exec_command = [
devtools_paths.node_path(),
path.join(CURRENT_DIRECTORY, 'run_lint_check_js.mjs'),
]
eslint_proc = Popen(exec_command, cwd=ROOT_DIRECTORY)
eslint_proc.communicate()
sys.exit(eslint_proc.returncode)
if __name__ == '__main__':
main()
+62
View File
@@ -0,0 +1,62 @@
// Copyright 2020 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.
const path = require('path');
const childProcess = require('child_process');
const {
devtoolsRootPath,
stylelintExecutablePath,
nodePath,
} = require('../devtools_paths.js');
const yargsObject = require('yargs')
.option('files', {type: 'array', desc: 'One or more files to lint.'})
.option('glob', {default: '**/*.css', desc: 'A glob to choose which files to lint.'})
.option('cwd', {default: devtoolsRootPath(), desc: 'Working directory to glob from'})
.parserConfiguration({
// So that if we pass --foo-bar, Yargs only populates
// argv with '--foo-bar', not '--foo-bar' and
// 'fooBar'. This is important because if we have both
// versions and pass them to stylelint, it errors
// saying that we've passed the same argument twice.
'camel-case-expansion': false
})
.argv;
// Note: stylelint requires POSIX-formatted paths/globs, even on Windows.
// The forward slash is not a bug.
const DEFAULT_GLOB = '**/*.css';
function getCSSFilesOrGlobList() {
const files = yargsObject.files || [];
if (files.length > 0) {
return files.map(file => {
// Enforce posix file paths even on Windows
return file.split(path.sep).join(path.posix.sep);
});
}
return [yargsObject.glob || DEFAULT_GLOB];
}
function run() {
// eslint-disable-next-line no-unused-vars
const {glob, files, cwd, _, $0, ...flagsForStylelint} = yargsObject;
const extraFlagsForStylelint = Object.keys(flagsForStylelint).flatMap(key => [`--${key}`, flagsForStylelint[key]]);
const args = [
stylelintExecutablePath(), ...getCSSFilesOrGlobList(), '--fix', '--allow-empty-input', ...extraFlagsForStylelint
];
const result = childProcess.spawnSync(nodePath(), args, {encoding: 'utf-8', cwd, stdio: 'inherit'});
if (result.error) {
// If spawnSync returns an error, exit with an error no matter what result.status says.
console.error(result.error);
process.exit(1);
return;
}
process.exit(result.status);
}
run();
+81
View File
@@ -0,0 +1,81 @@
// Copyright 2020 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.
// Use V8's code cache to speed up instantiation time.
await import('v8-compile-cache');
import path from 'path';
import {ESLint} from 'eslint';
import { fileURLToPath } from 'url';
import yargs from 'yargs';
// False positive from the ESLint rule: crbug.com/1319352
// eslint-disable-next-line rulesdir/es_modules_import
import {hideBin} from 'yargs/helpers';
const flags = yargs(hideBin(process.argv)).option('fix', {
type: 'boolean',
default: true,
describe: 'If to run ESLint in fix mode',
}).parse();
const shouldFix = flags.fix === true;
if(!shouldFix) {
console.log('[ESLint]: fix is disabled; no errors will be autofixed.');
}
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT_DIRECTORY = path.join(__dirname, '..', '..');
const FRONT_END_DIRECTORY = path.join(ROOT_DIRECTORY, 'front_end');
const INSPECTOR_OVERLAY_DIRECTORY = path.join(ROOT_DIRECTORY, 'inspector_overlay');
const TEST_DIRECTORY = path.join(ROOT_DIRECTORY, 'test');
const SCRIPTS_DIRECTORY = path.join(ROOT_DIRECTORY, 'scripts');
const DEFAULT_DIRECTORIES_TO_LINT =
[FRONT_END_DIRECTORY, INSPECTOR_OVERLAY_DIRECTORY, TEST_DIRECTORY, SCRIPTS_DIRECTORY];
const eslintignorePath = path.join(ROOT_DIRECTORY, '.eslintignore');
// Yargs gathers up any non-flag arguments into the `_` property.
// npm run check-lint-js foo => flags._ === ['foo']
let directoriesOrFilesToLint = flags._;
if (directoriesOrFilesToLint.length === 0) {
directoriesOrFilesToLint = DEFAULT_DIRECTORIES_TO_LINT;
}
const cli = new ESLint({
extensions: ['.js', '.ts'],
ignorePath: eslintignorePath,
fix: shouldFix,
});
// We filter out certain files in the `.eslintignore`. However, ESLint produces warnings
// when you include a particular file that is ignored. This means that if you edit a file
// that is directly ignored in the `.eslintignore`, ESLint would report a failure.
// This was originally reported in https://github.com/eslint/eslint/issues/9977
// The suggested workaround is to use the CLIEngine to pre-emptively filter out these
// problematic paths.
const filteredFilesToLint = [];
for (const path of directoriesOrFilesToLint) {
if (!(await cli.isPathIgnored(path))) {
filteredFilesToLint.push(path);
}
}
const results = await cli.lintFiles(filteredFilesToLint);
// Write fixes to the filesystem
if (shouldFix) {
await ESLint.outputFixes(results);
}
const formatter = await cli.loadFormatter('stylish');
console.log(formatter.format(results));
const hasProblems = results.find(report => report.errorCount + report.warningCount > 0);
process.exit(hasProblems ? 1 : 0);
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env vpython3
#
# 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 sys
from os import path
from subprocess import Popen
scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
sys.path.append(scripts_path)
import devtools_paths
CURRENT_DIRECTORY = path.dirname(path.abspath(__file__))
ROOT_DIRECTORY = path.normpath(path.join(CURRENT_DIRECTORY, '..', '..'))
def main():
exec_command = [
devtools_paths.node_path(),
path.join(CURRENT_DIRECTORY, 'run_lint_check_js.mjs'),
]
eslint_proc = Popen(exec_command, cwd=ROOT_DIRECTORY)
eslint_proc.communicate()
sys.exit(eslint_proc.returncode)
if __name__ == '__main__':
main()
+29
View File
@@ -0,0 +1,29 @@
// Copyright 2021 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.
function getTestRunnerConfig() {
try {
return JSON.parse(process.env.TEST_RUNNER_JSON_CONFIG);
} catch {
// Return an empty object so any lookups return undefined
return {};
}
}
function getTestRunnerConfigSetting(settingKey, fallbackValue) {
const config = getTestRunnerConfig();
return config[settingKey] === undefined ? fallbackValue : config[settingKey];
}
function requireTestRunnerConfigSetting(settingKey, errorMessage) {
const config = getTestRunnerConfig();
if (config[settingKey] === undefined) {
throw new Error(errorMessage || `Test runner error: could not find required setting ${settingKey}`);
}
return config[settingKey];
}
module.exports = {
getTestRunnerConfigSetting,
requireTestRunnerConfigSetting
};