New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-loopback-options

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-loopback-options - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

60

lib/rules/options-required.js

@@ -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 @@ ],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc