class CukeLinter::ElementWithDuplicateTagsLinter

A linter that detects taggable Gherkin elements that have duplicate tags

Public Instance Methods

configure(options) click to toggle source

Changes the linting settings on the linter using the provided configuration

# File lib/cuke_linter/linters/element_with_duplicate_tags_linter.rb, line 8
def configure(options)
  @tag_inheritance = options['IncludeInheritedTags']
end
message() click to toggle source

The message used to describe the problem that has been found

# File lib/cuke_linter/linters/element_with_duplicate_tags_linter.rb, line 31
def message
  class_name = @linted_model_class.name.split('::').last

  "#{class_name} has duplicate tag '#{@duplicate_tag}'."
end
rule(model) click to toggle source

The rule used to determine if a model has a problem

# File lib/cuke_linter/linters/element_with_duplicate_tags_linter.rb, line 13
def rule(model)
  return false unless relevant_model?(model)

  @linted_model_class = model.class

  relevant_tags = if @tag_inheritance
                    model.all_tags
                  else
                    model.tags || []
                  end
  tag_names     = relevant_tags.map(&:name)

  @duplicate_tag = tag_names.find { |tag| tag_names.count(tag) > 1 }

  !@duplicate_tag.nil?
end

Private Instance Methods

relevant_model?(model) click to toggle source
# File lib/cuke_linter/linters/element_with_duplicate_tags_linter.rb, line 41
def relevant_model?(model)
  model.is_a?(CukeModeler::Feature) ||
    model.is_a?(CukeModeler::Scenario) ||
    model.is_a?(CukeModeler::Outline) ||
    model.is_a?(CukeModeler::Example)
end