Class: GherkinLint::TagUsedMultipleTimes

Inherits:
Linter
  • Object
show all
Defined in:
lib/gherkin_lint/linter/tag_used_multiple_times.rb

Overview

service class to lint for tags used multiple times

Instance Attribute Summary

Attributes inherited from Linter

#issues

Instance Method Summary collapse

Methods inherited from Linter

#add_error, #add_warning, #backgrounds, descendants, #elements, #features, #files, #filled_scenarios, #filter_tag, #initialize, #line, #lint_files, #name, #reference, #render_step, #render_step_argument, #scenarios, #steps, #suppress, #suppress_tags, #tag?

Constructor Details

This class inherits a constructor from GherkinLint::Linter

Instance Method Details

#lintObject



6
7
8
9
10
11
12
13
14
# File 'lib/gherkin_lint/linter/tag_used_multiple_times.rb', line 6

def lint
  scenarios do |file, feature, scenario|
    references = [reference(file, feature, scenario)]
    total_tags = tags(feature) + tags(scenario)
    double_used_tags = total_tags.find_all { |a| total_tags.count(a) > 1 }.uniq!
    next if double_used_tags.nil?
    add_error(references, "Tag #{double_used_tags.join(' and ')} used multiple times")
  end
end

#tags(element) ⇒ Object



16
17
18
19
# File 'lib/gherkin_lint/linter/tag_used_multiple_times.rb', line 16

def tags(element)
  return [] unless element.include? :tags
  element[:tags].map { |a| a[:name] }
end