Skip to content

Commit d7ade4b

Browse files
authored
Merge pull request #670 from cdtinney/fix-order-in-rules-template-literals
Update `order-in-*` rules to consider template literals as properties
2 parents 412daa6 + f37b280 commit d7ade4b

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

lib/utils/ember.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ function isCustomProp(property) {
278278

279279
return (
280280
types.isLiteral(value) ||
281+
types.isTemplateLiteral(value) ||
281282
types.isIdentifier(value) ||
282283
types.isArrayExpression(value) ||
283284
types.isUnaryExpression(value) ||

tests/lib/rules/order-in-components.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ eslintTester.run('order-in-components', rule, {
2626
levelOfHappiness: computed("attitude", "health", () => {
2727
}),
2828
29+
actions: {}
30+
});`,
31+
`export default Component.extend({
32+
role: ${`${'sloth'}`},
33+
34+
vehicle: alias("car"),
35+
36+
levelOfHappiness: computed("attitude", "health", () => {
37+
}),
38+
2939
actions: {}
3040
});`,
3141
`export default Component.extend({
@@ -345,6 +355,33 @@ eslintTester.run('order-in-components', rule, {
345355
},
346356
],
347357
},
358+
{
359+
code: `export default Component.extend({
360+
actions: {},
361+
362+
role: ${`${'sloth'}`},
363+
364+
vehicle: alias("car"),
365+
366+
levelOfHappiness: computed("attitude", "health", () => {
367+
})
368+
});`,
369+
errors: [
370+
{
371+
message: 'The "role" property should be above the actions hash on line 2',
372+
line: 4,
373+
},
374+
{
375+
message: 'The "vehicle" single-line function should be above the actions hash on line 2',
376+
line: 6,
377+
},
378+
{
379+
message:
380+
'The "levelOfHappiness" multi-line function should be above the actions hash on line 2',
381+
line: 8,
382+
},
383+
],
384+
},
348385
{
349386
code: `export default Component.extend({
350387
vehicle: alias("car"),

tests/lib/utils/ember-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,9 @@ describe('isCustomProp', () => {
834834
node = getProperty("test = { test: 'someLiteral' }");
835835
expect(emberUtils.isCustomProp(node)).toBeTruthy();
836836

837+
node = getProperty("test = { test: `foo${'bar'}` }");
838+
expect(emberUtils.isCustomProp(node)).toBeTruthy();
839+
837840
node = getProperty('test = { test: someIdentifier }');
838841
expect(emberUtils.isCustomProp(node)).toBeTruthy();
839842

tests/lib/utils/property-order-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ describe('determinePropertyType', () => {
188188
expect(propertyOrder.determinePropertyType(node, 'component')).toStrictEqual('property');
189189
});
190190

191+
it('should determine template literals as properties', () => {
192+
const context = new FauxContext(
193+
`export default Component.extend({
194+
foo: ${`foo${"bar"}`}
195+
});`
196+
);
197+
const node = context.ast.body[0].declaration.arguments[0].properties[0];
198+
expect(propertyOrder.determinePropertyType(node, 'component')).toStrictEqual('property');
199+
});
200+
191201
it('should determine empty methods', () => {
192202
const context = new FauxContext(
193203
`export default Component.extend({

0 commit comments

Comments
 (0)