eslint-plugin-payfit
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -28,25 +28,5 @@ /** | ||
// visitor functions for different types of nodes | ||
VariableDeclarator: (node) => { | ||
if ( | ||
node.init && | ||
node.init.callee && | ||
node.init.callee.name === 'ObjectId' && | ||
node.init.type !== 'NewExpression' | ||
) { | ||
context.report({ | ||
node, | ||
message: 'Mongo ObjectId must be used with "new" keyword.', | ||
fix: (fixer) => { | ||
const sourceCode = context.getSourceCode() | ||
const fixedText = sourceCode.getText(node).split('ObjectId').join('new ObjectId') | ||
return fixer.replaceText(node, fixedText) | ||
}, | ||
}) | ||
} | ||
if ( | ||
node.init && | ||
node.init.type === 'ObjectExpression' && | ||
node.init.properties.length > 0 | ||
) { | ||
node.init.properties.forEach((property) => { | ||
ObjectExpression(node) { | ||
if (node.properties && node.properties.length > 0) { | ||
node.properties.forEach((property) => { | ||
if ( | ||
@@ -63,5 +43,3 @@ property.value && | ||
const text = context.getSourceCode().getText(node) | ||
const fixedText = text | ||
.split('ObjectId') | ||
.join('new ObjectId') | ||
const fixedText = text.split('ObjectId').join('new ObjectId') | ||
return fixer.replaceText(node, fixedText) | ||
@@ -74,3 +52,21 @@ }, | ||
}, | ||
VariableDeclarator: (node) => { | ||
if ( | ||
node.init && | ||
node.init.callee && | ||
node.init.callee.name === 'ObjectId' && | ||
node.init.type !== 'NewExpression' | ||
) { | ||
context.report({ | ||
node, | ||
message: 'Mongo ObjectId must be used with "new" keyword.', | ||
fix: (fixer) => { | ||
const text = context.getSourceCode().getText(node) | ||
const fixedText = text.split('ObjectId').join('new ObjectId') | ||
return fixer.replaceText(node, fixedText) | ||
}, | ||
}) | ||
} | ||
}, | ||
}), | ||
} |
{ | ||
"name": "eslint-plugin-payfit", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "eslint-payfit-plugin", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -34,2 +34,12 @@ /** | ||
{ | ||
code: 'callToFunction({ id: ObjectId() })', | ||
errors: [ | ||
{ | ||
message: 'Mongo ObjectId must be used with "new" keyword.', | ||
type: 'ObjectExpression', | ||
}, | ||
], | ||
output: 'callToFunction({ id: new ObjectId() })', | ||
}, | ||
{ | ||
code: 'var invalid = { id: ObjectId(), createdAt: Date(), companyId: ObjectId() }', | ||
@@ -39,7 +49,7 @@ errors: [ | ||
message: 'Mongo ObjectId must be used with "new" keyword.', | ||
type: 'VariableDeclarator', | ||
type: 'ObjectExpression', | ||
}, | ||
{ | ||
message: 'Mongo ObjectId must be used with "new" keyword.', | ||
type: 'VariableDeclarator', | ||
type: 'ObjectExpression', | ||
}, | ||
@@ -46,0 +56,0 @@ ], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7476
134