diff --git a/src/rules/no-restricted-tags.js b/src/rules/no-restricted-tags.js index 72c4b540..8423057c 100644 --- a/src/rules/no-restricted-tags.js +++ b/src/rules/no-restricted-tags.js @@ -6,34 +6,37 @@ var availableConfigs = { function noRestrictedTags(feature, fileName, configuration) { var forbiddenTags = configuration.tags; - - var featureErrors = checkTags(feature, forbiddenTags); - - var childrenErrors = _(feature.children).map(function(child) { - return checkTags(child, forbiddenTags); - }).flatten().value(); - - return featureErrors.concat(childrenErrors); + var errors = []; + + checkTags(feature, forbiddenTags, errors); + if (feature.children) { + feature.children.forEach(function(child) { + checkTags(child, forbiddenTags, errors); + + if (child.examples) { + child.examples.forEach(function(example) { + checkTags(example, forbiddenTags, errors); + }); + } + }); + } + return errors; } -function checkTags(node, forbiddenTags) { - return (node.tags || []).filter(function(tag) { - return isForbidden(tag, forbiddenTags); - }).map(function(tag) { - return createError(node, tag); +function checkTags(node, forbiddenTags, errors) { + var nodeTags = node.tags || []; + + nodeTags.forEach(function(tag) { + if (_.includes(forbiddenTags, tag.name)) { + errors.push({ + message: 'Forbidden tag ' + tag.name + ' on ' + node.type, + rule : rule, + line : tag.location.line + }); + } }); } -function isForbidden(tag, forbiddenTags) { - return _.includes(forbiddenTags, tag.name); -} - -function createError(node, tag) { - return {message: 'Forbidden tag ' + tag.name + ' on ' + node.type, - rule : rule, - line : tag.location.line}; -} - module.exports = { name: rule, run: noRestrictedTags, diff --git a/test/rules/no-restricted-tags/Violations.feature b/test/rules/no-restricted-tags/Violations.feature index edc0a78f..a3c43a46 100644 --- a/test/rules/no-restricted-tags/Violations.feature +++ b/test/rules/no-restricted-tags/Violations.feature @@ -11,6 +11,12 @@ Scenario: This is a Scenario with three duplicate tags @scenariotag @badTag @anotherBadTag Scenario Outline: This is a Scenario Outline with two duplicate tags Then this is a then step +@examplestag @badTag @anotherBadTag Examples: | foo | | bar | + +@examplestag @badTag @anotherBadTag +Examples: + | foo | + | bar | \ No newline at end of file diff --git a/test/rules/no-restricted-tags/no-restricted-tags.js b/test/rules/no-restricted-tags/no-restricted-tags.js index 1b623fbd..4079b6c8 100644 --- a/test/rules/no-restricted-tags/no-restricted-tags.js +++ b/test/rules/no-restricted-tags/no-restricted-tags.js @@ -35,6 +35,22 @@ describe('No Restricted Tags Rule', function() { { messageElements: {tag: '@anotherBadTag', nodeType:'ScenarioOutline'}, line: 11 + }, + { + messageElements: {tag: '@badTag', nodeType:'Examples'}, + line: 14 + }, + { + messageElements: {tag: '@anotherBadTag', nodeType:'Examples'}, + line: 14 + }, + { + messageElements: {tag: '@badTag', nodeType:'Examples'}, + line: 19 + }, + { + messageElements: {tag: '@anotherBadTag', nodeType:'Examples'}, + line: 19 }]); }); });