Skip to content

Commit

Permalink
add explicitReturn flag to no-nill Fixes #28
Browse files Browse the repository at this point in the history
Allows rule users to use a slower, but more accurate must-return rule:

eg, idmitriev/eslint-plugin-better#3
  • Loading branch information
graingert authored Jul 31, 2017
1 parent 5f4c679 commit 7026101
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rules/no-nil.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function reportFunctions(context, node) {
}

const create = function (context) {
const reportFunc = _.partial(reportFunctions, [context]);
const options = context.options[0] || { explicitReturn: true };
const explicitReturn = options.explicitReturn === true;
const reportFunc = explicitReturn ? _.partial(reportFunctions, [context]) : () => {};
return {
Literal(node) {
if (node.value === null) {
Expand Down Expand Up @@ -74,6 +76,15 @@ module.exports = {
docs: {
description: 'Forbid the use of `null` and `undefined`.',
recommended: 'error'
}
},
schema: [{
type: "object",
properties: {
explicitReturn: {
type: "boolean"
},
},
additionalProperties: false
}]
}
};

0 comments on commit 7026101

Please sign in to comment.