eslint-plugin-should-promised
Advanced tools
Comparing version 1.0.8 to 2.0.0
'use strict'; | ||
var assertion_properties = [ | ||
'Promise', | ||
'fulfilled', | ||
'fulfilledWith', | ||
'rejected', | ||
'rejectedWith', | ||
'finally', | ||
'eventually' | ||
]; | ||
function isPromiseAssertionProperty(property) { | ||
var name = property && (property.name || property.value); | ||
return name && assertion_properties.indexOf(name) !== -1; | ||
const name = property && (property.name || property.value); | ||
return name === 'Promise' || | ||
name === 'fulfilled' || | ||
name === 'fulfilledWith' || | ||
name === 'rejected' || | ||
name === 'rejectedWith' || | ||
name === 'finally' || | ||
name === 'eventually'; | ||
} | ||
function ancestorReturns(parents) { | ||
for (var i = parents.length - 1; i >= 0; i--) { | ||
var parent = parents[i]; | ||
var type = parent.type; | ||
if (type === 'ReturnStatement' || type === 'YieldExpression') { | ||
for (let i = parents.length - 1; i >= 0; i--) { | ||
let parent = parents[i]; | ||
let type = parent.type; | ||
if (type === 'ReturnStatement' || type === 'AwaitExpression' || type === 'YieldExpression') { | ||
return true; | ||
@@ -36,16 +32,22 @@ } | ||
module.exports = function(context) { | ||
return { | ||
MemberExpression: function(node) { | ||
if (!isPromiseAssertionProperty(node.property)) { | ||
return; | ||
} | ||
module.exports = { | ||
meta: { | ||
docs: {} | ||
}, | ||
if (ancestorReturns(context.getAncestors(node))) { | ||
return; | ||
create(context) { | ||
return { | ||
MemberExpression(node) { | ||
if (!isPromiseAssertionProperty(node.property)) { | ||
return; | ||
} | ||
if (ancestorReturns(context.getAncestors(node))) { | ||
return; | ||
} | ||
context.report(node.property, 'Promise assertion must return, await or yield.'); | ||
} | ||
context.report(node.property, 'Promise assertion must return or await.'); | ||
} | ||
}; | ||
}; | ||
} | ||
}; |
{ | ||
"name": "eslint-plugin-should-promised", | ||
"version": "1.0.8", | ||
"description": "Eslint rule for checking that should-promised assertions return", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", | ||
"lib" | ||
], | ||
"scripts": { | ||
"test": "istanbul cover _mocha -- --recursive --reporter spec", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls" | ||
"test": "jest --coverage", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
@@ -14,9 +17,13 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"babel-eslint": "^4.1.8", | ||
"coveralls": "^2.11.6", | ||
"eslint": "^2.0.0", | ||
"is-my-json-valid": "^2.12.4", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.4.5" | ||
"eslint": "^3.9.0", | ||
"jest": "^16.0.2", | ||
"semantic-release": "^4.3.5" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node" | ||
}, | ||
"engines": { | ||
"node": ">=4", | ||
"npm": ">=3" | ||
}, | ||
"repository": { | ||
@@ -37,3 +44,4 @@ "type": "git", | ||
"promise" | ||
] | ||
} | ||
], | ||
"version": "2.0.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
3
6316
5
49