Class: Danger::DangerTypos

Inherits:
Plugin
  • Object
show all
Defined in:
lib/typos/plugin.rb

Overview

[Danger](danger.systems/ruby/) plugin for [typos](github.com/crate-ci/typos).

Examples:

Run typos and send warn comment.


typos.binary_path = "path/to/typos"
typos.run

See Also:

  • ktakayama/danger-typos

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binary_pathString

typos path

Returns:

  • (String)


20
21
22
# File 'lib/typos/plugin.rb', line 20

def binary_path
  @binary_path
end

Instance Method Details

#run(options = {}) ⇒ void

This method returns an undefined value.

Execute typos



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/typos/plugin.rb', line 24

def run(options = {})
  return if target_files.empty?

  args = [
    "--force-exclude",
    "--format", "json"
  ]
  args.push("--config", options[:config_path]) if options[:config_path]
  args += target_files

  stdout, = Open3.capture3(cmd_path, *args)

  stdout.split("\n").each do |result|
    data = JSON.parse(result)
    next if data["type"] != "typo"

    warn(
      "`#{data['typo']}` should be `#{data['corrections'].first}`",
      file: data["path"],
      line: data["line_num"]
    )
  end
end