Class: CucumberLint::StepsLinter

Inherits:
Linter
  • Object
show all
Defined in:
lib/cucumber_lint/linter/steps_linter.rb

Overview

A linter for a series of steps (as parsed by Gherkin)

Instance Method Summary collapse

Methods inherited from Linter

#add_error, #add_fix

Constructor Details

#initialize(steps:, config:, linted_file:) ⇒ StepsLinter

Returns a new instance of StepsLinter.



5
6
7
8
9
# File 'lib/cucumber_lint/linter/steps_linter.rb', line 5

def initialize steps:, config:, linted_file:
  super config: config, linted_file: linted_file

  @steps = steps
end

Instance Method Details

#lintObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cucumber_lint/linter/steps_linter.rb', line 12

def lint
  previous_keyword = nil

  @steps.each do |step|
    current_keyword = step.keyword.strip

    if STEP_TYPES.include?(current_keyword) && current_keyword == previous_keyword
      repeated_keyword step.line, current_keyword
    else
      previous_keyword = current_keyword
    end

    lint_table(step.rows) if step.rows && step.rows.is_a?(Array)
  end
end