forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-no-obsolete-elements.js
More file actions
86 lines (85 loc) · 2.37 KB
/
template-no-obsolete-elements.js
File metadata and controls
86 lines (85 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const OBSOLETE = [
'acronym',
'applet',
'basefont',
'bgsound',
'big',
'blink',
'center',
'dir',
'font',
'frame',
'frameset',
'isindex',
'keygen',
'listing',
'marquee',
'menuitem',
'multicol',
'nextid',
'nobr',
'noembed',
'noframes',
'param',
'plaintext',
'rb',
'rtc',
'spacer',
'strike',
'tt',
'xmp',
];
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow obsolete HTML elements',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-obsolete-elements.md',
templateMode: 'both',
},
schema: [],
messages: { obsolete: '<{{element}}> is obsolete, use modern alternatives' },
originallyFrom: {
name: 'ember-template-lint',
rule: 'lib/rules/no-obsolete-elements.js',
docs: 'docs/rule/no-obsolete-elements.md',
tests: 'test/unit/rules/no-obsolete-elements-test.js',
},
},
create(context) {
const obsolete = new Set(OBSOLETE);
const blockParamsInScope = [];
return {
GlimmerBlockStatement(node) {
const params = node.program?.blockParams || [];
blockParamsInScope.push(...params);
},
'GlimmerBlockStatement:exit'(node) {
const params = node.program?.blockParams || [];
for (let i = 0; i < params.length; i++) {
blockParamsInScope.pop();
}
},
GlimmerElementNode(node) {
// Check the element's own tag before pushing its block params, so an
// element's own params don't shadow its own tag name (e.g.
// `<marquee as |marquee|>` should still flag the outer <marquee>).
if (!blockParamsInScope.includes(node.tag) && obsolete.has(node.tag)) {
context.report({ node, messageId: 'obsolete', data: { element: node.tag } });
}
// Element-level block params (e.g. `<Comp as |param|>`) are scoped to
// the children, so push them after the obsolete check. Pop on exit.
const elementParams = node.blockParams || [];
blockParamsInScope.push(...elementParams);
},
'GlimmerElementNode:exit'(node) {
const elementParams = node.blockParams || [];
for (let i = 0; i < elementParams.length; i++) {
blockParamsInScope.pop();
}
},
};
},
};