Skip to content

Commit e2e4402

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Speed up jslog context list
Eslint rule function `create` is called on every file. Before: 6194.884ms | 8.0% After: 2785.006ms | 4.1% Percentage is from total lint time. Bug: none Change-Id: I0483afc481eeb4a7eb19ec4c86265a4de78379d9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6420759 Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Liviu Rau <[email protected]> Reviewed-by: Danil Somsikov <[email protected]>
1 parent 6aa6ca4 commit e2e4402

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

PRESUBMIT.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,8 @@ def _CheckDevToolsLint(input_api, output_api):
304304
]
305305

306306
lint_related_files = [
307-
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
308-
'eslint'),
309-
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
310-
'stylelint'),
311-
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
312-
'@typescript-eslint'),
313307
input_api.os_path.join(input_api.PresubmitLocalPath(),
314308
'eslint.config.mjs'),
315-
input_api.os_path.join(scripts_directory, 'eslint_rules'),
316309
input_api.os_path.join(input_api.PresubmitLocalPath(),
317310
'.stylelintrc.json'),
318311
input_api.os_path.join(input_api.PresubmitLocalPath(),
@@ -324,8 +317,20 @@ def _CheckDevToolsLint(input_api, output_api):
324317
'run_lint_check.mjs'),
325318
]
326319

327-
lint_config_files = _getAffectedFiles(input_api, lint_related_files, [],
328-
['.js', '.py'])
320+
lint_related_directories = [
321+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
322+
'eslint'),
323+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
324+
'stylelint'),
325+
input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules',
326+
'@typescript-eslint'),
327+
input_api.os_path.join(scripts_directory, 'eslint_rules'),
328+
]
329+
330+
lint_config_files = _getAffectedFiles(
331+
input_api, lint_related_directories,
332+
[], [".js", ".mjs", ".ts"]) + _getAffectedFiles(
333+
input_api, lint_related_files, [], [])
329334

330335
should_bail_out, files_to_lint = _getFilesToLint(
331336
input_api, output_api, lint_config_files, default_linted_directories,

scripts/eslint_rules/lib/jslog-context-list.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const LICENSE_HEADER = `// Copyright 2024 The Chromium Authors. All rights reser
1616
1717
`;
1818

19+
const formattedValues = new Set(
20+
fs.readFileSync(ABSOLUTE_FILE_PATH, 'utf-8').split('\n').filter(l => l.startsWith(' \'')),
21+
);
22+
1923
/**
2024
* @type {import('eslint').Rule.RuleModule}
2125
*/
@@ -30,13 +34,8 @@ module.exports = {
3034
fixable: 'code',
3135
schema: [], // no options
3236
},
37+
defaultOptions: [],
3338
create: function (context) {
34-
const formattedValues = new Set(
35-
fs
36-
.readFileSync(ABSOLUTE_FILE_PATH, 'utf-8')
37-
.split('\n')
38-
.filter(l => l.startsWith(' \'')),
39-
);
4039
const checkValue = (value, node) => {
4140
if (typeof value !== 'string') {
4241
return;

scripts/eslint_rules/tests/jslog-context-list.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ new RuleTester().run('jslog-context-list', rule, {
2424
code: `
2525
Lit.render(Lit.html\`
2626
<dialog @click=\${this.#handlePointerEvent} @pointermove=\${this.#handlePointerEvent} @cancel=\${this.#onCancel}
27-
jslog=\${VisualLogging.dialog('uNkNown').track({resize: true, keydown: 'Escape'}).parent('mapped')}>
27+
jslog=\${VisualLogging.dialog('uNkNown2').track({resize: true, keydown: 'Escape'}).parent('mapped')}>
2828
<div id="content-wrap">
2929
<div id="content">
3030
<slot></slot>
@@ -36,7 +36,7 @@ new RuleTester().run('jslog-context-list', rule, {
3636
errors: [
3737
{
3838
message:
39-
'Found jslog context value \'uNkNown\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
39+
'Found jslog context value \'uNkNown2\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
4040
},
4141
],
4242
filename: 'front_end/components/test.ts',
@@ -45,7 +45,7 @@ new RuleTester().run('jslog-context-list', rule, {
4545
code: `
4646
UI.ActionRegistration.registerActionExtension({
4747
category: UI.ActionRegistration.ActionCategory.RECORDER,
48-
actionId: 'uNkNown',
48+
actionId: 'uNkNown3',
4949
title: i18nLazyString(UIStrings.createRecording),
5050
async loadActionDelegate() {
5151
const Recorder = await loadRecorderModule();
@@ -56,7 +56,7 @@ new RuleTester().run('jslog-context-list', rule, {
5656
errors: [
5757
{
5858
message:
59-
'Found jslog context value \'uNkNown\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
59+
'Found jslog context value \'uNkNown3\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
6060
},
6161
],
6262
filename: 'front_end/components/test.ts',
@@ -65,7 +65,7 @@ new RuleTester().run('jslog-context-list', rule, {
6565
code: `
6666
UI.ViewManager.registerViewExtension({
6767
location: UI.ViewManager.ViewLocationValues.PANEL,
68-
id: 'uNkNown',
68+
id: 'uNkNown4',
6969
commandPrompt: i18nLazyString(UIStrings.showSources),
7070
title: i18nLazyString(UIStrings.sources),
7171
order: 30,
@@ -78,7 +78,7 @@ new RuleTester().run('jslog-context-list', rule, {
7878
errors: [
7979
{
8080
message:
81-
'Found jslog context value \'uNkNown\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
81+
'Found jslog context value \'uNkNown4\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
8282
},
8383
],
8484
filename: 'front_end/components/test.ts',
@@ -87,41 +87,41 @@ new RuleTester().run('jslog-context-list', rule, {
8787
code: `
8888
Common.Settings.registerSettingExtension({
8989
storageType: Common.Settings.SettingStorageType.Synced,
90-
settingName: 'uNkNown',
90+
settingName: 'uNkNown5',
9191
settingType: Common.Settings.SettingType.REGEX,
9292
defaultValue: '/node_modules/|/bower_components/',
9393
});
9494
`,
9595
errors: [
9696
{
9797
message:
98-
'Found jslog context value \'uNkNown\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
98+
'Found jslog context value \'uNkNown5\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
9999
},
100100
],
101101
filename: 'front_end/components/test.ts',
102102
},
103103
{
104104
code: `
105105
this.disableCaptureJSProfileSetting =
106-
Common.Settings.Settings.instance().createSetting('uNkNown', false);
106+
Common.Settings.Settings.instance().createSetting('uNkNown6', false);
107107
`,
108108
errors: [
109109
{
110110
message:
111-
'Found jslog context value \'uNkNown\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
111+
'Found jslog context value \'uNkNown6\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
112112
},
113113
],
114114
filename: 'front_end/components/test.ts',
115115
},
116116
{
117117
code: `
118118
contextMenu.defaultSection().appendItem(
119-
i18nString(UIStrings.refresh), this.refreshCallback.bind(this), {jslogContext: 'uNkNown'});
119+
i18nString(UIStrings.refresh), this.refreshCallback.bind(this), {jslogContext: 'uNkNown7'});
120120
`,
121121
errors: [
122122
{
123123
message:
124-
'Found jslog context value \'uNkNown\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
124+
'Found jslog context value \'uNkNown7\' that is not listed in front_end/ui/visual_logging/KnownContextValues.ts',
125125
},
126126
],
127127
filename: 'front_end/components/test.ts',

0 commit comments

Comments
 (0)