class CucumberLint::FeatureLinter

A linter for a given feature (represented by a filename)

Public Instance Methods

lint() click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 13
def lint
  features = parse_content

  features.each do |feature|
    lint_feature_empty_lines feature if @config.consistent_empty_lines.enabled
    lint_elements feature
  end

  empty_feature if features.count == 0
end

Private Instance Methods

empty_feature() click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 27
def empty_feature
  return unless @config.no_empty_features.enabled

  if @config.fix
    @linted_file.mark_for_deletion
  else
    add_error ' Remove file with no feature'
  end
end
lint_elements(feature) click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 43
def lint_elements feature
  return unless feature.elements

  feature.elements.each do |element|
    lint_steps element.steps

    if element.type == 'scenario_outline'
      lint_scenario_outline element.steps
      lint_examples element.examples
    end
  end
end
lint_examples(examples) click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 38
def lint_examples examples
  examples.each { |example| lint_table example.rows }
end
lint_feature_empty_lines(feature) click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 57
def lint_feature_empty_lines feature
  linter = FeatureEmptyLinesLinter.new linter_options.merge(feature: feature)
  linter.lint
end
lint_scenario_outline(steps) click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 63
def lint_scenario_outline steps
  linter = ScenarioOutlineLinter.new linter_options.merge(steps: steps)
  linter.lint
end
lint_steps(steps) click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 69
def lint_steps steps
  linter = StepsLinter.new linter_options.merge(steps: steps)
  linter.lint
end
lint_table(rows) click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 75
def lint_table rows
  linter = TableLinter.new linter_options.merge(rows: rows)
  linter.lint
end
linter_options() click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 81
def linter_options
  { config: @config, linted_file: @linted_file }
end
parse_content() click to toggle source
# File lib/cucumber_lint/linter/feature_linter.rb, line 86
def parse_content
  io = StringIO.new
  formatter = Gherkin::Formatter::JSONFormatter.new(io)
  parser = Gherkin::Parser::Parser.new(formatter)
  parser.parse(@linted_file.content, '', 0)
  formatter.done
  MultiJson.load(io.string).to_open_struct
end