Class: Chutney::InconsistentQuoting

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

Overview

service class to lint for avoiding periods

Defined Under Namespace

Classes: Parameter

Constant Summary collapse

QUOTED_STRING =

regular expression to extract quoted string matching group 1: opening quote; 2: quoted text; 3: closing quote opening and closing quote must match (via backrefs) apostrophes, both singular and plural posessives, are accounted for

/(?!\b\b)(['"])(.*(?:\b'\b[^\1]*)*(?!\b[\1]\b))(\1)/

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

#lintObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chutney/linter/inconsistent_quoting.rb', line 13

def lint
  quoted_params = parameters.group_by(&:quotation_mark)
  single_quoted = quoted_params[%(')] || []
  double_quoted = quoted_params[%(")] || []
  return unless single_quoted.count.positive? && double_quoted.count.positive?

  add_issue(
    I18n.t('linters.inconsistent_quoting',
           count_single: single_quoted.count, count_double: double_quoted.count,
           example_single: %('#{single_quoted.first.name}'), example_double: %("#{double_quoted.first.name}")),
    feature
  )
end

#parametersObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chutney/linter/inconsistent_quoting.rb', line 27

def parameters
  parameters = []

  steps do |_feature, _child, step|
    step_parameters = step
                      .text
                      .scan(QUOTED_STRING)
                      .map { |p| p.take(2) } # close quote will match open quote: drop it
                      .map { |p| Parameter.new(*p) }
    parameters.concat(step_parameters)
  end

  parameters
end