Class: CukeLinter::ElementWithTooManyTagsLinter

Inherits:
Linter
  • Object
show all
Defined in:
lib/cuke_linter/linters/element_with_too_many_tags_linter.rb

Overview

A linter that detects taggable Gherkin elements that have too many tags

Instance Attribute Summary

Attributes inherited from Linter

#name

Instance Method Summary collapse

Methods inherited from Linter

#initialize, #lint

Constructor Details

This class inherits a constructor from CukeLinter::Linter

Instance Method Details

#configure(options) ⇒ Object

Changes the linting settings on the linter using the provided configuration



7
8
9
10
# File 'lib/cuke_linter/linters/element_with_too_many_tags_linter.rb', line 7

def configure(options)
  @tag_threshold   = options['TagCountThreshold']
  @tag_inheritance = options['CountInheritedTags']
end

#messageObject

The message used to describe the problem that has been found



28
29
30
31
32
# File 'lib/cuke_linter/linters/element_with_too_many_tags_linter.rb', line 28

def message
  class_name = @linted_model_class.name.split('::').last

  "#{class_name} has too many tags. #{@linted_tag_count} tags found (max #{@linted_tag_threshold})."
end

#rule(model) ⇒ Object

The rule used to determine if a model has a problem



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cuke_linter/linters/element_with_too_many_tags_linter.rb', line 13

def rule(model)
  return false unless relevant_model?(model)

  @linted_model_class   = model.class
  @linted_tag_threshold = @tag_threshold || 5
  @linted_tag_count     = if @tag_inheritance
                            model.all_tags.count
                          else
                            model.tags.nil? ? 0 : model.tags.count
                          end

  @linted_tag_count > @linted_tag_threshold
end