eslint-plugin-cucumber
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -1,5 +0,3 @@ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
var _ = require('lodash'); | ||
module.exports = { | ||
@@ -14,3 +12,3 @@ rules: { | ||
preprocess: function(text, filename) { | ||
return _.map(text.split("\n"), function (line) { | ||
return _.map(text.split('\n'), function(line) { | ||
if (line.trim().match(/^@/)) { | ||
@@ -25,3 +23,3 @@ return '/*__CUCUMBER_TAG__' + line.trim() + '*/'; | ||
postprocess: function(messages, filename) { | ||
return _.filter(_.flatten(messages), function (message) { | ||
return _.filter(_.flatten(messages), function(message) { | ||
return message.ruleId.match(/^cucumber/); | ||
@@ -28,0 +26,0 @@ }); |
@@ -1,30 +0,52 @@ | ||
'use strict'; | ||
module.exports = function(context) { | ||
var CALLBACK_NAMES = /^(next|done)$/; | ||
const CALLBACK_NAMES = /^(next|done)$/; | ||
function isThenStep(node) { | ||
return node.callee && | ||
node.callee.object && | ||
node.callee.object.type === 'ThisExpression' && | ||
node.callee.property && | ||
node.callee.property.name === 'Then'; | ||
return isCucumberOneThenStep(node) || isCucumberTwoPlusThenStep(node); | ||
} | ||
function isCucumberOneThenStep(node) { | ||
return ( | ||
node.callee && | ||
node.callee.object && | ||
node.callee.object.type === 'ThisExpression' && | ||
node.callee.property && | ||
node.callee.property.name === 'Then' | ||
); | ||
} | ||
function isCucumberTwoPlusThenStep(node) { | ||
return ( | ||
node.type === 'CallExpression' && | ||
node.callee && | ||
node.callee.type === 'Identifier' && | ||
node.callee.name === 'Then' | ||
); | ||
} | ||
function didNotReturnAnythingIn(func) { | ||
var statements = func.body.body; | ||
return !statements.length || statements[statements.length - 1].type !== 'ReturnStatement'; | ||
const statements = func.body.body; | ||
return ( | ||
!statements.length || | ||
statements[statements.length - 1].type !== 'ReturnStatement' | ||
); | ||
} | ||
function doesNotHaveCallback(func) { | ||
return !func.params.length || !CALLBACK_NAMES.exec(func.params[func.params.length - 1].name) | ||
return ( | ||
!func.params.length || | ||
!CALLBACK_NAMES.exec(func.params[func.params.length - 1].name) | ||
); | ||
} | ||
return { | ||
'CallExpression': function (node) { | ||
CallExpression: function(node) { | ||
if (isThenStep(node)) { | ||
var stepBody = node.arguments[node.arguments.length - 1]; | ||
const stepBody = node.arguments[node.arguments.length - 1]; | ||
if (doesNotHaveCallback(stepBody) && didNotReturnAnythingIn(stepBody)) { | ||
context.report(node.callee.property, 'Then step didn\'t return a promise or have a callback.'); | ||
context.report( | ||
node.callee.property || node.callee, | ||
"Then step didn't return a promise or have a callback." | ||
); | ||
} | ||
@@ -31,0 +53,0 @@ } |
@@ -1,9 +0,7 @@ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
var _ = require('lodash'); | ||
module.exports = function(context) { | ||
var TAG_IDENTIFIER = '__CUCUMBER_TAG__'; | ||
const TAG_IDENTIFIER = '__CUCUMBER_TAG__'; | ||
var restrictedTags = _.map(context.options, function (tag) { | ||
const restrictedTags = _.map(context.options, function(tag) { | ||
if (!tag.match(/^@/)) tag = '@' + tag; | ||
@@ -18,9 +16,11 @@ return tag; | ||
return { | ||
'Program': function(node) { | ||
var tags = getTagsFrom(node.leadingComments); | ||
Program: function(node) { | ||
const tags = getTagsFrom(node.leadingComments); | ||
if (tags.length) { | ||
_.each(tags, function (tag) { | ||
_.each(tags, function(tag) { | ||
if (_.includes(restrictedTags, tag)) { | ||
context.report(node, "'{{tag}}' is restricted from being used.", {tag: tag}); | ||
context.report(node, "'{{tag}}' is restricted from being used.", { | ||
tag: tag | ||
}); | ||
} | ||
@@ -33,6 +33,10 @@ }); | ||
function getTagsFrom(comments) { | ||
var tags = []; | ||
let tags = []; | ||
if (comments && comments.length === 1 && comments[0].value.match(new RegExp(TAG_IDENTIFIER))) { | ||
tags = comments[0].value.replace(TAG_IDENTIFIER, '').split(' ') | ||
if ( | ||
comments && | ||
comments.length === 1 && | ||
comments[0].value.match(new RegExp(TAG_IDENTIFIER)) | ||
) { | ||
tags = comments[0].value.replace(TAG_IDENTIFIER, '').split(' '); | ||
} | ||
@@ -39,0 +43,0 @@ |
{ | ||
"name": "eslint-plugin-cucumber", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "eslint rules for cucumber steps", | ||
@@ -14,9 +14,16 @@ "keywords": [ | ||
"scripts": { | ||
"test": "script/test.sh" | ||
"format": "prettier --loglevel warn --write \"**/*.js\"", | ||
"test": "npm run --silent format && script/test.sh" | ||
}, | ||
"devDependencies": { | ||
"eslint": "~1.2.0" | ||
"eslint": "~1.2.0", | ||
"prettier": "^1.10.2" | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"singleQuote": true, | ||
"bracketSpacing": false | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
@@ -36,3 +43,7 @@ "license": "MIT", | ||
"lodash": "~3.10.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "~1.2.0", | ||
"prettier": "^1.10.2" | ||
} | ||
} |
@@ -1,13 +0,16 @@ | ||
'use strict'; | ||
const rule = require('../../../lib/rules/async-then'); | ||
const RuleTester = require('eslint').RuleTester; | ||
var rule = require('../../../lib/rules/async-then'); | ||
var RuleTester = require('eslint').RuleTester; | ||
new RuleTester().run('async-then', rule, { | ||
valid: [ | ||
'this.Then(/step/, function () {return "anything";})', | ||
'Then(/step/, function () {return "anything";})', | ||
'this.Then(/step/, function (done) {})', | ||
'Then(/step/, function (done) {})', | ||
'this.Then(/step/, function (next) {})', | ||
'Then(/step/, function (next) {})', | ||
'this.Given(/step/, function () {})', | ||
'this.When(/step/, function () {})' | ||
'Given(/step/, function () {})', | ||
'this.When(/step/, function () {})', | ||
'When(/step/, function () {})' | ||
], | ||
@@ -18,7 +21,17 @@ | ||
code: 'this.Then(/step/, function () {})', | ||
errors: [{ | ||
message: 'Then step didn\'t return a promise or have a callback.', | ||
}] | ||
errors: [ | ||
{ | ||
message: "Then step didn't return a promise or have a callback." | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'Then(/step/, function () {})', | ||
errors: [ | ||
{ | ||
message: "Then step didn't return a promise or have a callback." | ||
} | ||
] | ||
} | ||
] | ||
}); |
@@ -1,19 +0,18 @@ | ||
'use strict'; | ||
const plugin = require('../../../lib/index'); | ||
const rule = require('../../../lib/rules/no-restricted-tags'); | ||
const RuleTester = require('eslint').RuleTester; | ||
var plugin = require('../../../lib/index'); | ||
var rule = require('../../../lib/rules/no-restricted-tags'); | ||
var RuleTester = require('eslint').RuleTester; | ||
new RuleTester().run("no-restricted-tags", rule, { | ||
valid: [ | ||
{ code: preprocess("@wip"), options: ["foo"]} | ||
], | ||
invalid: [{ | ||
code: preprocess("@wip"), options: ["foo", "wip", "bar"], | ||
errors: [{ message: "'@wip' is restricted from being used."}] | ||
}] | ||
new RuleTester().run('no-restricted-tags', rule, { | ||
valid: [{code: preprocess('@wip'), options: ['foo']}], | ||
invalid: [ | ||
{ | ||
code: preprocess('@wip'), | ||
options: ['foo', 'wip', 'bar'], | ||
errors: [{message: "'@wip' is restricted from being used."}] | ||
} | ||
] | ||
}); | ||
function preprocess(code) { | ||
return plugin.processors['.feature'].preprocess(code).join("\n"); | ||
return plugin.processors['.feature'].preprocess(code).join('\n'); | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9977
160
1
2
11