Class: CukeLinter::FeatureWithTooManyDifferentTagsLinter

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

Overview

A linter that detects features that contain too many different 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
# File 'lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb', line 7

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

#messageObject

The message used to describe the problem that has been found



30
31
32
# File 'lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb', line 30

def message
  "Feature contains too many different 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



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

def rule(model)
  return false unless model.is_a?(CukeModeler::Feature)

  tags = model.tags

  model.each_descendant do |descendant_model|
    tags.concat(descendant_model.tags) if descendant_model.respond_to?(:tags)
  end

  tags = tags.collect(&:name).uniq

  @linted_tag_threshold = @tag_threshold || 10
  @linted_tag_count     = tags.count

  @linted_tag_count > @linted_tag_threshold
end