Skip to content

Commit 49d12de

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
Revert "Remove custom_element_definitions_location lint rule."
This reverts commit dc5df3f. Reason for revert: Actually this is fully inline with the UI eng vision. Not sure what I was thinking. Original change's description: > Remove custom_element_definitions_location lint rule. > > It is hard to justify this requiement in the light of UI engineering > approach we are taking. > > Bug: 301364727 > Change-Id: I9f8f42255aab5dd41858e5840e048e47719f8520 > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5899035 > Reviewed-by: Benedikt Meurer <[email protected]> > Commit-Queue: Benedikt Meurer <[email protected]> > Auto-Submit: Danil Somsikov <[email protected]> Bug: 301364727 Change-Id: I5096f996bb1ca22d8e1a26535dc3aa742fb84c02 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6252746 Reviewed-by: Benedikt Meurer <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 72880a0 commit 49d12de

File tree

4 files changed

+229
-1
lines changed

4 files changed

+229
-1
lines changed

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,12 @@ export default [
568568
'rulesdir/jslog-context-list': 'error',
569569
'rulesdir/es-modules-import': 'error',
570570
'rulesdir/html-tagged-template': 'error',
571+
'rulesdir/enforce-custom-element-definitions-location': [
572+
'error',
573+
{
574+
rootFrontendDirectory: join(import.meta.dirname, 'front_end'),
575+
},
576+
],
571577
},
572578
},
573579
{
@@ -620,6 +626,7 @@ export default [
620626
'rulesdir/prefer-assert-length-of': 'error',
621627
'rulesdir/prefer-url-string': 'error',
622628
'rulesdir/trace-engine-test-timeouts': 'error',
629+
'rulesdir/enforce-custom-element-definitions-location': 'off',
623630
},
624631

625632
settings: {

front_end/ui/legacy/components/perf_ui/BrickBreaker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ const colorPallettes: ColorPalette[] = [
108108
},
109109
];
110110

111-
/* rulesdir/no-underscored-properties, rulesdir/no-a-tags-in-lit */
112111
export class BrickBreaker extends HTMLElement {
113112
#canvas: HTMLCanvasElement;
114113
#ctx: CanvasRenderingContext2D;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
'use strict';
5+
6+
const path = require('path');
7+
8+
/**
9+
* @type {import('eslint').Rule.RuleModule}
10+
*/
11+
module.exports = {
12+
meta: {
13+
type: 'problem',
14+
15+
docs: {
16+
description:
17+
'ensure that custom element definitions are in the correct folders.',
18+
category: 'Possible Errors',
19+
},
20+
fixable: 'code',
21+
messages: {
22+
definitionInWrongFolder:
23+
'A custom element definition was found in a folder that ' +
24+
'should not contain element definitions. If you want to define a custom element, ' +
25+
'either place it in `ui/components/` or in a `components` sub-folder of a panel. ' +
26+
'E.g. `panels/elements/components/`.',
27+
},
28+
schema: [
29+
{
30+
type: 'object',
31+
properties: {
32+
rootFrontendDirectory: {
33+
type: 'string',
34+
},
35+
},
36+
additionalProperties: false,
37+
},
38+
],
39+
},
40+
create: function (context) {
41+
const filename = context.filename ?? context.getFilename();
42+
const classDefiningFileName = path.resolve(filename);
43+
44+
let frontEndDirectory = '';
45+
if (context.options?.[0]?.rootFrontendDirectory) {
46+
frontEndDirectory = context.options[0].rootFrontendDirectory;
47+
}
48+
if (!frontEndDirectory) {
49+
throw new Error(
50+
'rootFrontEndDirectory must be provided to custom_elements_definitions_location.',
51+
);
52+
}
53+
54+
const PANELS_DIRECTORY = path.join(frontEndDirectory, 'panels');
55+
56+
const ALLOWED_CUSTOM_ELEMENT_LOCATIONS = new Set([
57+
path.join(frontEndDirectory, 'ui', 'components'),
58+
59+
// These should be moved to `ui/components` at some point
60+
path.join(frontEndDirectory, 'ui', 'legacy'),
61+
// path.join(frontEndDirectory, 'ui', 'legacy', 'components', 'inline_editor'),
62+
// path.join(frontEndDirectory, 'ui', 'legacy', 'components', 'perf_ui', 'PieChart.ts'),
63+
// path.join(frontEndDirectory, 'ui', 'legacy', 'XElement.ts'),
64+
]);
65+
66+
return {
67+
ClassDeclaration(node) {
68+
if (node.superClass?.name !== 'HTMLElement') {
69+
return;
70+
}
71+
72+
for (const allowedLocation of ALLOWED_CUSTOM_ELEMENT_LOCATIONS) {
73+
if (classDefiningFileName.startsWith(allowedLocation)) {
74+
return;
75+
}
76+
}
77+
78+
if (classDefiningFileName.startsWith(PANELS_DIRECTORY)) {
79+
const filePathWithPanelName = classDefiningFileName.substring(
80+
PANELS_DIRECTORY.length + 1,
81+
);
82+
const filePathWithoutPanelName = filePathWithPanelName.substring(
83+
filePathWithPanelName.indexOf(path.sep) + 1,
84+
);
85+
86+
if (filePathWithoutPanelName.includes(`components${path.sep}`)) {
87+
return;
88+
}
89+
}
90+
91+
context.report({
92+
node,
93+
messageId: 'definitionInWrongFolder',
94+
});
95+
},
96+
};
97+
},
98+
};
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
'use strict';
5+
6+
const path = require('path');
7+
8+
const rule = require('../lib/enforce-custom-element-definitions-location.js');
9+
10+
const {ruleTester} = require('./utils/utils.js');
11+
12+
ruleTester.run('enforce-custom-element-definitions-location', rule, {
13+
valid: [
14+
{
15+
code: 'class Foo extends HTMLElement {}',
16+
filename: 'front_end/ui/components/foo/Foo.ts',
17+
options: [
18+
{
19+
rootFrontendDirectory: path.join(
20+
__dirname,
21+
'..',
22+
'..',
23+
'..',
24+
'front_end',
25+
),
26+
},
27+
],
28+
},
29+
{
30+
code: 'class Foo extends HTMLElement {}',
31+
filename: 'front_end/panels/issues/components/Foo.ts',
32+
options: [
33+
{
34+
rootFrontendDirectory: path.join(
35+
__dirname,
36+
'..',
37+
'..',
38+
'..',
39+
'front_end',
40+
),
41+
},
42+
],
43+
},
44+
{
45+
code: 'class Foo extends HTMLElement {}',
46+
filename: 'front_end/panels/issues/components/nested/folder/Foo.ts',
47+
options: [
48+
{
49+
rootFrontendDirectory: path.join(
50+
__dirname,
51+
'..',
52+
'..',
53+
'..',
54+
'front_end',
55+
),
56+
},
57+
],
58+
},
59+
{
60+
code: 'class Foo extends HTMLElement {}',
61+
filename: 'front_end/panels/performance/library/components/metrics/Metric.ts',
62+
options: [
63+
{
64+
rootFrontendDirectory: path.join(
65+
__dirname,
66+
'..',
67+
'..',
68+
'..',
69+
'front_end',
70+
),
71+
},
72+
],
73+
},
74+
{
75+
code: 'class Foo extends OtherClass {}',
76+
filename: 'front_end/models/some/Model.ts',
77+
options: [
78+
{
79+
rootFrontendDirectory: path.join(
80+
__dirname,
81+
'..',
82+
'..',
83+
'..',
84+
'front_end',
85+
),
86+
},
87+
],
88+
},
89+
],
90+
invalid: [
91+
{
92+
code: 'class Foo extends HTMLElement {}',
93+
filename: 'front_end/panels/issues/IssuesPanel.ts',
94+
errors: [{messageId: 'definitionInWrongFolder'}],
95+
options: [
96+
{
97+
rootFrontendDirectory: path.join(
98+
__dirname,
99+
'..',
100+
'..',
101+
'..',
102+
'front_end',
103+
),
104+
},
105+
],
106+
},
107+
{
108+
code: 'class Foo extends HTMLElement {}',
109+
filename: 'front_end/models/bindings/Bindings.ts',
110+
errors: [{messageId: 'definitionInWrongFolder'}],
111+
options: [
112+
{
113+
rootFrontendDirectory: path.join(
114+
__dirname,
115+
'..',
116+
'..',
117+
'..',
118+
'front_end',
119+
),
120+
},
121+
],
122+
},
123+
],
124+
});

0 commit comments

Comments
 (0)