Skip to content

Commit

Permalink
Merge pull request #4 from michoelchaikin/master
Browse files Browse the repository at this point in the history
Add support for object member assignment return pattern to entry-points rules
  • Loading branch information
acdvs authored Dec 24, 2020
2 parents be2b5c9 + aa20cd7 commit 380e1e3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/rules/entry-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ module.exports = {
}
}

if (returnArgument && returnArgument.type === 'Identifier') {
const returnAssignments = callbackBody.filter(n =>
n.type === 'ExpressionStatement' &&
n.expression.left.type === 'MemberExpression' &&
n.expression.left.object.name === returnArgument.name &&
scriptTypeMap[scriptType].entryPoints.includes(n.expression.left.property.name)
);
if (returnAssignments.length > 0) {
hasValidEntryPoint = true;
}
}

if (!hasValidEntryPoint) {
context.report({
node: returnStatement || callback,
Expand Down
39 changes: 39 additions & 0 deletions tests/rules/entry-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ ruleTester.run('entry-points', rule, {
' return { somethingElse: x };',
'});'
].join('\n')
},
{
code: [
'/**',
' * @NScriptType ClientScript',
' */',
'define([], function() {',
' var exports = {};',
' exports.pageInit = x;',
' return exports;',
'});'
].join('\n')
}
],

Expand Down Expand Up @@ -137,6 +149,33 @@ ruleTester.run('entry-points', rule, {
'});'
].join('\n'),
errors: [{ messageId: 'returnEntryPoint', data: { type: 'Restlet' }}]
},
{
code: [
'/**',
' * @NScriptType ClientScript',
' */',
'define([], function() {',
' var exports = {};',
' exports.notAnEntryPoint = x;',
' return exports;',
'});'
].join('\n'),
errors: [{ messageId: 'returnEntryPoint', data: { type: 'ClientScript' }}]
},
{
code: [
'/**',
' * @NScriptType ClientScript',
' */',
'define([], function() {',
' var exports = {};',
' var notTheReturnObject = {};',
' notTheReturnObject.pageInit = x;',
' return exports;',
'});'
].join('\n'),
errors: [{ messageId: 'returnEntryPoint', data: { type: 'ClientScript' }}]
}
]
});

0 comments on commit 380e1e3

Please sign in to comment.