gherkin-lint
Advanced tools
Comparing version 2.5.2 to 2.6.0
@@ -22,4 +22,12 @@ { | ||
"always" | ||
], | ||
"brace-style": [ | ||
"error", | ||
"1tbs" | ||
], | ||
"space-before-blocks": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
{ | ||
"name": "gherkin-lint", | ||
"version": "2.5.2", | ||
"version": "2.6.0", | ||
"description": "A Gherkin linter/validator written in javascript", | ||
@@ -5,0 +5,0 @@ "author": "Vasiliki Siakka", |
@@ -69,15 +69,30 @@ # Gherkin lint | ||
`indentation` can be configured in a more granular level and uses following rules by default: | ||
- Expected indentation for Feature, Background, Scenario: 0 spaces | ||
- Expected indentation for Steps: 2 spaces | ||
- Expected indentation for Feature, Background, Scenario, Examples heading: 0 spaces | ||
- Expected indentation for Steps and each example: 2 spaces | ||
You can override the defaults for `indentation` like this: | ||
`Step` will be used as a fallback if the keyword of the step is not specified. | ||
This feature is able to handle all localizations of the gherkin steps. | ||
``` | ||
{ | ||
"indentation" : ["on", { "Feature": 0, "Background": 0, "Scenario": 0, "Step": 2, "given": 2, "and": 3 }] | ||
"indentation" : [ | ||
"on", { | ||
"Feature": 0, | ||
"Background": 0, | ||
"Scenario": 0, | ||
"Step": 2, | ||
"Examples": 0, | ||
"example": 2, | ||
"given": 2, | ||
"when": 2, | ||
"then": 2, | ||
"and": 2, | ||
"but": 2 | ||
} | ||
] | ||
} | ||
There is no need to override all the defaults, as is done above, instead they can be overriden only where required. `Step` will be used as a fallback if the keyword of the step, eg. 'given', is not specified. | ||
This feature is able to handle all localizations of the gherkin steps. | ||
``` | ||
## `name-length` | ||
### `name-length` | ||
@@ -84,0 +99,0 @@ `name-length` can be configured separately for Feature, Scenario and Step names. |
@@ -24,3 +24,3 @@ var fs = require('fs'); | ||
console.error('\x1b[31m\x1b[1mError(s) in configuration file:\x1b[0m'); // eslint-disable-line no-console | ||
errors.forEach(function(error){ | ||
errors.forEach(function(error) { | ||
console.error('\x1b[31m- ' + error + '\x1b[0m'); // eslint-disable-line no-console | ||
@@ -27,0 +27,0 @@ }); |
@@ -10,2 +10,4 @@ var _ = require('lodash'); | ||
'Step': 2, | ||
'Examples': 0, | ||
'example': 2, | ||
'given': 2, | ||
@@ -23,3 +25,5 @@ 'when': 2, | ||
if (--parsedLocation.column !== configuration[type]) { | ||
errors.push({message: 'Wrong indentation for "' + type + '", expected indentation level of ' + configuration[type] + ', but got ' + parsedLocation.column, | ||
errors.push({message: 'Wrong indentation for "' + type + | ||
'", expected indentation level of ' + configuration[type] + | ||
', but got ' + parsedLocation.column, | ||
rule : rule, | ||
@@ -32,3 +36,5 @@ line : parsedLocation.line}); | ||
var keyword = step.keyword; | ||
var stepType = _.findKey(language, function(values) { return values instanceof Array && values.indexOf(keyword) !== -1; }); | ||
var stepType = _.findKey(language, function(values) { | ||
return values instanceof Array && values.indexOf(keyword) !== -1; | ||
}); | ||
stepType = stepType in configuration ? stepType : 'Step'; | ||
@@ -38,2 +44,13 @@ test(step.location, mergedConfiguration, stepType); | ||
function testScenarioOutline(scenarioOutline, mergedConfiguration) { | ||
test(scenarioOutline.location, mergedConfiguration, 'Scenario'); | ||
scenarioOutline.examples.forEach(function(examples) { | ||
test(examples.location, mergedConfiguration, 'Examples'); | ||
test(examples.tableHeader.location, mergedConfiguration, 'example'); | ||
examples.tableBody.forEach(function(row) { | ||
test(row.location, mergedConfiguration, 'example'); | ||
}); | ||
}); | ||
} | ||
function indentation(feature, unused, configuration) { | ||
@@ -53,10 +70,10 @@ if (!feature || Object.keys(feature).length === 0) { | ||
case 'Background': | ||
// Check Background indentation | ||
test(child.location, mergedConfiguration, 'Background'); | ||
break; | ||
case 'Scenario': | ||
case 'ScenarioOutline': | ||
// Check Scenario indentation | ||
test(child.location, mergedConfiguration, 'Scenario'); | ||
break; | ||
case 'ScenarioOutline': | ||
testScenarioOutline(child, mergedConfiguration); | ||
break; | ||
default: | ||
@@ -63,0 +80,0 @@ errors.push({message: 'Unknown gherkin node type ' + child.type, |
@@ -16,4 +16,3 @@ var _ = require('lodash'); | ||
var errormsg = ''; | ||
if (hasNewLineAtEOF && configuration === 'no') | ||
{ | ||
if (hasNewLineAtEOF && configuration === 'no') { | ||
errormsg = 'New line at EOF(end of file) is not allowed'; | ||
@@ -20,0 +19,0 @@ } else if (!hasNewLineAtEOF && configuration === 'yes') { |
@@ -9,3 +9,3 @@ var _ = require('lodash'); | ||
if(feature.children !== undefined) { | ||
_.forEach(feature.children, function(child) { | ||
feature.children.forEach(function(child) { | ||
errors = errors.concat(verifyTags(child.tags, child.location)); | ||
@@ -22,3 +22,3 @@ }); | ||
if (tags !== undefined && location !== undefined) { | ||
_.forEach(tags, function(tag) { | ||
tags.forEach(function(tag) { | ||
if (!_.includes(failedTagNames, tag.name)) { | ||
@@ -25,0 +25,0 @@ if (_.includes(uniqueTagNames, tag.name)) { |
@@ -8,3 +8,3 @@ var _ = require('lodash'); | ||
if(feature.tags !== undefined && feature.children !== undefined) { | ||
_.forEach(feature.children, function(child) { | ||
feature.children.forEach(function(child) { | ||
if (child.tags !== undefined) { | ||
@@ -11,0 +11,0 @@ var superfluousTags = _.intersectionWith(child.tags, feature.tags, function(lhs, rhs) { |
@@ -25,2 +25,11 @@ var ruleTestBase = require('../rule-test-base'); | ||
},{ | ||
messageElements: {element: 'Examples', expected: 0, actual: 2}, | ||
line: 11 | ||
},{ | ||
messageElements: {element: 'example', expected: 2, actual:4}, | ||
line: 12 | ||
},{ | ||
messageElements: {element: 'example', expected: 2, actual:4}, | ||
line: 13 | ||
},{ | ||
messageElements: {element: 'Step', expected: 2, actual: 3}, | ||
@@ -67,2 +76,11 @@ line: 10 | ||
},{ | ||
messageElements: {element: 'Examples', expected: 0, actual: 7}, | ||
line: 12 | ||
},{ | ||
messageElements: {element: 'example', expected: 2, actual: 15}, | ||
line: 13 | ||
},{ | ||
messageElements: {element: 'example', expected: 2, actual: 15}, | ||
line: 14 | ||
},{ | ||
messageElements: {element: 'Step', expected: 2, actual: 11}, | ||
@@ -69,0 +87,0 @@ line: 11 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62685
1233
156