Skip to content

Commit 19f5da2

Browse files
Add 2 more rules: no-quoteless-attributes, no-this-in-template-only-components (27/127)
Co-authored-by: NullVoxPopuli <[email protected]>
1 parent 86499ac commit 19f5da2

12 files changed

Lines changed: 187 additions & 0 deletions

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,16 @@ rules in templates can be disabled with eslint directives with mustache or html
188188

189189
| Name | Description | 💼 | 🔧 | 💡 |
190190
| :--------------------------------------------------------------------------------- | :----------------------------------------------------- | :-------------------------------------------------------------- | :- | :- |
191+
| [template-no-args-paths](docs/rules/template-no-args-paths.md) | disallow @args in paths | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | | |
191192
| [template-no-debugger](docs/rules/template-no-debugger.md) | disallow {{debugger}} in templates | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | | |
192193
| [template-no-duplicate-attributes](docs/rules/template-no-duplicate-attributes.md) | disallow duplicate attribute names in templates | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | 🔧 | |
193194
| [template-no-duplicate-id](docs/rules/template-no-duplicate-id.md) | disallow duplicate id attributes | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | | |
194195
| [template-no-inline-styles](docs/rules/template-no-inline-styles.md) | disallow inline styles | | | |
196+
| [template-no-input-block](docs/rules/template-no-input-block.md) | disallow block usage of {{input}} helper | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | | |
197+
| [template-no-input-tagname](docs/rules/template-no-input-tagname.md) | disallow tagName attribute on {{input}} helper | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | | |
195198
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | | |
196199
| [template-no-unnecessary-concat](docs/rules/template-no-unnecessary-concat.md) | disallow unnecessary string concatenation | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | 🔧 | |
200+
| [template-no-valueless-arguments](docs/rules/template-no-valueless-arguments.md) | disallow valueless named arguments | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | | |
197201
| [template-require-button-type](docs/rules/template-require-button-type.md) | require button elements to have a valid type attribute | ![gjs logo](/docs/svgs/gjs.svg) ![gts logo](/docs/svgs/gts.svg) | 🔧 | |
198202

199203
### Components
@@ -341,6 +345,12 @@ rules in templates can be disabled with eslint directives with mustache or html
341345
| [no-unnecessary-service-injection-argument](docs/rules/no-unnecessary-service-injection-argument.md) | disallow unnecessary argument when injecting services | | 🔧 | |
342346
| [no-unused-services](docs/rules/no-unused-services.md) | disallow unused service injections (see rule doc for limitations) | | | 💡 |
343347

348+
### Style
349+
350+
| Name | Description | 💼 | 🔧 | 💡 |
351+
| :------------------------------------------------------------------------------------------- | :--------------------------------------------------------- | :- | :- | :- |
352+
| [template-no-unnecessary-curly-strings](docs/rules/template-no-unnecessary-curly-strings.md) | disallow unnecessary curly braces in string interpolations | | | |
353+
344354
### Stylistic Issues
345355

346356
| Name | Description | 💼 | 🔧 | 💡 |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ember/template-no-args-paths
2+
3+
💼 This rule is enabled in the following [configs](https://github.com/ember-cli/eslint-plugin-ember#-configurations): ![gjs logo](/docs/svgs/gjs.svg) `recommended-gjs`, ![gts logo](/docs/svgs/gts.svg) `recommended-gts`.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Examples
8+
9+
See ember-template-lint documentation.
10+
11+
## References
12+
13+
- [ember-template-lint no-args-paths](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-args-paths.md)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ember/template-no-input-block
2+
3+
💼 This rule is enabled in the following [configs](https://github.com/ember-cli/eslint-plugin-ember#-configurations): ![gjs logo](/docs/svgs/gjs.svg) `recommended-gjs`, ![gts logo](/docs/svgs/gts.svg) `recommended-gts`.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Examples
8+
9+
See ember-template-lint documentation.
10+
11+
## References
12+
13+
- [ember-template-lint no-input-block](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-input-block.md)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ember/template-no-input-tagname
2+
3+
💼 This rule is enabled in the following [configs](https://github.com/ember-cli/eslint-plugin-ember#-configurations): ![gjs logo](/docs/svgs/gjs.svg) `recommended-gjs`, ![gts logo](/docs/svgs/gts.svg) `recommended-gts`.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Examples
8+
9+
See ember-template-lint documentation.
10+
11+
## References
12+
13+
- [ember-template-lint no-input-tagname](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-input-tagname.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ember/template-no-unnecessary-curly-strings
2+
3+
<!-- end auto-generated rule header -->
4+
5+
## Examples
6+
7+
See ember-template-lint documentation.
8+
9+
## References
10+
11+
- [ember-template-lint no-unnecessary-curly-strings](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-unnecessary-curly-strings.md)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ember/template-no-valueless-arguments
2+
3+
💼 This rule is enabled in the following [configs](https://github.com/ember-cli/eslint-plugin-ember#-configurations): ![gjs logo](/docs/svgs/gjs.svg) `recommended-gjs`, ![gts logo](/docs/svgs/gts.svg) `recommended-gts`.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Examples
8+
9+
See ember-template-lint documentation.
10+
11+
## References
12+
13+
- [ember-template-lint no-valueless-arguments](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-valueless-arguments.md)

lib/recommended-rules-gjs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ module.exports = {
1111
"ember/template-no-abstract-roles": "error",
1212
"ember/template-no-accesskey-attribute": "error",
1313
"ember/template-no-action": "error",
14+
"ember/template-no-args-paths": "error",
1415
"ember/template-no-aria-hidden-body": "error",
1516
"ember/template-no-autofocus-attribute": "error",
1617
"ember/template-no-debugger": "error",
1718
"ember/template-no-duplicate-attributes": "error",
1819
"ember/template-no-duplicate-id": "error",
20+
"ember/template-no-input-block": "error",
21+
"ember/template-no-input-tagname": "error",
1922
"ember/template-no-let-reference": "error",
2023
"ember/template-no-log": "error",
2124
"ember/template-no-partial": "error",
2225
"ember/template-no-positive-tabindex": "error",
2326
"ember/template-no-triple-curlies": "error",
2427
"ember/template-no-unbound": "error",
2528
"ember/template-no-unnecessary-concat": "error",
29+
"ember/template-no-valueless-arguments": "error",
2630
"ember/template-no-with": "error",
2731
"ember/template-require-button-type": "error"
2832
}

lib/recommended-rules-gts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ module.exports = {
1111
"ember/template-no-abstract-roles": "error",
1212
"ember/template-no-accesskey-attribute": "error",
1313
"ember/template-no-action": "error",
14+
"ember/template-no-args-paths": "error",
1415
"ember/template-no-aria-hidden-body": "error",
1516
"ember/template-no-autofocus-attribute": "error",
1617
"ember/template-no-debugger": "error",
1718
"ember/template-no-duplicate-attributes": "error",
1819
"ember/template-no-duplicate-id": "error",
20+
"ember/template-no-input-block": "error",
21+
"ember/template-no-input-tagname": "error",
1922
"ember/template-no-let-reference": "error",
2023
"ember/template-no-log": "error",
2124
"ember/template-no-partial": "error",
2225
"ember/template-no-positive-tabindex": "error",
2326
"ember/template-no-triple-curlies": "error",
2427
"ember/template-no-unbound": "error",
2528
"ember/template-no-unnecessary-concat": "error",
29+
"ember/template-no-valueless-arguments": "error",
2630
"ember/template-no-with": "error",
2731
"ember/template-require-button-type": "error"
2832
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/** @type {import('eslint').Rule.RuleModule} */
2+
module.exports = {
3+
meta: {
4+
type: 'suggestion',
5+
docs: {
6+
description: 'require quotes on all attribute values',
7+
category: 'Style',
8+
recommendedGjs: false,
9+
recommendedGts: false,
10+
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-quoteless-attributes.md',
11+
},
12+
fixable: 'code',
13+
schema: [],
14+
messages: {
15+
missing: '{{type}} {{name}} should be either quoted or wrapped in mustaches',
16+
},
17+
},
18+
create(context) {
19+
return {
20+
GlimmerAttrNode(node) {
21+
// Check if attribute has text value without quotes
22+
if (node.value?.type === 'GlimmerTextNode' && !node.value.chars.match(/^["']/)) {
23+
const sourceCode = context.sourceCode;
24+
const attrText = sourceCode.getText(node);
25+
26+
// If value looks unquoted (no = or =value without quotes)
27+
if (/=\s*[^"'{]/.test(attrText)) {
28+
const type = node.name?.startsWith('@') ? 'Argument' : 'Attribute';
29+
context.report({
30+
node,
31+
messageId: 'missing',
32+
data: { type, name: node.name },
33+
fix(fixer) {
34+
const valueText = node.value.chars;
35+
const replacementText = `${node.name}="${valueText}"`;
36+
return fixer.replaceText(node, replacementText);
37+
},
38+
});
39+
}
40+
}
41+
},
42+
};
43+
},
44+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** @type {import('eslint').Rule.RuleModule} */
2+
module.exports = {
3+
meta: {
4+
type: 'suggestion',
5+
docs: {
6+
description: 'disallow this in template-only components (gjs/gts)',
7+
category: 'Best Practices',
8+
recommendedGjs: true,
9+
recommendedGts: true,
10+
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-this-in-template-only-components.md',
11+
},
12+
schema: [],
13+
messages: {
14+
noThis:
15+
"Usage of 'this' in path '{{original}}' is not allowed in a template-only component. Use '{{fixed}}' if it is a named argument.",
16+
},
17+
},
18+
create(context) {
19+
return {
20+
GlimmerPathExpression(node) {
21+
// In gjs/gts files with <template> tags, check for this.* usage
22+
if (node.head?.type === 'ThisHead' && node.tail?.length > 0) {
23+
const original = node.original;
24+
const fixed = `@${node.tail[0]}`;
25+
context.report({
26+
node,
27+
messageId: 'noThis',
28+
data: { original, fixed },
29+
});
30+
}
31+
},
32+
};
33+
},
34+
};

0 commit comments

Comments
 (0)