Skip to content

Determine Property Types in Native Classes #2279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions lib/utils/ember.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ module.exports = {
isEmberHelper,
isEmberProxy,

isActionMethod,
isSingleLineAccessor,
isSingleLineFn,
isMultiLineAccessor,
isMultiLineFn,
isFunctionExpression,

Expand Down Expand Up @@ -478,10 +481,12 @@ function isObjectProp(node) {
return types.isObjectExpression(node.value);
}

function isCustomProp(property) {
const value = property.value;
function isCustomProp(property, isNativeClass = false) {
const { value } = property;
if (!value) {
return false;
// Native classes allow for empty values
// e.g. class Example { foo; }
return isNativeClass;
}
const isCustomObjectProp = types.isObjectExpression(value) && property.key.name !== 'actions';

Expand Down Expand Up @@ -509,6 +514,13 @@ function isActionsProp(property) {
);
}

function isActionMethod(property) {
if (property?.type === 'MethodDefinition') {
return decoratorUtils.hasDecorator(property, 'action');
}
return false;
}

function isComponentLifecycleHookName(name) {
return [
'didDestroyElement',
Expand Down Expand Up @@ -635,6 +647,13 @@ function getEmberImportAliasName(importDeclaration) {
return importDeclaration.specifiers[0].local.name;
}

function isSingleLineAccessor(property) {
return (
(types.isPropAccessor(property) || decoratorUtils.hasDecorator(property, 'computed')) &&
utils.getSize(property) === 1
);
}

function isSingleLineFn(property, importedEmberName, importedObserverName) {
return (
(types.isMethodDefinition(property) && utils.getSize(property) === 1) ||
Expand All @@ -647,6 +666,13 @@ function isSingleLineFn(property, importedEmberName, importedObserverName) {
);
}

function isMultiLineAccessor(property) {
return (
(types.isPropAccessor(property) || decoratorUtils.hasDecorator(property, 'computed')) &&
utils.getSize(property) > 1
);
}

function isMultiLineFn(property, importedEmberName, importedObserverName) {
return (
(types.isMethodDefinition(property) && utils.getSize(property) > 1) ||
Expand All @@ -663,7 +689,8 @@ function isFunctionExpression(property) {
return (
types.isFunctionExpression(property) ||
types.isArrowFunctionExpression(property) ||
types.isCallWithFunctionExpression(property)
types.isCallWithFunctionExpression(property) ||
types.isCallWithArrowFunctionExpression(property)
);
}

Expand Down
90 changes: 90 additions & 0 deletions lib/utils/property-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

module.exports = {
determinePropertyType,
determinePropertyTypeInNativeClass,
reportUnorderedProperties,
addBackwardsPosition,
};
Expand Down Expand Up @@ -148,6 +149,95 @@
return 'unknown';
}

function determinePropertyTypeInNativeClass(

Check failure on line 152 in lib/utils/property-order.js

View workflow job for this annotation

GitHub Actions / self-lint

Function 'determinePropertyTypeInNativeClass' has a complexity of 31. Maximum allowed is 20
node,
parentType,
ORDER,
importedEmberName,
importedInjectName,
importedObserverName,
importedControllerName
) {
if (node === undefined) {
return 'unknown';
}

if (ember.isInjectedServiceProp(node, importedEmberName, importedInjectName)) {
return 'service';
}

if (ember.isInjectedControllerProp(node, importedEmberName, importedControllerName)) {
return 'controller';
}

if (node.type === 'MethodDefinition' && node.key.name === 'constructor') {
return 'constructor';
}

if (parentType === 'component') {

Check failure on line 177 in lib/utils/property-order.js

View workflow job for this annotation

GitHub Actions / self-lint

Use `switch` instead of multiple `else-if`
if (node.type === 'MethodDefinition' && ember.isComponentLifecycleHook(node)) {
return node.key.name;
}
} else if (parentType === 'controller') {
if (
node.key !== undefined &&
node.key.type === 'Identifier' &&
node.key.name === 'queryParams'
) {
return 'query-params';
} else if (ember.isControllerDefaultProp(node)) {
return 'inherited-property';
}
} else if (parentType === 'model') {
if (decoratorUtils.isClassPropertyOrPropertyDefinitionWithDecorator(node, 'attr')) {
return 'attribute';
} else if (ember.isRelation(node)) {
return 'relationship';
}
} else if (parentType === 'route') {
if (ember.isRouteDefaultProp(node)) {
return 'inherited-property';
} else if (ember.isRouteLifecycleHook(node)) {
return node.key.name;
}
}

if (parentType !== 'model' && ember.isActionMethod(node)) {
return 'action';
}

if (ember.isSingleLineAccessor(node)) {
return 'single-line-accessor';
}

if (ember.isMultiLineAccessor(node)) {
return 'multi-line-accessor';
}

const propName = getNodeKeyName(node);
const possibleOrderName = `custom:${propName}`;
if (ORDER.includes(possibleOrderName)) {
return possibleOrderName;
}

if (
(node.type === 'ClassProperty' || node.type === 'PropertyDefinition') &&
ember.isCustomProp(node, true)
) {
return 'property';
}

if (node.value && ember.isFunctionExpression(node.value)) {
if (utils.isEmptyMethod(node)) {
return 'empty-method';
}

return 'method';
}

return 'unknown';
}

function getOrder(ORDER, type) {
for (let i = 0, len = ORDER.length; i < len; i++) {
const value = ORDER[i];
Expand Down
42 changes: 42 additions & 0 deletions lib/utils/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
isAssignmentExpression,
isBinaryExpression,
isCallExpression,
isCallWithArrowFunctionExpression,
isCallWithFunctionExpression,
isClassDeclaration,
isClassPropertyOrPropertyDefinition,
Expand All @@ -36,6 +37,7 @@
isObjectPattern,
isOptionalCallExpression,
isOptionalMemberExpression,
isPropAccessor,
isProperty,
isReturnStatement,
isSpreadElement,
Expand Down Expand Up @@ -113,6 +115,36 @@
return node !== undefined && node.type === 'CallExpression';
}

/**
* Check whether or not a node is a CallExpression that has a
* ArrowExpression as the first argument
*
* @example
* ```js
* // Native class
* tSomeAction = mysteriousFnc(() => {})
*
* // Classic Ember object
* tSomeAction: mysteriousFnc(() => {})
* ```
*
* @param {Object} node The node to check
* @return {boolean} Whether or not the node is a call with a arrow function expression as the first argument
*/
function isCallWithArrowFunctionExpression(node) {
if (!node?.type === 'CallExpression') {
return false;
}
const callObj = node.callee?.type === 'MemberExpression' ? node.callee.object : node;

Check failure on line 138 in lib/utils/types.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

tests/lib/rules/order-in-routes.js > order-in-routes > valid > export default Route.extend({ ...foo });

TypeError: Cannot read properties of undefined (reading 'callee') Occurred while linting <input>:1 Rule: "order-in-routes" ❯ Object.isCallWithArrowFunctionExpression lib/utils/types.js:138:24 ❯ isFunctionExpression lib/utils/ember.js:693:11 ❯ Object.isRouteLifecycleHook lib/utils/ember.js:506:10 ❯ determinePropertyType lib/utils/property-order.js:105:22 ❯ reportUnorderedProperties lib/utils/property-order.js:310:18 ❯ CallExpression lib/rules/order-in-routes.js:114:9 ❯ ruleErrorHandler node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1076:28 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58 ❯ Object.emit node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38 ❯ NodeEventGenerator.applySelector node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26 ❯ NodeEventGenerator.applySelectors node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:326:22 ❯ NodeEventGenerator.enterNode node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:340:14 ❯ CodePathAnalyzer.enterNode node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1111:32 ❯ runRules node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1106:15 ❯ Linter._verifyWithoutProcessors node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1355:31 ❯ Linter.verify node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1453:57 ❯ runRuleForItem node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:832:35 ❯ testValidTemplate node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:896:28 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:1181:33 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { ruleId: 'order-in-routes', currentNode: { type: 'CallExpression', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 39, index: 39, constructor: 'Function<Position>' }, filename: undefined, identifierName: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 39 ], callee: { type: 'MemberExpression', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 27, index: 27, constructor: 'Function<Position>' }, filename: undefined, identifierName: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 27 ], object: { type: 'Identifier', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 20, index: 20, constructor: 'Function<Position>' }, filename: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 20 ], name: 'Route', parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anonymous>' }, computed: false, property: { type: 'Identifier', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 21, index: 21, constructor: 'Function<Position>' }, end: { line: 1, column: 27, index: 27, constructor: 'Function<Position>' }, filename: undefined, constructor: 'Function<SourceLocation>' }, range: [ 21, 27 ], name: 'extend', parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anonymous>' }, optional: false, parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anony

Check failure on line 138 in lib/utils/types.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 22.x)

tests/lib/rules/order-in-routes.js > order-in-routes > valid > export default Route.extend({ ...foo });

TypeError: Cannot read properties of undefined (reading 'callee') Occurred while linting <input>:1 Rule: "order-in-routes" ❯ Object.isCallWithArrowFunctionExpression lib/utils/types.js:138:24 ❯ isFunctionExpression lib/utils/ember.js:693:11 ❯ Object.isRouteLifecycleHook lib/utils/ember.js:506:10 ❯ determinePropertyType lib/utils/property-order.js:105:22 ❯ reportUnorderedProperties lib/utils/property-order.js:310:18 ❯ CallExpression lib/rules/order-in-routes.js:114:9 ❯ ruleErrorHandler node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1076:28 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58 ❯ Object.emit node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38 ❯ NodeEventGenerator.applySelector node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26 ❯ NodeEventGenerator.applySelectors node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:326:22 ❯ NodeEventGenerator.enterNode node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:340:14 ❯ CodePathAnalyzer.enterNode node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1111:32 ❯ runRules node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1106:15 ❯ Linter._verifyWithoutProcessors node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1355:31 ❯ Linter.verify node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1453:57 ❯ runRuleForItem node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:832:35 ❯ testValidTemplate node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:896:28 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:1181:33 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { ruleId: 'order-in-routes', currentNode: { type: 'CallExpression', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 39, index: 39, constructor: 'Function<Position>' }, filename: undefined, identifierName: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 39 ], callee: { type: 'MemberExpression', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 27, index: 27, constructor: 'Function<Position>' }, filename: undefined, identifierName: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 27 ], object: { type: 'Identifier', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 20, index: 20, constructor: 'Function<Position>' }, filename: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 20 ], name: 'Route', parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anonymous>' }, computed: false, property: { type: 'Identifier', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 21, index: 21, constructor: 'Function<Position>' }, end: { line: 1, column: 27, index: 27, constructor: 'Function<Position>' }, filename: undefined, constructor: 'Function<SourceLocation>' }, range: [ 21, 27 ], name: 'extend', parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anonymous>' }, optional: false, parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anony

Check failure on line 138 in lib/utils/types.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 20.x)

tests/lib/rules/order-in-routes.js > order-in-routes > valid > export default Route.extend({ ...foo });

TypeError: Cannot read properties of undefined (reading 'callee') Occurred while linting <input>:1 Rule: "order-in-routes" ❯ Object.isCallWithArrowFunctionExpression lib/utils/types.js:138:24 ❯ isFunctionExpression lib/utils/ember.js:693:11 ❯ Object.isRouteLifecycleHook lib/utils/ember.js:506:10 ❯ determinePropertyType lib/utils/property-order.js:105:22 ❯ reportUnorderedProperties lib/utils/property-order.js:310:18 ❯ CallExpression lib/rules/order-in-routes.js:114:9 ❯ ruleErrorHandler node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1076:28 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58 ❯ Object.emit node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38 ❯ NodeEventGenerator.applySelector node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26 ❯ NodeEventGenerator.applySelectors node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:326:22 ❯ NodeEventGenerator.enterNode node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:340:14 ❯ CodePathAnalyzer.enterNode node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1111:32 ❯ runRules node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1106:15 ❯ Linter._verifyWithoutProcessors node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1355:31 ❯ Linter.verify node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1453:57 ❯ runRuleForItem node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:832:35 ❯ testValidTemplate node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:896:28 ❯ node_modules/.pnpm/[email protected]/node_modules/eslint/lib/rule-tester/rule-tester.js:1181:33 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { ruleId: 'order-in-routes', currentNode: { type: 'CallExpression', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 39, index: 39, constructor: 'Function<Position>' }, filename: undefined, identifierName: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 39 ], callee: { type: 'MemberExpression', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 27, index: 27, constructor: 'Function<Position>' }, filename: undefined, identifierName: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 27 ], object: { type: 'Identifier', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 15, index: 15, constructor: 'Function<Position>' }, end: { line: 1, column: 20, index: 20, constructor: 'Function<Position>' }, filename: undefined, constructor: 'Function<SourceLocation>' }, range: [ 15, 20 ], name: 'Route', parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anonymous>' }, computed: false, property: { type: 'Identifier', start: '<unserializable>: Use node.range[0] instead of node.start', end: '<unserializable>: Use node.range[1] instead of node.end', loc: { start: { line: 1, column: 21, index: 21, constructor: 'Function<Position>' }, end: { line: 1, column: 27, index: 27, constructor: 'Function<Position>' }, filename: undefined, constructor: 'Function<SourceLocation>' }, range: [ 21, 27 ], name: 'extend', parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anonymous>' }, optional: false, parent: [Circular], constructor: 'Function<Node>', __clone: 'Function<anony
const firstArg = callObj.arguments ? callObj.arguments[0] : null;
return (
callObj !== undefined &&
callObj?.type === 'CallExpression' &&
firstArg &&
firstArg?.type === 'ArrowFunctionExpression'
);
}

/**
* Check whether or not a node is a CallExpression that has a FunctionExpression
* as first argument, eg.:
Expand Down Expand Up @@ -358,6 +390,16 @@
return node.type === 'OptionalMemberExpression';
}

/**
* Check whether a node is a property accessor (get/set).
*
* @param {Node} node the node to check
* @returns {boolean} whether the node is an accessor
*/
function isPropAccessor(node) {
return node?.type === 'MethodDefinition' && ['get', 'set'].includes(node?.kind);
}

/**
* Check whether or not a node is an Property.
*
Expand Down
53 changes: 51 additions & 2 deletions tests/lib/utils/ember-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const emberUtils = require('../../../lib/utils/ember');
const { FauxContext } = require('../../helpers/faux-context');

function parse(code) {
return babelESLintParse(code).body[0].expression;
const { body } = babelESLintParse(code);
const [firstBodyNode] = body;
if (firstBodyNode.type === 'ClassDeclaration') {
// return first node within ClassBody
return firstBodyNode.body.body[0];
}
return firstBodyNode.expression;
}

function getProperty(code) {
Expand Down Expand Up @@ -320,7 +326,7 @@ describe('isEmberComponent', () => {
});
});

describe('isGlimerComponent', () => {
describe('isGlimmerComponent', () => {
describe("should check if it's a Glimmer Component", () => {
it('should detect Component when using native classes', () => {
const context = new FauxContext(`
Expand Down Expand Up @@ -1475,6 +1481,18 @@ describe('isActionsProp', () => {
});
});

describe('isActionMethod', () => {
const node = parse(
`class Test {
@action foo() {}
}`
);

it('should be actions method', () => {
expect(emberUtils.isActionMethod(node)).toBeTruthy();
});
});

describe('getModuleProperties', () => {
it("returns module's properties", () => {
const code = `
Expand Down Expand Up @@ -1535,6 +1553,18 @@ describe('getModuleProperties', () => {
});
});

describe('isSingleLineAccessor', () => {
const node = parse(
`class Test {
get foo() { return 'bar'; }
}`
);

it('should be single line accessor', () => {
expect(emberUtils.isSingleLineAccessor(node)).toBeTruthy();
});
});

describe('isSingleLineFn', () => {
const property = getProperty(`test = {
test: computed.or('asd', 'qwe')
Expand Down Expand Up @@ -1563,6 +1593,20 @@ describe('isSingleLineFn', () => {
});
});

describe('isMultiLineAccessor', () => {
const node = parse(
`class Test {
get foo() {
return 'bar';
}
}`
);

it('should be multi line accessor', () => {
expect(emberUtils.isMultiLineAccessor(node)).toBeTruthy();
});
});

describe('isMultiLineFn', () => {
const property = getProperty(`test = {
test: computed('asd', function() {
Expand Down Expand Up @@ -1616,6 +1660,11 @@ describe('isFunctionExpression', () => {
test: () => {}
}`);
expect(emberUtils.isFunctionExpression(property.value)).toBeTruthy();

property = getProperty(`test = {
test: someFn(() => {})
}`);
expect(emberUtils.isFunctionExpression(property.value)).toBeTruthy();
});
});

Expand Down
Loading
Loading