Skip to content

Commit 8e3ee24

Browse files
author
Michał Sajnóg
authored
Treat conditional expressions as custom properties (#31)
1 parent 54ddf7e commit 8e3ee24

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

lib/utils/ember.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ function isObjectProp(node) {
126126

127127
function isCustomProp(property) {
128128
var value = property.value;
129-
var isCustomObjectProp = utils.isObjectExpression(property.value) && property.key.name !== 'actions';
129+
var isCustomObjectProp = utils.isObjectExpression(value) && property.key.name !== 'actions';
130130

131131
return utils.isLiteral(value) ||
132132
utils.isIdentifier(value) ||
133133
utils.isArrayExpression(value) ||
134-
isCustomObjectProp;
134+
isCustomObjectProp ||
135+
utils.isConditionalExpression(value);
135136
}
136137

137138
function isModelProp(property) {

lib/utils/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
isNewExpression: isNewExpression,
1212
isCallWithFunctionExpression: isCallWithFunctionExpression,
1313
isThisExpression: isThisExpression,
14+
isConditionalExpression: isConditionalExpression,
1415
getSize: getSize,
1516
parseCallee: parseCallee,
1617
parseArgs: parseArgs,
@@ -151,6 +152,16 @@ function isThisExpression(node) {
151152
return node !== undefined && node.type === 'ThisExpression';
152153
}
153154

155+
/**
156+
* Check whether or not a node is a ConditionalExpression.
157+
*
158+
* @param {Object} node The node to check.
159+
* @returns {boolean} Whether or not the node is a ConditionalExpression.
160+
*/
161+
function isConditionalExpression(node) {
162+
return node !== undefined && node.type === 'ConditionalExpression';
163+
}
164+
154165
/**
155166
* Get size of expression in lines
156167
*

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ eslintTester.run('order-in-components', rule, {
304304
],
305305
}],
306306
},
307+
{
308+
code: `export default Component.extend({
309+
role: "sloth",
310+
qwe: foo ? 'bar' : null,
311+
abc: [],
312+
def: {},
313+
314+
ghi: alias("def")
315+
});`,
316+
parserOptions: {ecmaVersion: 6, sourceType: "module"},
317+
},
307318
],
308319
invalid: [
309320
{

tests/lib/utils/ember-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ describe('isCustomProp', function() {
144144
node = getProperty(`test = { test: {} }`);
145145
assert.ok(emberUtils.isCustomProp(node));
146146

147+
node = getProperty(`test = { test: foo ? 'bar': 'baz' }`);
148+
assert.ok(emberUtils.isCustomProp(node));
149+
147150
node = getProperty(`test = { actions: {} }`);
148151
assert.notOk(emberUtils.isCustomProp(node));
149152
});

tests/lib/utils/utils-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ describe('isThisExpression', function() {
116116
});
117117
});
118118

119+
describe('isConditionalExpression', function() {
120+
const node = parse(`test = true ? 'asd' : 'qwe'`).right;
121+
122+
it('should check if node is a conditional expression', function() {
123+
assert.ok(utils.isConditionalExpression(node));
124+
});
125+
});
126+
119127
describe('getSize', function() {
120128
const node = parse('some = {\nfew: "line",\nheight: "statement",\nthat: "should",\nhave: "6 lines",\n};');
121129

0 commit comments

Comments
 (0)