Class: Chutney::AvoidScripting

Inherits:
Linter
  • Object
show all
Defined in:
lib/chutney/linter/avoid_scripting.rb

Overview

service class to lint for avoid scripting

Instance Attribute Summary

Attributes inherited from Linter

#configuration, #filename, #issues

Instance Method Summary collapse

Methods inherited from Linter

#add_issue, #and_word?, #background, #background_word?, #but_word?, descendants, #dialect, #dialect_word, #elements, #examples_word?, #feature, #feature_word?, #filled_scenarios, #given_word?, #initialize, linter_name, #linter_name, #location, #off_switch?, #render_step, #render_step_argument, #scenario_outline_word?, #scenarios, #steps, #tags_for, #then_word?, #type, #when_word?

Constructor Details

This class inherits a constructor from Chutney::Linter

Instance Method Details

#filter_when_steps(steps) ⇒ Object



14
15
16
17
18
19
# File 'lib/chutney/linter/avoid_scripting.rb', line 14

def filter_when_steps(steps)
  steps
    .drop_while { |step| !when_word?(step.keyword) }
    .then { |s| s.reverse.drop_while { |step| !then_word?(step.keyword) }.reverse }
    .then { |s| s.reject { |step| then_word?(step.keyword) } }
end

#lintObject



6
7
8
9
10
11
12
# File 'lib/chutney/linter/avoid_scripting.rb', line 6

def lint
  scenarios do |feature, scenario|
    when_steps = filter_when_steps(scenario.steps)
    whens = when_steps.count
    add_issue(I18n.t('linters.avoid_scripting', count: whens), feature, scenario, when_steps.last) if whens > 1
  end
end