Class: GherkinLint::TooManyDifferentTags

Inherits:
Linter
  • Object
show all
Includes:
TagCollector
Defined in:
lib/gherkin_lint/linter/too_many_different_tags.rb

Overview

service class to lint for too many different tags

Instance Attribute Summary

Attributes inherited from Linter

#issues

Instance Method Summary collapse

Methods included from TagCollector

#gather_tags

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



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gherkin_lint/linter/too_many_different_tags.rb', line 9

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

#tags_for_feature(feature) ⇒ Object



36
37
38
39
# File 'lib/gherkin_lint/linter/too_many_different_tags.rb', line 36

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

#warn_across_all_features(references, tags) ⇒ Object



29
30
31
32
33
34
# File 'lib/gherkin_lint/linter/too_many_different_tags.rb', line 29

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

#warn_single_feature(references, tags) ⇒ Object



22
23
24
25
26
27
# File 'lib/gherkin_lint/linter/too_many_different_tags.rb', line 22

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