Class: YARD::CLI::Spellcheck

Inherits:
Command
  • Object
show all
Includes:
Spellcheck::Printer
Defined in:
lib/yard/cli/spellcheck.rb

Overview

The yard-spellcheck command.

Constant Summary

Constants included from Spellcheck::Printer

Spellcheck::Printer::HIGHLIGHT, Spellcheck::Printer::UNHIGHLIGHT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Spellcheck::Printer

#print_stats, #print_text, #print_typos

Constructor Details

#initializeSpellcheck

Initializes the spellcheck command.



17
18
19
20
21
# File 'lib/yard/cli/spellcheck.rb', line 17

def initialize
  @checker = YARD::Spellcheck::Checker.new
  @names = []
  @stats = false
end

Instance Attribute Details

#checkerObject (readonly)

The spellchecker.



12
13
14
# File 'lib/yard/cli/spellcheck.rb', line 12

def checker
  @checker
end

Instance Method Details

#descriptionString

The command description.

Returns:

  • (String)

    Description.



29
30
31
# File 'lib/yard/cli/spellcheck.rb', line 29

def description
  'Spellchecks YARD documentation'
end

#optparse(*args) ⇒ Object (protected)

Parses the command options.

Parameters:

  • args (Array<String>)

    The arguments for the command.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/yard/cli/spellcheck.rb', line 66

def optparse(*args)
  opts = OptionParser.new
  opts.banner = "Usage: yard spellcheck [options]"
  opts.separator ""
  opts.separator description
  opts.separator ""

  opts.on('-D','--dict-dir DIR','Dictionary directory') do |dir|
    FFI::Hunspell.directories << File.expand_path(dir)
  end

  opts.on('-c','--check [CLASS | MODULE]','Classes/Modules to spellcheck') do |name|
    @names << name
  end

  opts.on('-L','--lang LANG','Language to spellcheck for') do |lang|
    @checker.lang = lang
  end

  opts.on('-I','--ignore WORD','Words to ignore') do |word|
    @checker.ignore << word
  end

  opts.on('-a','--add WORD [...]','Adds a word') do |word|
    @checker.added << word
  end

  opts.on('-S','--statistics','Print statistics') do
    @stats = true
  end

  common_options(opts)
  parse_options(opts,args)
end

#run(*args) ⇒ Object

Runs the spellcheck command.

Parameters:

  • args (Array<String>)

    The arguments for the command.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/yard/cli/spellcheck.rb', line 39

def run(*args)
  optparse(*args)

  CLI::Yardoc.run('-c', '-n', '--no-stats')

  @checker.check!(@names) do |element,typos|
    print_typos element, typos
  end

  if @stats
    puts "Statistics"
    print_stats @checker
  end

  exit -1 unless @checker.misspelled.empty?
end