yast-rake 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/tasks/spell.yml +50 -0
- data/lib/tasks/spellcheck.rake +2 -94
- data/lib/tasks/spellcheck_task.rb +170 -0
- metadata +4 -3
- data/lib/tasks/spell.dict +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6064a1a8380fe02784d5f7009d4c700aa8d7980c
|
4
|
+
data.tar.gz: 12db5b4793732221de0f81a7e94941e66d7d825d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aeb3e3082628dc89e9c39c794f2eaba7914ff167de09d33fbed35289beb22027a39b9f95f309d3f8163cd4018e1af431e0e35755804a12634aa44e3a09b56e3e
|
7
|
+
data.tar.gz: eba47c56dda60084cd00e3dc6e447c289250d0554a6f384176c1179a928bc7564243b0c9acfb4aa8f96860e0e19a9a160d969cfdff931c021a18988a6f4f5fa6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/tasks/spell.yml
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# This is the global spellcheck config shared by all YaST repositories.
|
2
|
+
|
3
|
+
---
|
4
|
+
check:
|
5
|
+
- "**/*.html"
|
6
|
+
- "**/*.md"
|
7
|
+
ignore: []
|
8
|
+
dictionary:
|
9
|
+
#
|
10
|
+
# Notes: Write the words in alphabetical order, if an unknown word
|
11
|
+
# is not generic put it into the repository specific dictionary.
|
12
|
+
#
|
13
|
+
- API
|
14
|
+
- bnc
|
15
|
+
- boolean
|
16
|
+
- Bugzilla
|
17
|
+
- devel
|
18
|
+
- DHCP
|
19
|
+
- freenode
|
20
|
+
- gh
|
21
|
+
- GitHub
|
22
|
+
- GitHub's
|
23
|
+
- html
|
24
|
+
- IRC
|
25
|
+
- LDAP
|
26
|
+
- md
|
27
|
+
- NCurses
|
28
|
+
- NFS
|
29
|
+
- NIS
|
30
|
+
- openSUSE
|
31
|
+
- osc
|
32
|
+
- Rakefile
|
33
|
+
- rb
|
34
|
+
- refactorings
|
35
|
+
- RSpec
|
36
|
+
- runlevel
|
37
|
+
- SCR
|
38
|
+
- SLP
|
39
|
+
- sudo
|
40
|
+
- SUSE
|
41
|
+
- systemd
|
42
|
+
- testsuite
|
43
|
+
- UI
|
44
|
+
- WFM
|
45
|
+
- workflow
|
46
|
+
- yast
|
47
|
+
- YaST
|
48
|
+
- ycp
|
49
|
+
- YCP
|
50
|
+
- zypper
|
data/lib/tasks/spellcheck.rake
CHANGED
@@ -28,97 +28,5 @@
|
|
28
28
|
# The lines starting with '#' character are ignored (used for comments),
|
29
29
|
#
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def read_dictionary_file(file)
|
35
|
-
puts "Loading custom dictionary (#{file})..." if verbose == true
|
36
|
-
words = File.read(file).split("\n")
|
37
|
-
|
38
|
-
# remove comments
|
39
|
-
words.reject! { |word| word.start_with?("#")}
|
40
|
-
words.each(&:chomp!)
|
41
|
-
end
|
42
|
-
|
43
|
-
# read the global and the repository custom dictionary
|
44
|
-
def read_custom_words
|
45
|
-
# read the global default custom dictionary
|
46
|
-
dict_path = File.expand_path("../#{GLOBAL_DICTIONARY_FILE}", __FILE__)
|
47
|
-
custom_words = read_dictionary_file(dict_path)
|
48
|
-
|
49
|
-
# read the custom dictionary from the project directory if present
|
50
|
-
dict_path = CUSTOM_DICTIONARY_FILE
|
51
|
-
if File.exist?(dict_path)
|
52
|
-
local_dict = read_dictionary_file(dict_path)
|
53
|
-
duplicates = custom_words & local_dict
|
54
|
-
|
55
|
-
if !duplicates.empty?
|
56
|
-
$stderr.puts "Warning: Found duplicates in the local dictionary (#{dict_path}):\n"
|
57
|
-
duplicates.each {|duplicate| $stderr.puts " #{duplicate}" }
|
58
|
-
$stderr.puts
|
59
|
-
end
|
60
|
-
|
61
|
-
custom_words += local_dict - duplicates
|
62
|
-
end
|
63
|
-
|
64
|
-
custom_words
|
65
|
-
end
|
66
|
-
|
67
|
-
def aspell_speller
|
68
|
-
# raspell is an optional dependency, handle the missing case nicely
|
69
|
-
begin
|
70
|
-
require "raspell"
|
71
|
-
rescue LoadError
|
72
|
-
$stderr.puts "ERROR: Ruby gem \"raspell\" is not installed."
|
73
|
-
exit 1
|
74
|
-
end
|
75
|
-
|
76
|
-
# initialize aspell
|
77
|
-
speller = Aspell.new("en_US")
|
78
|
-
speller.suggestion_mode = Aspell::NORMAL
|
79
|
-
# ignore the HTML tags in the text
|
80
|
-
speller.set_option("mode", "html")
|
81
|
-
|
82
|
-
speller
|
83
|
-
end
|
84
|
-
|
85
|
-
namespace :check do
|
86
|
-
desc "Run spell checker (by default for *.md and *.html files in Git)"
|
87
|
-
task :spelling, :regexp do |t, args|
|
88
|
-
regexp = args[:regexp] || /\.(md|html)\z/
|
89
|
-
success = true
|
90
|
-
|
91
|
-
files = `git ls-files . | grep -v \\.gitignore`.split("\n")
|
92
|
-
files.select!{|file| file.match(regexp)}
|
93
|
-
|
94
|
-
custom_words = read_custom_words
|
95
|
-
speller = aspell_speller
|
96
|
-
|
97
|
-
files.each do |file|
|
98
|
-
puts "Checking #{file}..." if verbose == true
|
99
|
-
# spell check each line separately so we can report error locations properly
|
100
|
-
lines = File.read(file).split("\n")
|
101
|
-
|
102
|
-
lines.each_with_index do |text, index|
|
103
|
-
misspelled = speller.list_misspelled([text]) - custom_words
|
104
|
-
|
105
|
-
if !misspelled.empty?
|
106
|
-
success = false
|
107
|
-
puts "#{file}:#{index + 1}: #{text.inspect}"
|
108
|
-
misspelled.each do |word|
|
109
|
-
puts " #{word.inspect} => #{speller.suggest(word)}"
|
110
|
-
end
|
111
|
-
puts
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
if success
|
117
|
-
puts "Spelling OK."
|
118
|
-
else
|
119
|
-
$stderr.puts "Spellcheck failed! (Fix it or add the words to " \
|
120
|
-
"'#{CUSTOM_DICTIONARY_FILE}' file if it is OK.)"
|
121
|
-
exit 1
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
31
|
+
require_relative "spellcheck_task"
|
32
|
+
Yast::SpellcheckTask.new
|
@@ -0,0 +1,170 @@
|
|
1
|
+
#--
|
2
|
+
# Yast rake
|
3
|
+
#
|
4
|
+
# Copyright (C) 2015 Novell, Inc.
|
5
|
+
# This library is free software; you can redistribute it and/or modify
|
6
|
+
# it only under the terms of version 2.1 of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful, but WITHOUT
|
10
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
11
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
12
|
+
# details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
#++
|
18
|
+
#
|
19
|
+
# Rake task for checking spelling in the documentation files.
|
20
|
+
# By default checks all *.md and *.html files.
|
21
|
+
#
|
22
|
+
# Supports custom dictionaries:
|
23
|
+
#
|
24
|
+
# - global dictionary located in the tasks gem (lib/tasks/spell.yml)
|
25
|
+
# - repository specific dictionary (.spell.yml in the root directory)
|
26
|
+
#
|
27
|
+
# The custom dictionaries are defined at the "dictionary" key.
|
28
|
+
#
|
29
|
+
|
30
|
+
require 'rake'
|
31
|
+
require 'rake/tasklib'
|
32
|
+
|
33
|
+
module Yast
|
34
|
+
# Defines a spellcheck rake task
|
35
|
+
class SpellcheckTask < Rake::TaskLib
|
36
|
+
GLOBAL_SPELL_CONFIG_FILE = File.expand_path("../spell.yml", __FILE__)
|
37
|
+
CUSTOM_SPELL_CONFIG_FILE = ".spell.yml"
|
38
|
+
|
39
|
+
# define the Rake task in the constructor
|
40
|
+
def initialize
|
41
|
+
namespace :check do
|
42
|
+
desc "Run spell checker (by default for *.md and *.html files)"
|
43
|
+
task :spelling do
|
44
|
+
run_task
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# optionally colorize the misspelled words if the rainbow gem is present
|
53
|
+
# @return [Boolean] true when the colorization support is present
|
54
|
+
def colorize?
|
55
|
+
return @colorize unless @colorize.nil?
|
56
|
+
|
57
|
+
begin
|
58
|
+
require "rainbow"
|
59
|
+
@colorize = true
|
60
|
+
rescue LoadError
|
61
|
+
@colorize = false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# create an Aspell speller object
|
66
|
+
# @return [Aspell] the speller object
|
67
|
+
def speller
|
68
|
+
return @speller if @speller
|
69
|
+
# raspell is an optional dependency, handle the missing case nicely
|
70
|
+
begin
|
71
|
+
require "raspell"
|
72
|
+
rescue LoadError
|
73
|
+
$stderr.puts "ERROR: Ruby gem \"raspell\" is not installed."
|
74
|
+
exit 1
|
75
|
+
end
|
76
|
+
|
77
|
+
# initialize aspell
|
78
|
+
@speller = Aspell.new("en_US")
|
79
|
+
@speller.suggestion_mode = Aspell::NORMAL
|
80
|
+
# ignore the HTML tags in the text
|
81
|
+
@speller.set_option("mode", "html")
|
82
|
+
|
83
|
+
@speller
|
84
|
+
end
|
85
|
+
|
86
|
+
# evaluate the files to check
|
87
|
+
# @return [Array<String>] list of files
|
88
|
+
def files_to_check
|
89
|
+
files = config["check"].reduce([]) {|acc, glob| acc + Dir[glob]}
|
90
|
+
config["ignore"].reduce(files) {|acc, glob| acc - Dir[glob]}
|
91
|
+
end
|
92
|
+
|
93
|
+
# read a Yaml config file
|
94
|
+
def read_spell_config(file)
|
95
|
+
return {} unless File.exist?(file)
|
96
|
+
|
97
|
+
puts "Loading config file (#{file})..." if verbose == true
|
98
|
+
require "yaml"
|
99
|
+
YAML.load_file(file)
|
100
|
+
end
|
101
|
+
|
102
|
+
# print the duplicate dictionary entries
|
103
|
+
# @param dict1 [Array<String>] the first dictionary
|
104
|
+
# @param dict2 [Array<String>] the second dictionary
|
105
|
+
def report_duplicates(dict1, dict2)
|
106
|
+
duplicates = dict1 & dict2
|
107
|
+
return if duplicates.empty?
|
108
|
+
|
109
|
+
$stderr.puts "Warning: Found dictionary duplicates in the local dictionary " \
|
110
|
+
"(#{CUSTOM_SPELL_CONFIG_FILE}):\n"
|
111
|
+
duplicates.each {|duplicate| $stderr.puts " #{duplicate}" }
|
112
|
+
$stderr.puts
|
113
|
+
end
|
114
|
+
|
115
|
+
# return the merged global and the custom spell configs
|
116
|
+
# @return [Hash] the merged configuration to use
|
117
|
+
def config
|
118
|
+
return @config if @config
|
119
|
+
|
120
|
+
@config = read_spell_config(GLOBAL_SPELL_CONFIG_FILE)
|
121
|
+
custom_config = read_spell_config(CUSTOM_SPELL_CONFIG_FILE)
|
122
|
+
|
123
|
+
report_duplicates(config["dictionary"], custom_config["dictionary"].to_a)
|
124
|
+
|
125
|
+
custom_config["dictionary"] = @config["dictionary"] + custom_config["dictionary"].to_a
|
126
|
+
custom_config["dictionary"].uniq!
|
127
|
+
|
128
|
+
# override the global values by the local if present
|
129
|
+
@config.merge!(custom_config)
|
130
|
+
|
131
|
+
@config
|
132
|
+
end
|
133
|
+
|
134
|
+
# check the file using the spellchecker
|
135
|
+
# @param file [String] file name
|
136
|
+
# @return [Boolean] true on success (no spelling error found)
|
137
|
+
def check_file(file)
|
138
|
+
puts "Checking #{file}..." if verbose == true
|
139
|
+
# spell check each line separately so we can report error locations properly
|
140
|
+
lines = File.read(file).split("\n")
|
141
|
+
|
142
|
+
success = true
|
143
|
+
lines.each_with_index do |text, index|
|
144
|
+
misspelled = speller.list_misspelled([text]) - config["dictionary"]
|
145
|
+
next if misspelled.empty?
|
146
|
+
|
147
|
+
success = false
|
148
|
+
misspelled.each {|word| text.gsub!(word, Rainbow(word).red)} if colorize?
|
149
|
+
puts "#{file}:#{index + 1}: \"#{text}\""
|
150
|
+
|
151
|
+
misspelled.each { |word| puts " #{word.inspect} => #{speller.suggest(word)}" }
|
152
|
+
puts
|
153
|
+
end
|
154
|
+
|
155
|
+
success
|
156
|
+
end
|
157
|
+
|
158
|
+
# run the task
|
159
|
+
def run_task
|
160
|
+
if files_to_check.all? { |file| check_file(file) }
|
161
|
+
puts "Spelling OK."
|
162
|
+
else
|
163
|
+
$stderr.puts "Spellcheck failed! (Fix it or add the words to " \
|
164
|
+
"'#{CUSTOM_SPELL_CONFIG_FILE}' file if it is OK.)"
|
165
|
+
exit 1
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yast-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Reidinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,8 +52,9 @@ files:
|
|
52
52
|
- lib/tasks/install.rake
|
53
53
|
- lib/tasks/pot.rake
|
54
54
|
- lib/tasks/run.rake
|
55
|
-
- lib/tasks/spell.
|
55
|
+
- lib/tasks/spell.yml
|
56
56
|
- lib/tasks/spellcheck.rake
|
57
|
+
- lib/tasks/spellcheck_task.rb
|
57
58
|
- lib/tasks/test_unit.rake
|
58
59
|
- lib/tasks/version.rake
|
59
60
|
- lib/yast/rake.rb
|
data/lib/tasks/spell.dict
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# This is the global custom dictionary shared with all YaST repositories.
|
2
|
-
#
|
3
|
-
# Write the words in alphabetical order, one word per line.
|
4
|
-
# If an unknown word is not generic put it into the repository specific dictionary.
|
5
|
-
#
|
6
|
-
API
|
7
|
-
bnc
|
8
|
-
boolean
|
9
|
-
Bugzilla
|
10
|
-
devel
|
11
|
-
DHCP
|
12
|
-
freenode
|
13
|
-
gh
|
14
|
-
GitHub
|
15
|
-
GitHub's
|
16
|
-
html
|
17
|
-
IRC
|
18
|
-
LDAP
|
19
|
-
md
|
20
|
-
NCurses
|
21
|
-
NFS
|
22
|
-
NIS
|
23
|
-
openSUSE
|
24
|
-
osc
|
25
|
-
Rakefile
|
26
|
-
rb
|
27
|
-
refactorings
|
28
|
-
RSpec
|
29
|
-
runlevel
|
30
|
-
SCR
|
31
|
-
SLP
|
32
|
-
sudo
|
33
|
-
SUSE
|
34
|
-
systemd
|
35
|
-
testsuite
|
36
|
-
UI
|
37
|
-
WFM
|
38
|
-
workflow
|
39
|
-
yast
|
40
|
-
YaST
|
41
|
-
ycp
|
42
|
-
YCP
|
43
|
-
zypper
|