Class: Mdlint::Linter::Rules::JapaneseCommaCount

Inherits:
Mdlint::Linter::Rule show all
Includes:
JapaneseHelpers
Defined in:
lib/mdlint/linter/rules/japanese.rb,
sig/internal.rbs

Constant Summary

Constants included from JapaneseHelpers

Mdlint::Linter::Rules::JapaneseHelpers::CJK, Mdlint::Linter::Rules::JapaneseHelpers::JAPANESE

Instance Attribute Summary

Attributes inherited from Mdlint::Linter::Rule

#violations

Instance Method Summary collapse

Methods included from JapaneseHelpers

#each_inline, #line_for, #prose_content

Methods inherited from Mdlint::Linter::Rule

#add_violation, #fix, inherited, #initialize

Constructor Details

This class inherits a constructor from Mdlint::Linter::Rule

Instance Method Details

#check(tokens, _source) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/mdlint/linter/rules/japanese.rb', line 136

def check(tokens, _source)
  maximum = @options.fetch(:max_commas, 3).to_i
  each_inline(tokens) do |token|
    prose_content(token).split(/(?<=[。!?!?])\s*/).each do |sentence|
      commas = sentence.count("、,")
      next unless commas > maximum

      add_violation(
        message: "Sentence contains #{commas} commas (maximum #{maximum})",
        line: line_for(token),
        fixable: false
      )
    end
  end
  @violations
end