Skip to content

Commit

Permalink
Add custom message options for valid-suite-description rule
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgoisMickael committed Aug 21, 2019
1 parent 3102e7c commit b7d7682
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/rules/valid-suite-description.js
Expand Up @@ -8,9 +8,28 @@
const astUtils = require('../util/ast');
const defaultSuiteNames = [ 'describe', 'context', 'suite' ];

module.exports = function (context) {
function inlineOptions(context) {
const pattern = new RegExp(context.options[0]);
const suiteNames = context.options[1] ? context.options[1] : defaultSuiteNames;
const message = context.options[2];

return { pattern, suiteNames, message };
}

function objectOptions(options) {
const pattern = new RegExp(options.pattern);
const suiteNames = options.suiteNames ? options.suiteNames : defaultSuiteNames;
const message = options.message;

return { pattern, suiteNames, message };
}

module.exports = function (context) {
const options = context.options[0];

const { pattern, suiteNames, message } = typeof options === 'object' && !(options instanceof RegExp) ?
objectOptions(options) :
inlineOptions(context);

function isSuite(node) {
return node.callee && node.callee.name && suiteNames.indexOf(node.callee.name) > -1;
Expand Down Expand Up @@ -40,7 +59,7 @@ module.exports = function (context) {

if (isSuite(node)) {
if (!hasValidOrNoSuiteDescription(node)) {
context.report(node, `Invalid "${ callee.name }()" description found.`);
context.report(node, message || `Invalid "${ callee.name }()" description found.`);
}
}
}
Expand Down

0 comments on commit b7d7682

Please sign in to comment.