Sha256: a3bc96d4d58479da689c3144b12002935b8b83c1eb0cbb1da3598be8bb165605

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require 'gherkin_lint/linter'

module GherkinLint
  # service class to lint for too many different tags
  class TooManyDifferentTags < Linter
    def lint
      overall_tags = []
      overall_references = []
      features do |file, feature|
        tags = tags_for_feature(feature)
        overall_tags += tags
        references = [reference(file, feature)]
        overall_references += references unless tags.empty?
        warn_single_feature(references, tags)
      end
      warn_across_all_features(overall_references, overall_tags)
    end

    def warn_single_feature(references, tags)
      tags.uniq!
      references.uniq!
      return false unless tags.length >= 3
      add_error(references, "Used #{tags.length} Tags within single Feature")
    end

    def warn_across_all_features(references, tags)
      tags.uniq!
      references.uniq!
      return false unless tags.length >= 10
      add_error(references, "Used #{tags.length} Tags across all Features")
    end

    def tags_for_feature(feature)
      return [] unless feature.include? 'elements'
      gather_tags(feature) + feature['elements'].map { |scenario| gather_tags(scenario) }.flatten
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gherkin_lint-0.3.1 lib/gherkin_lint/linter/too_many_different_tags.rb
gherkin_lint-0.3.0 lib/gherkin_lint/linter/too_many_different_tags.rb