Skip to content

Commit

Permalink
Merge pull request #26 from xgbuils/fix-25
Browse files Browse the repository at this point in the history
fix no-duplicated-tags: one report by duplicated tag
  • Loading branch information
xgbuils authored May 6, 2019
2 parents 4ee6b3c + a17139e commit 50fcc9e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
38 changes: 16 additions & 22 deletions src/rules/no-duplicate-tags.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
const rule = 'no-duplicate-tags';
const {compose, intoArray} = require('../utils/generic');
const {filter, map} = require('../utils/transducers');
const {flatMapNodeTags} = require('../utils/gherkin');

const collectTagsInfo = (tags, {name, location}) => {
const info = tags[name];
if (info) {
info.count++;
const appendErrors = (track, tag) => {
if (track.names.has(tag.name)) {
track.errors.push(createError(tag));
} else {
tags[name] = {
count: 1,
location,
name,
};
track.names.add(tag.name);
}
return tags;
return track;
};

const createError = (tag) => ({
type: 'rule',
message: `Duplicate tags are not allowed: ${tag.name}`,
rule: rule,
location: tag.location,
});

const verifyTags = ({tags, location}) => {
const tagsInfo = tags.reduce(collectTagsInfo, {});
return intoArray(compose(
filter(({count}) => count > 1),
map((tag) => ({
type: 'rule',
message: `Duplicate tags are not allowed: ${tag.name}`,
rule: rule,
location: tag.location,
}))
))(tagsInfo);
return tags.reduce(appendErrors, {
names: new Set(),
errors: [],
}).errors;
};

module.exports = {
Expand Down
24 changes: 20 additions & 4 deletions test/rules/no-duplicate-tags/no-duplicate-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,47 @@ describe('No Duplicate Tags Rule', () => {
rule: ruleName,
location: {
line: 1,
column: 1,
column: 13,
},
},
{
messageElements: {tags: '@scenariotag'},
rule: ruleName,
location: {
line: 7,
column: 1,
column: 14,
},
},
{
messageElements: {tags: '@scenariotag'},
rule: ruleName,
location: {
line: 7,
column: 27,
},
},
{
messageElements: {tags: '@scenariotag'},
rule: ruleName,
location: {
line: 11,
column: 1,
column: 14,
},
},
{
messageElements: {tags: '@exampletag'},
rule: ruleName,
location: {
line: 14,
column: 15,
},
},
{
messageElements: {tags: '@exampletag'},
rule: ruleName,
location: {
line: 14,
column: 3,
column: 27,
},
}]);
});
Expand Down

0 comments on commit 50fcc9e

Please sign in to comment.