Skip to content

Commit

Permalink
Fix one-space-between-tags rule not detecting errors in Examples nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
vsiakka committed May 12, 2019
1 parent 803a040 commit 8ef092b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
46 changes: 28 additions & 18 deletions src/rules/one-space-between-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,35 @@ const _ = require('lodash');
var rule = 'one-space-between-tags';

function run(feature) {
if (!feature || Object.keys(feature).length === 0) {
return [];
}
var errors = [];

testTags(feature, errors);

if (feature.children) {
feature.children.forEach(function(child) {

testTags(child, errors);

if (child.examples) {
child.examples.forEach(function(example) {
testTags(example, errors);
});
}
});
}
return errors;
}

function testTags(allTags) {
_(allTags).groupBy('location.line').sortBy('location.column')
.forEach(function(tags) {
_.range(tags.length - 1).map(function(i) {
function testTags(node, errors) {
if (!node.tags) {
return;
}
_(node.tags)
.groupBy('location.line')
.sortBy('location.column')
.forEach(function(tags) {
_.range(tags.length - 1)
.map(function(i) {
if (tags[i].location.column + tags[i].name.length < tags[i + 1].location.column - 1) {
errors.push({
line: tags[i].location.line,
Expand All @@ -21,17 +41,7 @@ function run(feature) {
});
}
});
});
}

testTags(feature.tags);
feature.children.forEach(function(child) {
if (child.type === 'Scenario' || child.type === 'ScenarioOutline') {
testTags(child.tags);
}
});

return errors;
});
}

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions test/rules/one-space-between-tags/NoViolations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Scenario: This is a Scenario with good tag spacing
@scenariotag5 @scenariotag6
Scenario Outline: This is a Scenario Outline with good tag spacing
Then this is a then step <foo>
@examplestag1 @examplestag2
Examples:
| foo |
| bar |
3 changes: 2 additions & 1 deletion test/rules/one-space-between-tags/Violations.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@featuretag1 @featuretag2
@featuretag3
Feature: Feature with good tag spacing
Feature: Feature with bad tag spacing

Background:
Given I have a Background
Expand All @@ -13,6 +13,7 @@ Scenario: This is a Scenario with bad tag spacing
@scenariotag5 @scenariotag6
Scenario Outline: This is a Scenario Outline with bad tag spacing
Then this is a then step <foo>
@examplestag1 @examplestag2
Examples:
| foo |
| bar |
35 changes: 22 additions & 13 deletions test/rules/one-space-between-tags/one-space-between-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,27 @@ describe('One Space Between Tags Rule', function() {
});

it('detects errors for tags on features, scenarios, and scenario outlines', function() {
runTest('one-space-between-tags/Violations.feature', {}, [{
line: 1,
messageElements: {left: '@featuretag1', right: '@featuretag2'}
}, {
line: 9,
messageElements: {left: '@scenariotag3', right: '@scenariotag4'}
}, {
line: 9,
messageElements: {left: '@scenariotag4', right: '@scenariotag5'}
}, {
line: 13,
messageElements: {left: '@scenariotag5', right: '@scenariotag6'}
}]);
runTest('one-space-between-tags/Violations.feature', {}, [
{
line: 1,
messageElements: {left: '@featuretag1', right: '@featuretag2'}
},
{
line: 9,
messageElements: {left: '@scenariotag3', right: '@scenariotag4'}
},
{
line: 9,
messageElements: {left: '@scenariotag4', right: '@scenariotag5'}
},
{
line: 13,
messageElements: {left: '@scenariotag5', right: '@scenariotag6'}
},
{
line: 16,
messageElements: {left: '@examplestag1', right: '@examplestag2'}
}
]);
});
});

0 comments on commit 8ef092b

Please sign in to comment.