rubocop-spellcheck 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +152 -45
- data/config/default.yml +11 -1
- data/lib/rubocop/cop/spellcheck/spelling.rb +49 -45
- data/lib/rubocop/spellcheck/asciidoc.rb +120 -0
- data/lib/rubocop/spellcheck/asciidoc_inline.rb +89 -0
- data/lib/rubocop/spellcheck/asciidoc_table.rb +49 -0
- data/lib/rubocop/spellcheck/checker.rb +6 -6
- data/lib/rubocop/spellcheck/correction.rb +66 -0
- data/lib/rubocop/spellcheck/front_matter.rb +49 -6
- data/lib/rubocop/spellcheck/front_matter_paths.rb +37 -0
- data/lib/rubocop/spellcheck/markdown.rb +34 -14
- data/lib/rubocop/spellcheck/markdown_directives.rb +83 -0
- data/lib/rubocop/spellcheck/markdown_ruby.rb +94 -0
- data/lib/rubocop/spellcheck/plugin.rb +1 -1
- data/lib/rubocop/spellcheck/prose_source.rb +1 -1
- data/lib/rubocop/spellcheck/rdoc.rb +140 -0
- data/lib/rubocop/spellcheck/rdoc_comments.rb +66 -0
- data/lib/rubocop/spellcheck/ruby_code.rb +37 -0
- data/lib/rubocop/spellcheck/ruby_identifiers.rb +54 -0
- data/lib/rubocop/spellcheck/ruby_string_map.rb +89 -0
- data/lib/rubocop/spellcheck/ruby_strings.rb +163 -0
- data/lib/rubocop/spellcheck/span.rb +35 -0
- data/lib/rubocop/spellcheck/version.rb +1 -1
- data/lib/rubocop/spellcheck/vocabulary.rb +94 -0
- data/lib/rubocop/spellcheck/vocabulary_config.rb +72 -0
- data/lib/rubocop/spellcheck/vocabulary_formatter.rb +47 -0
- data/lib/rubocop-spellcheck.rb +17 -0
- metadata +50 -5
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module RuboCop
|
|
6
|
+
module Spellcheck
|
|
7
|
+
# Updates only the generated dictionary setting, preserving surrounding configuration.
|
|
8
|
+
class VocabularyConfig
|
|
9
|
+
COP = 'Spellcheck/Spelling'
|
|
10
|
+
|
|
11
|
+
def initialize(path, section:)
|
|
12
|
+
@path = path
|
|
13
|
+
@section = section
|
|
14
|
+
@source = File.read(path, encoding: 'UTF-8')
|
|
15
|
+
@root = Psych.parse(@source)&.root
|
|
16
|
+
rescue Psych::SyntaxError => e
|
|
17
|
+
raise RuboCop::ValidationError, "Cannot update spelling configuration #{@path}: #{e.message}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def updated(dictionaries)
|
|
21
|
+
setting = YAML.dump('DictionaryFiles' => dictionaries).delete_prefix("---\n")
|
|
22
|
+
cop = value_for(@root, @section)
|
|
23
|
+
return append("#{@section}:\n#{indent(setting)}") unless cop
|
|
24
|
+
|
|
25
|
+
unless cop.is_a?(Psych::Nodes::Mapping) && cop.style == Psych::Nodes::Mapping::BLOCK
|
|
26
|
+
raise RuboCop::ValidationError, "Cannot generate spelling vocabulary for non-block #{@section} in #{@path}."
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
replace_setting(cop, setting)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def value_for(mapping, key)
|
|
35
|
+
return unless mapping.is_a?(Psych::Nodes::Mapping)
|
|
36
|
+
|
|
37
|
+
mapping.children.each_slice(2).find { |name, _value| name.value == key }&.last
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def indent(text, width = 2)
|
|
41
|
+
text.lines.map { |line| "#{' ' * width}#{line}" }.join
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def append(text)
|
|
45
|
+
if @root && @source.lines[@root.end_line]&.match?(/\A\.\.\.(?:\s|#|\z)/)
|
|
46
|
+
return @source.lines.insert(@root.end_line, "\n#{text}").join
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
"#{@source.rstrip}\n\n#{text}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def replace_setting(cop, setting)
|
|
53
|
+
lines = @source.lines
|
|
54
|
+
pair = cop.children.each_slice(2).find { |key, _value| key.value == 'DictionaryFiles' }
|
|
55
|
+
if pair
|
|
56
|
+
replace_pair(lines, pair, setting)
|
|
57
|
+
else
|
|
58
|
+
first = cop.children.first
|
|
59
|
+
lines.insert(first.start_line, indent(setting, first.start_column))
|
|
60
|
+
end
|
|
61
|
+
lines.join
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def replace_pair(lines, pair, setting)
|
|
65
|
+
key, value = pair
|
|
66
|
+
prefix = lines[value.end_line]&.slice(0, value.end_column)
|
|
67
|
+
last = value.end_line + (prefix && !prefix.strip.empty? ? 1 : 0)
|
|
68
|
+
lines[key.start_line...last] = [indent(setting, key.start_column)]
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Spellcheck
|
|
5
|
+
# Collects auto-generation results in the parent process, even when investigations are cached.
|
|
6
|
+
module VocabularyFormatter
|
|
7
|
+
def file_started(file, options)
|
|
8
|
+
@spellcheck_config_store = options.fetch(:config_store)
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def file_finished(file, offenses)
|
|
13
|
+
spelling, others = offenses.partition { |offense| offense.cop_name == VocabularyConfig::COP }
|
|
14
|
+
config = @spellcheck_config_store.for_file(file)
|
|
15
|
+
if !spelling.empty? || regenerating?(file, config)
|
|
16
|
+
@spellcheck_vocabularies ||= {}
|
|
17
|
+
vocabulary = (@spellcheck_vocabularies[config.loaded_path] ||= Vocabulary.new(config))
|
|
18
|
+
spelling.each { |offense| vocabulary.add(offense) }
|
|
19
|
+
end
|
|
20
|
+
super(file, others)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def finished(inspected_files)
|
|
24
|
+
@spellcheck_vocabularies&.each_value(&:write)
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def regenerating?(file, config)
|
|
31
|
+
return false unless spelling_selected?
|
|
32
|
+
return false unless File.exist?(File.join(config.base_dir_for_path_parameters, '.spellcheck.txt'))
|
|
33
|
+
|
|
34
|
+
@spellcheck_cops ||= {}
|
|
35
|
+
cop = (@spellcheck_cops[config.loaded_path] ||= RuboCop::Cop::Spellcheck::Spelling.new(config, @options))
|
|
36
|
+
config.for_badge(cop.class.badge)['Enabled'] && cop.relevant_file?(file)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def spelling_selected?
|
|
40
|
+
names = %w[Spellcheck Spellcheck/Spelling]
|
|
41
|
+
(!@options[:only] || @options[:only].intersect?(names)) && !@options.fetch(:except, []).intersect?(names)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
RuboCop::Formatter::DisabledConfigFormatter.prepend(RuboCop::Spellcheck::VocabularyFormatter)
|
data/lib/rubocop-spellcheck.rb
CHANGED
|
@@ -4,7 +4,24 @@ require 'rubocop'
|
|
|
4
4
|
require_relative 'rubocop/spellcheck/version'
|
|
5
5
|
require_relative 'rubocop/spellcheck/plugin'
|
|
6
6
|
require_relative 'rubocop/spellcheck/checker'
|
|
7
|
+
require_relative 'rubocop/spellcheck/vocabulary_config'
|
|
8
|
+
require_relative 'rubocop/spellcheck/vocabulary'
|
|
9
|
+
require_relative 'rubocop/spellcheck/vocabulary_formatter'
|
|
10
|
+
require_relative 'rubocop/spellcheck/correction'
|
|
11
|
+
require_relative 'rubocop/spellcheck/span'
|
|
12
|
+
require_relative 'rubocop/spellcheck/ruby_identifiers'
|
|
13
|
+
require_relative 'rubocop/spellcheck/ruby_string_map'
|
|
14
|
+
require_relative 'rubocop/spellcheck/ruby_strings'
|
|
15
|
+
require_relative 'rubocop/spellcheck/ruby_code'
|
|
16
|
+
require_relative 'rubocop/spellcheck/front_matter_paths'
|
|
7
17
|
require_relative 'rubocop/spellcheck/front_matter'
|
|
8
18
|
require_relative 'rubocop/spellcheck/markdown'
|
|
19
|
+
require_relative 'rubocop/spellcheck/markdown_directives'
|
|
20
|
+
require_relative 'rubocop/spellcheck/markdown_ruby'
|
|
21
|
+
require_relative 'rubocop/spellcheck/rdoc'
|
|
22
|
+
require_relative 'rubocop/spellcheck/rdoc_comments'
|
|
23
|
+
require_relative 'rubocop/spellcheck/asciidoc'
|
|
24
|
+
require_relative 'rubocop/spellcheck/asciidoc_inline'
|
|
25
|
+
require_relative 'rubocop/spellcheck/asciidoc_table'
|
|
9
26
|
require_relative 'rubocop/spellcheck/prose_source'
|
|
10
27
|
require_relative 'rubocop/cop/spellcheck/spelling'
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-spellcheck
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel (dB.) Doubrovkine
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: asciidoctor
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: commonmarker
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,6 +66,20 @@ dependencies:
|
|
|
52
66
|
- - "~>"
|
|
53
67
|
- !ruby/object:Gem::Version
|
|
54
68
|
version: '1.1'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rdoc
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '8.1'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '8.1'
|
|
55
83
|
- !ruby/object:Gem::Dependency
|
|
56
84
|
name: rubocop
|
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,8 +100,8 @@ dependencies:
|
|
|
72
100
|
- - ">="
|
|
73
101
|
- !ruby/object:Gem::Version
|
|
74
102
|
version: 1.72.1
|
|
75
|
-
description: RuboCop spelling checks for Ruby comments,
|
|
76
|
-
using offline dictionaries.
|
|
103
|
+
description: RuboCop spelling checks for Ruby comments, strings, identifiers, and
|
|
104
|
+
documentation, using offline dictionaries.
|
|
77
105
|
email:
|
|
78
106
|
- dblock@dblock.org
|
|
79
107
|
executables: []
|
|
@@ -90,12 +118,29 @@ files:
|
|
|
90
118
|
- data/en/en.dic
|
|
91
119
|
- lib/rubocop-spellcheck.rb
|
|
92
120
|
- lib/rubocop/cop/spellcheck/spelling.rb
|
|
121
|
+
- lib/rubocop/spellcheck/asciidoc.rb
|
|
122
|
+
- lib/rubocop/spellcheck/asciidoc_inline.rb
|
|
123
|
+
- lib/rubocop/spellcheck/asciidoc_table.rb
|
|
93
124
|
- lib/rubocop/spellcheck/checker.rb
|
|
125
|
+
- lib/rubocop/spellcheck/correction.rb
|
|
94
126
|
- lib/rubocop/spellcheck/front_matter.rb
|
|
127
|
+
- lib/rubocop/spellcheck/front_matter_paths.rb
|
|
95
128
|
- lib/rubocop/spellcheck/markdown.rb
|
|
129
|
+
- lib/rubocop/spellcheck/markdown_directives.rb
|
|
130
|
+
- lib/rubocop/spellcheck/markdown_ruby.rb
|
|
96
131
|
- lib/rubocop/spellcheck/plugin.rb
|
|
97
132
|
- lib/rubocop/spellcheck/prose_source.rb
|
|
133
|
+
- lib/rubocop/spellcheck/rdoc.rb
|
|
134
|
+
- lib/rubocop/spellcheck/rdoc_comments.rb
|
|
135
|
+
- lib/rubocop/spellcheck/ruby_code.rb
|
|
136
|
+
- lib/rubocop/spellcheck/ruby_identifiers.rb
|
|
137
|
+
- lib/rubocop/spellcheck/ruby_string_map.rb
|
|
138
|
+
- lib/rubocop/spellcheck/ruby_strings.rb
|
|
139
|
+
- lib/rubocop/spellcheck/span.rb
|
|
98
140
|
- lib/rubocop/spellcheck/version.rb
|
|
141
|
+
- lib/rubocop/spellcheck/vocabulary.rb
|
|
142
|
+
- lib/rubocop/spellcheck/vocabulary_config.rb
|
|
143
|
+
- lib/rubocop/spellcheck/vocabulary_formatter.rb
|
|
99
144
|
homepage: https://github.com/dblock/rubocop-spellcheck
|
|
100
145
|
licenses:
|
|
101
146
|
- MIT
|
|
@@ -124,5 +169,5 @@ requirements: []
|
|
|
124
169
|
rubygems_version: 3.5.16
|
|
125
170
|
signing_key:
|
|
126
171
|
specification_version: 4
|
|
127
|
-
summary: Spellcheck Ruby
|
|
172
|
+
summary: Spellcheck Ruby code and documentation with RuboCop.
|
|
128
173
|
test_files: []
|