Skip to content

Commit 6988c6b

Browse files
Fix code review issues: attribute-splat logic, remove LinkTo conflict, simplify index check
Co-authored-by: NullVoxPopuli <[email protected]>
1 parent a612754 commit 6988c6b

6 files changed

Lines changed: 16 additions & 26 deletions

docs/rules/template-no-builtin-form-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Disallows usage of built-in form components.
88

99
## Rule Details
1010

11-
Built-in Ember components like `<Input>`, `<Textarea>`, and `<LinkTo>` should be replaced with native HTML elements for better performance and simpler code.
11+
Built-in Ember components like `<Input>` and `<Textarea>` should be replaced with native HTML elements for better performance and simpler code.
1212

1313
## Examples
1414

docs/rules/template-no-index-component-invocation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Examples of **incorrect** code for this rule:
1616

1717
```gjs
1818
<template>
19-
<MyComponent/index />
19+
<MyComponent::Index />
2020
</template>
2121
```
2222

2323
```gjs
2424
<template>
25-
<Foo/index />
25+
<Foo::Index />
2626
</template>
2727
```
2828

lib/rules/template-no-attribute-splat-on-html-element.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ module.exports = {
2020
create(context) {
2121
return {
2222
GlimmerElementNode(node) {
23-
// Check if it's an HTML element (lowercase tag)
24-
if (node.tag && node.tag[0] === node.tag[0].toLowerCase() && node.attributes) {
25-
for (const attr of node.attributes) {
26-
if (attr.name === '...attributes') {
27-
context.report({
28-
node: attr,
29-
messageId: 'noAttributeSplat',
30-
});
23+
// Check if it's an HTML element (starts with lowercase letter)
24+
if (node.tag && node.tag.length > 0 && node.tag[0] === node.tag[0].toLowerCase()) {
25+
if (node.attributes) {
26+
for (const attr of node.attributes) {
27+
if (attr.name === '...attributes') {
28+
context.report({
29+
node: attr,
30+
messageId: 'noAttributeSplat',
31+
});
32+
}
3133
}
3234
}
3335
}

lib/rules/template-no-builtin-form-components.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
},
1919

2020
create(context) {
21-
const BUILTIN_FORM_COMPONENTS = new Set(['Input', 'Textarea', 'LinkTo']);
21+
const BUILTIN_FORM_COMPONENTS = new Set(['Input', 'Textarea']);
2222

2323
return {
2424
GlimmerElementNode(node) {

lib/rules/template-no-index-component-invocation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module.exports = {
2121
return {
2222
GlimmerElementNode(node) {
2323
if (node.tag && typeof node.tag === 'string') {
24-
// Check if tag ends with ::Index (case-insensitive to catch Index, index, INDEX)
25-
if (node.tag.endsWith('::Index') || /::index$/i.test(node.tag)) {
24+
// Check if tag ends with ::Index (case-insensitive)
25+
if (/::index$/i.test(node.tag)) {
2626
context.report({
2727
node,
2828
messageId: 'noIndexInvocation',

tests/lib/rules/template-no-builtin-form-components.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,5 @@ ruleTester.run('template-no-builtin-form-components', rule, {
5252
},
5353
],
5454
},
55-
{
56-
code: `<template>
57-
<LinkTo @route="index">Home</LinkTo>
58-
</template>`,
59-
output: null,
60-
errors: [
61-
{
62-
message: 'Do not use built-in form components. Use native HTML elements instead.',
63-
type: 'GlimmerElementNode',
64-
},
65-
],
66-
},
6755
],
6856
});

0 commit comments

Comments
 (0)