eslint-plugin-loopback-options
Advanced tools
Comparing version 0.0.0 to 1.0.0
@@ -26,2 +26,17 @@ /** | ||
// variables should be defined here | ||
function validateExp(exp, node) { | ||
if (!(exp && exp.callee && exp.callee.property)) { | ||
return; | ||
} | ||
if (exp.callee.property.name === 'save' && exp.arguments.length === 0) { | ||
context.report(node, 'Options should be passed to save() function'); | ||
} | ||
if ( | ||
exp.callee.property.name === 'create' && | ||
exp.arguments[exp.arguments.length - 1].name !== 'options' | ||
) { | ||
context.report(node, "'options' should be the last argument passed to create() function"); | ||
} | ||
} | ||
//---------------------------------------------------------------------- | ||
@@ -32,18 +47,33 @@ // Public | ||
return { | ||
ExpressionStatement: function(node) { | ||
if (node.expression && node.expression.callee) { | ||
var exp = node.expression; | ||
if (exp.callee.property.name === 'save' && exp.arguments.length === 0) { | ||
context.report(node, 'Options should be passed to save() function'); | ||
} | ||
if ( | ||
exp.callee.property.name === 'create' && | ||
exp.arguments[exp.arguments.length - 1].name !== 'options' | ||
) { | ||
context.report( | ||
node, | ||
"'options' should be the last argument passed to create() function", | ||
); | ||
} | ||
// ExpressionStatement: function(node) { | ||
// if (node.expression && node.expression.callee) { | ||
// var exp = node.expression; | ||
// if (exp.callee.property.name === 'save' && exp.arguments.length === 0) { | ||
// context.report(node, 'Options should be passed to save() function'); | ||
// } | ||
// if ( | ||
// exp.callee.property.name === 'create' && | ||
// exp.arguments[exp.arguments.length - 1].name !== 'options' | ||
// ) { | ||
// context.report( | ||
// node, | ||
// "'options' should be the last argument passed to create() function", | ||
// ); | ||
// } | ||
// } | ||
// }, | ||
CallExpression: function(node) { | ||
const memberExpression = node.callee; | ||
if (!(memberExpression && memberExpression.property)) { | ||
return; | ||
} | ||
if (memberExpression.property.name === 'save' && node.arguments.length === 0) { | ||
context.report(node, "'options' should be passed to save() function"); | ||
} | ||
if ( | ||
memberExpression.property.name === 'create' && | ||
node.arguments[node.arguments.length - 1].name !== 'options' | ||
) { | ||
context.report(node, "'options' should be the last argument passed to create() function"); | ||
} | ||
}, | ||
@@ -50,0 +80,0 @@ }; |
{ | ||
"name": "eslint-plugin-loopback-options", | ||
"version": "0.0.0", | ||
"version": "1.0.0", | ||
"description": "Checks if options argument is passed to write functions", | ||
"keywords": ["eslint", "eslintplugin", "eslint-plugin"], | ||
"keywords": [ | ||
"eslint", | ||
"eslintplugin", | ||
"eslint-plugin" | ||
], | ||
"author": "Jibin Mathews <jibinmathews7@gmail.com>", | ||
@@ -7,0 +11,0 @@ "main": "lib/index.js", |
@@ -18,8 +18,41 @@ /** | ||
RuleTester.setDefaultConfig({ | ||
parserOptions: { | ||
ecmaVersion: 2017, | ||
sourceType: 'module', | ||
}, | ||
}); | ||
var ruleTester = new RuleTester(); | ||
ruleTester.run('options-required', rule, { | ||
valid: ['ticket.save(options)', 'Model.create({}, options)', 'Model.create(objName, options)'], | ||
valid: [ | ||
'ticket.save(options)', | ||
'Model.create({}, options)', | ||
'Model.create(objName, options)', | ||
'async () => { await ticket.save(options) }', | ||
'async () => { await Model.create({}, options)}', | ||
'async () => { await Model.create(objName, options) }', | ||
], | ||
invalid: [ | ||
{ | ||
code: 'async () => { await ticket.save() }', | ||
errors: [ | ||
{ | ||
message: 'Options should be passed to save() function', | ||
type: 'CallExpression', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'async () => { await Model.create(modelObj) }', | ||
errors: [ | ||
{ | ||
message: "'options' should be the last argument passed to create() function", | ||
type: 'CallExpression', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'ticket.save()', | ||
@@ -29,3 +62,3 @@ errors: [ | ||
message: 'Options should be passed to save() function', | ||
type: 'ExpressionStatement', | ||
type: 'CallExpression', | ||
}, | ||
@@ -39,3 +72,3 @@ ], | ||
message: "'options' should be the last argument passed to create() function", | ||
type: 'ExpressionStatement', | ||
type: 'CallExpression', | ||
}, | ||
@@ -42,0 +75,0 @@ ], |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
38848
157
1