Skip to content

Commit af3845b

Browse files
committed
lint:fixes
1 parent fb38637 commit af3845b

22 files changed

Lines changed: 288 additions & 252 deletions

docs/rules/template-no-bare-strings.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ module.exports = {
9393
'ember/template-no-bare-strings': [
9494
'error',
9595
{
96-
globalAttributes: ['title', 'aria-label', 'aria-placeholder', 'aria-roledescription', 'aria-valuetext'],
96+
globalAttributes: [
97+
'title',
98+
'aria-label',
99+
'aria-placeholder',
100+
'aria-roledescription',
101+
'aria-valuetext',
102+
],
97103
},
98104
],
99105
},

lib/rules/template-deprecated-inline-view-helper.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
function isViewPath(pathNode) {
2+
return (
3+
pathNode &&
4+
pathNode.type === 'GlimmerPathExpression' &&
5+
pathNode.original &&
6+
pathNode.original.startsWith('view.') &&
7+
pathNode.head?.type !== 'ThisHead' &&
8+
pathNode.head?.type !== 'AtHead'
9+
);
10+
}
11+
112
/** @type {import('eslint').Rule.RuleModule} */
213
module.exports = {
314
meta: {
@@ -24,17 +35,6 @@ module.exports = {
2435
},
2536

2637
create(context) {
27-
function isViewPath(pathNode) {
28-
return (
29-
pathNode &&
30-
pathNode.type === 'GlimmerPathExpression' &&
31-
pathNode.original &&
32-
pathNode.original.startsWith('view.') &&
33-
pathNode.head?.type !== 'ThisHead' &&
34-
pathNode.head?.type !== 'AtHead'
35-
);
36-
}
37-
3838
function checkHashForViewPaths(node) {
3939
if (node.hash && node.hash.pairs) {
4040
for (const pair of node.hash.pairs) {

lib/rules/template-no-autofocus-attribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ module.exports = {
5151
},
5252
};
5353
},
54-
};
54+
};

lib/rules/template-no-chained-this.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ module.exports = {
7272
},
7373
};
7474
},
75-
};
75+
};

lib/rules/template-no-dynamic-subexpression-invocations.js

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
function isInAttrPosition(node) {
2+
let p = node.parent;
3+
while (p) {
4+
if (p.type === 'GlimmerAttrNode') {
5+
return true;
6+
}
7+
if (p.type === 'GlimmerConcatStatement') {
8+
p = p.parent;
9+
continue;
10+
}
11+
if (
12+
p.type === 'GlimmerElementNode' ||
13+
p.type === 'GlimmerTemplate' ||
14+
p.type === 'GlimmerBlockStatement' ||
15+
p.type === 'GlimmerBlock'
16+
) {
17+
return false;
18+
}
19+
p = p.parent;
20+
}
21+
return false;
22+
}
23+
124
/** @type {import('eslint').Rule.RuleModule} */
225
module.exports = {
326
meta: {
@@ -36,37 +59,28 @@ module.exports = {
3659

3760
function isLocal(name) {
3861
for (const scope of localScopes) {
39-
if (scope.has(name)) {return true;}
62+
if (scope.has(name)) {
63+
return true;
64+
}
4065
}
4166
return false;
4267
}
4368

4469
function isDynamicPath(path) {
45-
if (!path || path.type !== 'GlimmerPathExpression') {return false;}
46-
if (path.head?.type === 'AtHead') {return true;}
47-
if (path.head?.type === 'ThisHead') {return true;}
48-
if (path.original && path.original.includes('.')) {return true;}
49-
if (path.original && isLocal(path.original)) {return true;}
50-
return false;
51-
}
52-
53-
function isInAttrPosition(node) {
54-
let p = node.parent;
55-
while (p) {
56-
if (p.type === 'GlimmerAttrNode') {return true;}
57-
if (p.type === 'GlimmerConcatStatement') {
58-
p = p.parent;
59-
continue;
60-
}
61-
if (
62-
p.type === 'GlimmerElementNode' ||
63-
p.type === 'GlimmerTemplate' ||
64-
p.type === 'GlimmerBlockStatement' ||
65-
p.type === 'GlimmerBlock'
66-
) {
67-
return false;
68-
}
69-
p = p.parent;
70+
if (!path || path.type !== 'GlimmerPathExpression') {
71+
return false;
72+
}
73+
if (path.head?.type === 'AtHead') {
74+
return true;
75+
}
76+
if (path.head?.type === 'ThisHead') {
77+
return true;
78+
}
79+
if (path.original && path.original.includes('.')) {
80+
return true;
81+
}
82+
if (path.original && isLocal(path.original)) {
83+
return true;
7084
}
7185
return false;
7286
}
@@ -95,11 +109,7 @@ module.exports = {
95109
},
96110

97111
GlimmerSubExpression(node) {
98-
if (
99-
node.path &&
100-
node.path.type === 'GlimmerPathExpression' &&
101-
isDynamicPath(node.path)
102-
) {
112+
if (node.path && node.path.type === 'GlimmerPathExpression' && isDynamicPath(node.path)) {
103113
context.report({
104114
node,
105115
messageId: 'noDynamicSubexpressionInvocations',
@@ -108,11 +118,7 @@ module.exports = {
108118
},
109119

110120
GlimmerElementModifierStatement(node) {
111-
if (
112-
node.path &&
113-
node.path.type === 'GlimmerPathExpression' &&
114-
isDynamicPath(node.path)
115-
) {
121+
if (node.path && node.path.type === 'GlimmerPathExpression' && isDynamicPath(node.path)) {
116122
context.report({
117123
node,
118124
messageId: 'noDynamicSubexpressionInvocations',
@@ -121,10 +127,7 @@ module.exports = {
121127
},
122128

123129
GlimmerMustacheStatement(node) {
124-
if (
125-
node.path &&
126-
node.path.type === 'GlimmerPathExpression'
127-
) {
130+
if (node.path && node.path.type === 'GlimmerPathExpression') {
128131
const inAttr = isInAttrPosition(node);
129132
const hasArgs =
130133
(node.params && node.params.length > 0) ||

lib/rules/template-no-implicit-this.js

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1+
// Built-in helpers and keywords
2+
const BUILT_INS = new Set([
3+
'yield',
4+
'outlet',
5+
'has-block',
6+
'has-block-params',
7+
'if',
8+
'unless',
9+
'each',
10+
'let',
11+
'with',
12+
'each-in',
13+
'concat',
14+
'get',
15+
'array',
16+
'hash',
17+
'log',
18+
'debugger',
19+
'component',
20+
'helper',
21+
'modifier',
22+
'mount',
23+
]);
24+
25+
// Control-flow built-ins whose params should not be flagged
26+
const CONTROL_FLOW_HELPERS = new Set([
27+
'if',
28+
'unless',
29+
'each',
30+
'let',
31+
'with',
32+
'each-in',
33+
'concat',
34+
'get',
35+
'array',
36+
'hash',
37+
'log',
38+
]);
39+
40+
function isMustacheCalleeWithArgs(node) {
41+
const parent = node.parent;
42+
if (parent.path !== node) {
43+
return false;
44+
}
45+
if (parent.params && parent.params.length > 0) {
46+
return true;
47+
}
48+
return Boolean(parent.hash && parent.hash.pairs && parent.hash.pairs.length > 0);
49+
}
50+
51+
function isControlFlowParam(node) {
52+
const callee = node.parent.path?.original;
53+
return CONTROL_FLOW_HELPERS.has(callee) && node.parent.params?.includes(node);
54+
}
55+
56+
function isBlockParamPath(node, path) {
57+
const blockParams = node.parent.program?.blockParams || [];
58+
return blockParams.includes(path.split('.')[0]);
59+
}
60+
161
/** @type {import('eslint').Rule.RuleModule} */
262
module.exports = {
363
meta: {
@@ -33,67 +93,23 @@ module.exports = {
3393
}
3494

3595
// Skip built-in helpers and keywords
36-
const builtIns = [
37-
'yield',
38-
'outlet',
39-
'has-block',
40-
'has-block-params',
41-
'if',
42-
'unless',
43-
'each',
44-
'let',
45-
'with',
46-
'each-in',
47-
'concat',
48-
'get',
49-
'array',
50-
'hash',
51-
'log',
52-
'debugger',
53-
'component',
54-
'helper',
55-
'modifier',
56-
'mount',
57-
];
58-
if (builtIns.includes(path)) {
96+
if (BUILT_INS.has(path)) {
5997
return;
6098
}
6199

62-
// Control-flow built-ins whose params should not be flagged
63-
const controlFlowHelpers = new Set([
64-
'if',
65-
'unless',
66-
'each',
67-
'let',
68-
'with',
69-
'each-in',
70-
'concat',
71-
'get',
72-
'array',
73-
'hash',
74-
'log',
75-
]);
76-
77100
// Skip single identifiers that are the callee of a helper-like MustacheStatement
78101
if (node.parent && node.parent.type === 'GlimmerMustacheStatement') {
79-
// Only skip the callee (path) of a mustache with params/hash, not the params themselves
80-
if (node.parent.path === node && node.parent.params && node.parent.params.length > 0) {
81-
return;
82-
}
83-
if (node.parent.path === node && node.parent.hash && node.parent.hash.pairs && node.parent.hash.pairs.length > 0) {
102+
if (isMustacheCalleeWithArgs(node)) {
84103
return;
85104
}
86-
// Skip params of control-flow built-in helpers
87-
const callee = node.parent.path?.original;
88-
if (controlFlowHelpers.has(callee) && node.parent.params?.includes(node)) {
105+
if (isControlFlowParam(node)) {
89106
return;
90107
}
91108
}
92109

93110
// Skip paths that are part of block params
94111
if (node.parent && node.parent.type === 'GlimmerBlockStatement') {
95-
const blockParams = node.parent.program?.blockParams || [];
96-
if (blockParams.includes(path.split('.')[0])) {
112+
if (isBlockParamPath(node, path)) {
97113
return;
98114
}
99115
}

lib/rules/template-no-invalid-aria-attributes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ function isValidAriaValue(attrName, value) {
5454
return permittedValues.includes(value);
5555
}
5656
case 'tokenlist': {
57-
return value
58-
.split(' ')
59-
.every((token) => attrDef.values.includes(token.toLowerCase()));
57+
return value.split(' ').every((token) => attrDef.values.includes(token.toLowerCase()));
6058
}
6159
default: {
6260
return true;

lib/rules/template-no-shadowed-elements.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ module.exports = {
148148

149149
function isLocal(name) {
150150
for (const scope of blockParamScope) {
151-
if (scope.has(name)) {return true;}
151+
if (scope.has(name)) {
152+
return true;
153+
}
152154
}
153155
return false;
154156
}
@@ -172,7 +174,9 @@ module.exports = {
172174
}
173175

174176
const tag = node.tag;
175-
if (!tag) {return;}
177+
if (!tag) {
178+
return;
179+
}
176180

177181
const firstChar = tag.charAt(0);
178182
const startsWithUpperCase =

lib/rules/template-no-unnecessary-curly-strings.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ module.exports = {
3939
}
4040
},
4141
GlimmerMustacheStatement(node) {
42-
if (
43-
node.path?.type === 'GlimmerStringLiteral' &&
44-
node.parent?.type !== 'GlimmerAttrNode'
45-
) {
42+
if (node.path?.type === 'GlimmerStringLiteral' && node.parent?.type !== 'GlimmerAttrNode') {
4643
const strValue = node.path.value || node.path.original;
4744
context.report({
4845
node,

0 commit comments

Comments
 (0)