eslint-plugin-mocha
Advanced tools
Comparing version 4.7.0 to 4.8.0
@@ -0,1 +1,20 @@ | ||
## 4.8.0 (December 23, 2016) | ||
### Enhancements | ||
* Support MemberExpression for additionalTestFunctions (#114) | ||
* Make no-mocha-arrows rule fixable (#112) | ||
### Bug Fixes | ||
* Fix no-mocha-arrow fixer (#118) | ||
### Build-Related | ||
* Add node 7 as travis build environment (#115) | ||
### Documentation | ||
* Fix rule name in CHANGELOG to match actual rule (#111) | ||
## 4.7.0 (October 12, 2016) | ||
@@ -16,3 +35,3 @@ | ||
* Add 'one-suite-per-file' rule (#103) (#105) | ||
* Add 'max-top-level-suites' rule (#103) (#105) | ||
@@ -19,0 +38,0 @@ ## 4.5.1 (August 30, 2016) |
'use strict'; | ||
var getAdditionalTestFunctions = require('../util/settings').getAdditionalTestFunctions; | ||
var getAdditionalTestFunctions = require('../util/settings').getAdditionalTestFunctions, | ||
astUtils = require('../util/ast'); | ||
@@ -20,7 +21,9 @@ module.exports = function (context) { | ||
function matchesMochaTestFunction(object) { | ||
return object && mochaTestFunctions.indexOf(object.name) !== -1; | ||
var name = astUtils.getNodeName(object); | ||
return mochaTestFunctions.indexOf(name) !== -1; | ||
} | ||
function isPropertyNamedOnly(property) { | ||
return property && (property.name === 'only' || property.value === 'only'); | ||
return property && astUtils.getPropertyName(property) === 'only'; | ||
} | ||
@@ -27,0 +30,0 @@ |
@@ -44,2 +44,38 @@ 'use strict'; | ||
function fixArrowFunction(fixer, fn) { | ||
var sourceCode = context.getSourceCode(), | ||
paramsLeftParen = sourceCode.getFirstToken(fn), | ||
paramsRightParen = sourceCode.getTokenBefore(sourceCode.getTokenBefore(fn.body)), | ||
paramsFullText = | ||
sourceCode.text.slice(paramsLeftParen.range[0], paramsRightParen.range[1]), | ||
functionKeyword = 'function', | ||
bodyText; | ||
if (fn.async) { | ||
// When 'async' specified, take care about the keyword. | ||
functionKeyword = 'async function'; | ||
// Strip 'async (...)' to ' (...)' | ||
paramsFullText = paramsFullText.slice(5); | ||
} | ||
if (fn.params.length > 0) { | ||
paramsFullText = '(' + sourceCode.text.slice(fn.params[0].start, R.last(fn.params).end) + ')'; | ||
} | ||
if (fn.body.type === 'BlockStatement') { | ||
// When it((...) => { ... }), | ||
// simply replace '(...) => ' with 'function () ' | ||
return fixer.replaceTextRange( | ||
[ fn.start, fn.body.start ], | ||
functionKeyword + paramsFullText + ' ' | ||
); | ||
} | ||
bodyText = sourceCode.text.slice(fn.body.range[0], fn.body.range[1]); | ||
return fixer.replaceTextRange( | ||
[ fn.start, fn.end ], | ||
functionKeyword + paramsFullText + ' { return ' + bodyText + '; }' | ||
); | ||
} | ||
return { | ||
@@ -54,3 +90,9 @@ CallExpression: function (node) { | ||
if (isLikelyMochaGlobal(context.getScope(), name)) { | ||
context.report(node, 'Do not pass arrow functions to ' + name + '()'); | ||
context.report({ | ||
node: node, | ||
message: 'Do not pass arrow functions to ' + name + '()', | ||
fix: function (fixer) { | ||
return fixArrowFunction(fixer, fnArg); | ||
} | ||
}); | ||
} | ||
@@ -57,0 +99,0 @@ } |
@@ -13,5 +13,9 @@ /* eslint-env node*/ | ||
function getPropertyName(property) { | ||
return property.name || property.value; | ||
} | ||
function getNodeName(node) { | ||
if (node.type === 'MemberExpression') { | ||
return node.object.name + '.' + node.property.name; | ||
return getNodeName(node.object) + '.' + getPropertyName(node.property); | ||
} | ||
@@ -42,3 +46,5 @@ return node.name; | ||
isHookIdentifier: isHookIdentifier, | ||
isTestCase: isTestCase | ||
isTestCase: isTestCase, | ||
getPropertyName: getPropertyName, | ||
getNodeName: getNodeName | ||
}; |
{ | ||
"name": "eslint-plugin-mocha", | ||
"version": "4.7.0", | ||
"version": "4.8.0", | ||
"description": "Eslint rules for mocha.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
44092
903