Skip to content

Commit 789751e

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
Revert "[cleanup] Remove dead code"
This reverts commit 26bc275. 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 <[email protected]> > Auto-Submit: Nikolay Vitkov <[email protected]> > Reviewed-by: Benedikt Meurer <[email protected]> Bug: none Change-Id: I090c1750ec1ada53df22c443253922162f41e271 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6072803 Reviewed-by: Simon Zünd <[email protected]> Bot-Commit: Rubber Stamper <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 8c4fd43 commit 789751e

File tree

8 files changed

+254
-14
lines changed

8 files changed

+254
-14
lines changed

scripts/component_server/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ import("../build/ninja/copy.gni")
77
copy_to_gen("component_server") {
88
sources = [ "server.js" ]
99

10-
deps = [ "../../front_end/ui/legacy:copy_stylesheets_for_server" ]
10+
deps = [
11+
"../../front_end/ui/legacy:copy_stylesheets_for_server",
12+
"../test",
13+
]
1114
}

scripts/component_server/server.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,11 @@ const path = require('path');
88
const parseURL = require('url').parse;
99
const {argv} = require('yargs');
1010

11+
const {getTestRunnerConfigSetting} = require('../test/test_config_helpers.js');
12+
1113
const tracesMode = argv.traces || false;
1214
const serverPort = parseInt(process.env.PORT, 10) || (tracesMode ? 11010 : 8090);
1315

14-
function getTestRunnerConfig() {
15-
try {
16-
return JSON.parse(process.env.TEST_RUNNER_JSON_CONFIG);
17-
} catch {
18-
// Return an empty object so any lookups return undefined
19-
return {};
20-
}
21-
}
22-
function getTestRunnerConfigSetting(settingKey, fallbackValue) {
23-
const config = getTestRunnerConfig();
24-
return config[settingKey] === undefined ? fallbackValue : config[settingKey];
25-
}
26-
2716
/**
2817
* When you run npm run components-server we run the script as is from scripts/,
2918
* but when this server is run as part of a test suite it's run from

scripts/test/BUILD.gn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2021 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("../build/ninja/copy.gni")
6+
7+
copy_to_gen("test") {
8+
sources = [ "test_config_helpers.js" ]
9+
}

scripts/test/run_lint_check.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env vpython3
2+
#
3+
# Copyright 2016 The Chromium Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
# TODO(1083142): remove this file in favor of run_lint_check_js.py once
8+
# infra has been updated.
9+
10+
import sys
11+
from os import path
12+
from subprocess import Popen
13+
14+
scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
15+
sys.path.append(scripts_path)
16+
import devtools_paths
17+
18+
CURRENT_DIRECTORY = path.dirname(path.abspath(__file__))
19+
ROOT_DIRECTORY = path.normpath(path.join(CURRENT_DIRECTORY, '..', '..'))
20+
21+
22+
def main():
23+
exec_command = [
24+
devtools_paths.node_path(),
25+
path.join(CURRENT_DIRECTORY, 'run_lint_check_js.mjs'),
26+
]
27+
28+
eslint_proc = Popen(exec_command, cwd=ROOT_DIRECTORY)
29+
eslint_proc.communicate()
30+
31+
sys.exit(eslint_proc.returncode)
32+
33+
34+
if __name__ == '__main__':
35+
main()

scripts/test/run_lint_check_css.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
const path = require('path');
6+
const childProcess = require('child_process');
7+
const {
8+
devtoolsRootPath,
9+
stylelintExecutablePath,
10+
nodePath,
11+
} = require('../devtools_paths.js');
12+
13+
const yargsObject = require('yargs')
14+
.option('files', {type: 'array', desc: 'One or more files to lint.'})
15+
.option('glob', {default: '**/*.css', desc: 'A glob to choose which files to lint.'})
16+
.option('cwd', {default: devtoolsRootPath(), desc: 'Working directory to glob from'})
17+
.parserConfiguration({
18+
// So that if we pass --foo-bar, Yargs only populates
19+
// argv with '--foo-bar', not '--foo-bar' and
20+
// 'fooBar'. This is important because if we have both
21+
// versions and pass them to stylelint, it errors
22+
// saying that we've passed the same argument twice.
23+
'camel-case-expansion': false
24+
})
25+
.argv;
26+
27+
// Note: stylelint requires POSIX-formatted paths/globs, even on Windows.
28+
// The forward slash is not a bug.
29+
const DEFAULT_GLOB = '**/*.css';
30+
31+
function getCSSFilesOrGlobList() {
32+
const files = yargsObject.files || [];
33+
if (files.length > 0) {
34+
return files.map(file => {
35+
// Enforce posix file paths even on Windows
36+
return file.split(path.sep).join(path.posix.sep);
37+
});
38+
}
39+
40+
return [yargsObject.glob || DEFAULT_GLOB];
41+
}
42+
43+
function run() {
44+
// eslint-disable-next-line no-unused-vars
45+
const {glob, files, cwd, _, $0, ...flagsForStylelint} = yargsObject;
46+
47+
const extraFlagsForStylelint = Object.keys(flagsForStylelint).flatMap(key => [`--${key}`, flagsForStylelint[key]]);
48+
49+
const args = [
50+
stylelintExecutablePath(), ...getCSSFilesOrGlobList(), '--fix', '--allow-empty-input', ...extraFlagsForStylelint
51+
];
52+
const result = childProcess.spawnSync(nodePath(), args, {encoding: 'utf-8', cwd, stdio: 'inherit'});
53+
if (result.error) {
54+
// If spawnSync returns an error, exit with an error no matter what result.status says.
55+
console.error(result.error);
56+
process.exit(1);
57+
return;
58+
}
59+
process.exit(result.status);
60+
}
61+
62+
run();

scripts/test/run_lint_check_js.mjs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Use V8's code cache to speed up instantiation time.
6+
await import('v8-compile-cache');
7+
8+
import path from 'path';
9+
import {ESLint} from 'eslint';
10+
import { fileURLToPath } from 'url';
11+
12+
import yargs from 'yargs';
13+
14+
// False positive from the ESLint rule: crbug.com/1319352
15+
// eslint-disable-next-line rulesdir/es_modules_import
16+
import {hideBin} from 'yargs/helpers';
17+
18+
const flags = yargs(hideBin(process.argv)).option('fix', {
19+
type: 'boolean',
20+
default: true,
21+
describe: 'If to run ESLint in fix mode',
22+
}).parse();
23+
24+
const shouldFix = flags.fix === true;
25+
26+
if(!shouldFix) {
27+
console.log('[ESLint]: fix is disabled; no errors will be autofixed.');
28+
}
29+
30+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
31+
32+
const ROOT_DIRECTORY = path.join(__dirname, '..', '..');
33+
const FRONT_END_DIRECTORY = path.join(ROOT_DIRECTORY, 'front_end');
34+
const INSPECTOR_OVERLAY_DIRECTORY = path.join(ROOT_DIRECTORY, 'inspector_overlay');
35+
const TEST_DIRECTORY = path.join(ROOT_DIRECTORY, 'test');
36+
const SCRIPTS_DIRECTORY = path.join(ROOT_DIRECTORY, 'scripts');
37+
38+
const DEFAULT_DIRECTORIES_TO_LINT =
39+
[FRONT_END_DIRECTORY, INSPECTOR_OVERLAY_DIRECTORY, TEST_DIRECTORY, SCRIPTS_DIRECTORY];
40+
41+
const eslintignorePath = path.join(ROOT_DIRECTORY, '.eslintignore');
42+
43+
// Yargs gathers up any non-flag arguments into the `_` property.
44+
// npm run check-lint-js foo => flags._ === ['foo']
45+
let directoriesOrFilesToLint = flags._;
46+
47+
if (directoriesOrFilesToLint.length === 0) {
48+
directoriesOrFilesToLint = DEFAULT_DIRECTORIES_TO_LINT;
49+
}
50+
51+
const cli = new ESLint({
52+
extensions: ['.js', '.ts'],
53+
ignorePath: eslintignorePath,
54+
fix: shouldFix,
55+
});
56+
57+
// We filter out certain files in the `.eslintignore`. However, ESLint produces warnings
58+
// when you include a particular file that is ignored. This means that if you edit a file
59+
// that is directly ignored in the `.eslintignore`, ESLint would report a failure.
60+
// This was originally reported in https://github.com/eslint/eslint/issues/9977
61+
// The suggested workaround is to use the CLIEngine to pre-emptively filter out these
62+
// problematic paths.
63+
const filteredFilesToLint = [];
64+
for (const path of directoriesOrFilesToLint) {
65+
if (!(await cli.isPathIgnored(path))) {
66+
filteredFilesToLint.push(path);
67+
}
68+
}
69+
70+
const results = await cli.lintFiles(filteredFilesToLint);
71+
72+
// Write fixes to the filesystem
73+
if (shouldFix) {
74+
await ESLint.outputFixes(results);
75+
}
76+
77+
const formatter = await cli.loadFormatter('stylish');
78+
console.log(formatter.format(results));
79+
80+
const hasProblems = results.find(report => report.errorCount + report.warningCount > 0);
81+
process.exit(hasProblems ? 1 : 0);

scripts/test/run_lint_check_js.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env vpython3
2+
#
3+
# Copyright 2016 The Chromium Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
import sys
8+
from os import path
9+
from subprocess import Popen
10+
11+
scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
12+
sys.path.append(scripts_path)
13+
import devtools_paths
14+
15+
CURRENT_DIRECTORY = path.dirname(path.abspath(__file__))
16+
ROOT_DIRECTORY = path.normpath(path.join(CURRENT_DIRECTORY, '..', '..'))
17+
18+
19+
def main():
20+
exec_command = [
21+
devtools_paths.node_path(),
22+
path.join(CURRENT_DIRECTORY, 'run_lint_check_js.mjs'),
23+
]
24+
25+
eslint_proc = Popen(exec_command, cwd=ROOT_DIRECTORY)
26+
eslint_proc.communicate()
27+
28+
sys.exit(eslint_proc.returncode)
29+
30+
31+
if __name__ == '__main__':
32+
main()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
function getTestRunnerConfig() {
6+
try {
7+
return JSON.parse(process.env.TEST_RUNNER_JSON_CONFIG);
8+
} catch {
9+
// Return an empty object so any lookups return undefined
10+
return {};
11+
}
12+
}
13+
function getTestRunnerConfigSetting(settingKey, fallbackValue) {
14+
const config = getTestRunnerConfig();
15+
return config[settingKey] === undefined ? fallbackValue : config[settingKey];
16+
}
17+
function requireTestRunnerConfigSetting(settingKey, errorMessage) {
18+
const config = getTestRunnerConfig();
19+
if (config[settingKey] === undefined) {
20+
throw new Error(errorMessage || `Test runner error: could not find required setting ${settingKey}`);
21+
}
22+
23+
return config[settingKey];
24+
}
25+
26+
module.exports = {
27+
getTestRunnerConfigSetting,
28+
requireTestRunnerConfigSetting
29+
};

0 commit comments

Comments
 (0)