Class: Chutney::AvoidTypographersQuotes

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

Overview

service class to lint for avoid scripting

Constant Summary collapse

TYPOGRAPHER_QUOTES =
["\u201c", "\u201d", "\u2018", "\u2019"].map(&:encode)

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

#issue(feature, scenario, location) ⇒ Object



35
36
37
# File 'lib/chutney/linter/avoid_typographers_quotes.rb', line 35

def issue(feature, scenario, location)
  add_issue(I18n.t('linters.avoid_typographers_quotes'), feature, scenario, location)
end

#lintObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/chutney/linter/avoid_typographers_quotes.rb', line 8

def lint
  scenarios do |feature, scenario|
    lint_steps(feature, scenario)

    example_count = scenario.is_a?(CukeModeler::Outline) ? scenario.examples.length : 0
    next unless example_count.positive?

    lint_examples(feature, scenario)
  end
end

#lint_examples(feature, scenario) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/chutney/linter/avoid_typographers_quotes.rb', line 25

def lint_examples(feature, scenario)
  scenario.examples.each do |example|
    example.rows.each do |row|
      row.cells.each do |cell|
        issue(feature, scenario, cell) if TYPOGRAPHER_QUOTES.any? { |tq| cell.value.include? tq }
      end
    end
  end
end

#lint_steps(feature, scenario) ⇒ Object



19
20
21
22
23
# File 'lib/chutney/linter/avoid_typographers_quotes.rb', line 19

def lint_steps(feature, scenario)
  scenario.steps.each do |step|
    issue(feature, scenario, step) if TYPOGRAPHER_QUOTES.any? { |tq| step.text.include? tq }
  end
end