Skip to content

Commit e6ec1a5

Browse files
committed
Sync with template-lint
1 parent d1299c4 commit e6ec1a5

3 files changed

Lines changed: 62 additions & 107 deletions

File tree

docs/rules/template-no-unnecessary-curly-parens.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66

77
Disallow unnecessary parentheses enclosing statements in curlies. When invoking a helper with arguments, the outer parentheses around the entire expression are unnecessary.
88

9-
## Rule Details
10-
11-
This rule flags `{{(helper args)}}` where the parentheses around the helper call can be removed, becoming `{{helper args}}`.
12-
139
## Examples
1410

15-
Examples of **incorrect** code for this rule:
11+
This rule **forbids** the following:
1612

1713
```gjs
1814
<template>
@@ -26,26 +22,17 @@ Examples of **incorrect** code for this rule:
2622
</template>
2723
```
2824

29-
Examples of **correct** code for this rule:
30-
31-
```gjs
32-
<template>
33-
{{concat "a" "b"}}
34-
</template>
35-
```
25+
This rule **allows** the following:
3626

3727
```gjs
3828
<template>
29+
{{foo}}
3930
{{(foo)}}
40-
</template>
41-
```
42-
43-
```gjs
44-
<template>
45-
{{this.property}}
31+
{{concat "a" "b"}}
32+
{{concat (capitalize "foo") "-bar"}}
4633
</template>
4734
```
4835

4936
## References
5037

51-
- [eslint-plugin-ember template-no-unnecessary-curly-parens](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/template-no-unnecessary-curly-parens.md)
38+
- Ember's [Helper Functions](https://guides.emberjs.com/release/components/helper-functions/) guide

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
fixable: 'code',
2222
schema: [],
2323
messages: {
24-
noUnnecessaryCurlyParens: 'Unnecessary parentheses enclosing statement.',
24+
noUnnecessaryCurlyParens: 'Unnecessary parentheses enclosing statement',
2525
},
2626
originallyFrom: {
2727
name: 'ember-template-lint',

tests/lib/rules/template-no-unnecessary-curly-parens.js

Lines changed: 55 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,63 @@
55
const rule = require('../../../lib/rules/template-no-unnecessary-curly-parens');
66
const RuleTester = require('eslint').RuleTester;
77

8-
const ruleTester = new RuleTester({
8+
const validHbs = [
9+
'{{foo}}',
10+
'{{this.foo}}',
11+
'{{(helper)}}',
12+
'{{(this.helper)}}',
13+
'{{concat "a" "b"}}',
14+
'{{concat (capitalize "foo") "-bar"}}',
15+
];
16+
17+
const invalidHbs = [
18+
{
19+
code: '<FooBar @x="{{index}}X{{(someHelper foo)}}" />',
20+
output: '<FooBar @x="{{index}}X{{someHelper foo}}" />',
21+
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
22+
},
23+
{
24+
code: '<FooBar @x="{{index}}XY{{(someHelper foo)}}" />',
25+
output: '<FooBar @x="{{index}}XY{{someHelper foo}}" />',
26+
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
27+
},
28+
{
29+
code: '<FooBar @x="{{index}}--{{(someHelper foo)}}" />',
30+
output: '<FooBar @x="{{index}}--{{someHelper foo}}" />',
31+
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
32+
},
33+
{
34+
code: '{{(concat "a" "b")}}',
35+
output: '{{concat "a" "b"}}',
36+
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
37+
},
38+
{
39+
code: '{{(helper a="b")}}',
40+
output: '{{helper a="b"}}',
41+
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
42+
},
43+
];
44+
45+
function wrapTemplate(entry) {
46+
if (typeof entry === 'string') {
47+
return `<template>${entry}</template>`;
48+
}
49+
50+
return {
51+
...entry,
52+
code: `<template>${entry.code}</template>`,
53+
output: entry.output ? `<template>${entry.output}</template>` : entry.output,
54+
};
55+
}
56+
57+
const gjsRuleTester = new RuleTester({
958
parser: require.resolve('ember-eslint-parser'),
1059
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
1160
});
1261

13-
ruleTester.run('template-no-unnecessary-curly-parens', rule, {
14-
valid: [
15-
'<template>{{helper param}}</template>',
16-
'<template>{{#if condition}}text{{/if}}</template>',
17-
'<template>{{this.property}}</template>',
18-
19-
'<template>{{foo}}</template>',
20-
'<template>{{this.foo}}</template>',
21-
'<template>{{(helper)}}</template>',
22-
'<template>{{(this.helper)}}</template>',
23-
'<template>{{concat "a" "b"}}</template>',
24-
'<template>{{concat (capitalize "foo") "-bar"}}</template>',
25-
],
26-
invalid: [
27-
{
28-
code: '<template>{{(helper value)}}</template>',
29-
output: '<template>{{helper value}}</template>',
30-
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
31-
},
32-
{
33-
code: '<template>{{(concat "a" "b")}}</template>',
34-
output: '<template>{{concat "a" "b"}}</template>',
35-
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
36-
},
37-
{
38-
code: '<template>{{(if condition "yes" "no")}}</template>',
39-
output: '<template>{{if condition "yes" "no"}}</template>',
40-
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
41-
},
42-
43-
{
44-
code: '<template><FooBar @x="{{index}}X{{(someHelper foo)}}" /></template>',
45-
output: '<template><FooBar @x="{{index}}X{{someHelper foo}}" /></template>',
46-
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
47-
},
48-
{
49-
code: '<template><FooBar @x="{{index}}XY{{(someHelper foo)}}" /></template>',
50-
output: '<template><FooBar @x="{{index}}XY{{someHelper foo}}" /></template>',
51-
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
52-
},
53-
{
54-
code: '<template><FooBar @x="{{index}}--{{(someHelper foo)}}" /></template>',
55-
output: '<template><FooBar @x="{{index}}--{{someHelper foo}}" /></template>',
56-
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
57-
},
58-
{
59-
code: '<template>{{(helper a="b")}}</template>',
60-
output: '<template>{{helper a="b"}}</template>',
61-
errors: [{ messageId: 'noUnnecessaryCurlyParens' }],
62-
},
63-
],
62+
gjsRuleTester.run('template-no-unnecessary-curly-parens', rule, {
63+
valid: validHbs.map(wrapTemplate),
64+
invalid: invalidHbs.map(wrapTemplate),
6465
});
6566

6667
const hbsRuleTester = new RuleTester({
@@ -72,39 +73,6 @@ const hbsRuleTester = new RuleTester({
7273
});
7374

7475
hbsRuleTester.run('template-no-unnecessary-curly-parens', rule, {
75-
valid: [
76-
'{{foo}}',
77-
'{{this.foo}}',
78-
'{{(helper)}}',
79-
'{{(this.helper)}}',
80-
'{{concat "a" "b"}}',
81-
'{{concat (capitalize "foo") "-bar"}}',
82-
],
83-
invalid: [
84-
{
85-
code: '<FooBar @x="{{index}}X{{(someHelper foo)}}" />',
86-
output: '<FooBar @x="{{index}}X{{someHelper foo}}" />',
87-
errors: [{ message: 'Unnecessary parentheses enclosing statement.' }],
88-
},
89-
{
90-
code: '<FooBar @x="{{index}}XY{{(someHelper foo)}}" />',
91-
output: '<FooBar @x="{{index}}XY{{someHelper foo}}" />',
92-
errors: [{ message: 'Unnecessary parentheses enclosing statement.' }],
93-
},
94-
{
95-
code: '<FooBar @x="{{index}}--{{(someHelper foo)}}" />',
96-
output: '<FooBar @x="{{index}}--{{someHelper foo}}" />',
97-
errors: [{ message: 'Unnecessary parentheses enclosing statement.' }],
98-
},
99-
{
100-
code: '{{(concat "a" "b")}}',
101-
output: '{{concat "a" "b"}}',
102-
errors: [{ message: 'Unnecessary parentheses enclosing statement.' }],
103-
},
104-
{
105-
code: '{{(helper a="b")}}',
106-
output: '{{helper a="b"}}',
107-
errors: [{ message: 'Unnecessary parentheses enclosing statement.' }],
108-
},
109-
],
76+
valid: validHbs,
77+
invalid: invalidHbs,
11078
});

0 commit comments

Comments
 (0)