class CucumberLint::StepsLinter

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

Constants

STEP_TYPES

Public Class Methods

new(steps:, config:, linted_file: super config: config, linted_file: linted_file) click to toggle source
# 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

Public Instance Methods

lint() click to toggle source
# 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

Private Instance Methods

lint_table(rows) click to toggle source
# File lib/cucumber_lint/linter/steps_linter.rb, line 44
def lint_table rows
  linter = TableLinter.new rows: rows, config: @config, linted_file: @linted_file
  linter.lint
end
repeated_keyword(line_number, keyword) click to toggle source
# File lib/cucumber_lint/linter/steps_linter.rb, line 33
def repeated_keyword line_number, keyword
  return unless @config.no_repeating_keywords.enabled

  if @config.fix
    add_fix line_number, -> (line) { line.sub(keyword, 'And') }
  else
    add_error "#{line_number}: Use \"And\" instead of repeating \"#{keyword}\""
  end
end