alfonsox 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46aba9cc362ba13a198ed04c55a31f0c7ea8a8305f1ae89f8b89a7e39e6a3c97
4
- data.tar.gz: a4bd31552791e901798ceab360ddc4ad71f8fb342cd285009a1025750d9ccc59
3
+ metadata.gz: 1eb7a727afac3198e29057bfa16aa7ad179062015f281bae0ec51029ce8de4a4
4
+ data.tar.gz: a97c686d226547dfa8573621ccdb2cc406bbd2c18b43614e553fb0fb0a1f6c06
5
5
  SHA512:
6
- metadata.gz: 2dccb7d3ff2ac28df3273762787d5c32a7646c5395c1aa46caa9399c3a7b0c0c3b0c2e446d2a0fc72028c4def6786124fe42096576c1b2261cce99701a1fdf3d
7
- data.tar.gz: c74839001cc6b6f18d56d0393ad39676fb43f9af7c8b66eac070d74d8a3701cee1327602373b19df01656c2a69c4ed325da60e5ea38c40a3a4dc634980924f72
6
+ metadata.gz: f0d8372493aac5c40c420c12fcf8906dd4da59982735f23dc4d8c9dd019b98d50b0a417f6ce6d718ab1a553606e9af8164c0443a91e6e5cadfcf68ac3732e899
7
+ data.tar.gz: d27ac0b3ae3762e884fefde2fdd346a789a3b43ec8913379ae9b41f691da6029ef6aa93f2cdbc7d774ed1f414bb42d4127d03b82f82acf6f4f3ad0e634824a2a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alfonsox (0.2.7)
4
+ alfonsox (0.2.8)
5
5
  hunspell (~> 1.1, >= 1.1.0)
6
6
  nokogiri (~> 1.8, >= 1.8.5)
7
7
 
@@ -22,54 +22,55 @@ GEM
22
22
  descendants_tracker (~> 0.0.1)
23
23
  descendants_tracker (0.0.4)
24
24
  thread_safe (~> 0.3, >= 0.3.1)
25
- docile (1.3.1)
25
+ docile (1.3.2)
26
26
  equalizer (0.0.11)
27
- ffi (1.9.25)
28
- hirb (0.7.3)
27
+ ffi (1.11.1)
29
28
  hunspell (1.1.0)
30
29
  ice_nine (0.11.2)
31
30
  iniparse (1.4.4)
32
- jaro_winkler (1.5.1)
33
- json (2.1.0)
31
+ jaro_winkler (1.5.3)
32
+ json (2.2.0)
34
33
  kwalify (0.7.2)
35
34
  mini_portile2 (2.4.0)
36
35
  minitest (5.11.3)
37
36
  nokogiri (1.10.3)
38
37
  mini_portile2 (~> 2.4.0)
39
- overcommit (0.46.0)
38
+ overcommit (0.48.1)
40
39
  childprocess (~> 0.6, >= 0.6.3)
41
40
  iniparse (~> 1.4)
42
- parallel (1.12.1)
43
- parser (2.5.3.0)
41
+ parallel (1.17.0)
42
+ parser (2.6.3.0)
44
43
  ast (~> 2.4.0)
45
- powerpack (0.1.2)
44
+ psych (3.1.0)
46
45
  rainbow (3.0.0)
47
46
  rake (10.5.0)
48
- reek (5.2.0)
47
+ reek (5.4.0)
49
48
  codeclimate-engine-rb (~> 0.4.0)
50
49
  kwalify (~> 0.7.0)
51
- parser (>= 2.5.0.0, < 2.6, != 2.5.1.1)
50
+ parser (>= 2.5.0.0, < 2.7, != 2.5.1.1)
51
+ psych (~> 3.1.0)
52
52
  rainbow (>= 2.0, < 4.0)
53
- rubocop (0.60.0)
53
+ rubocop (0.72.0)
54
54
  jaro_winkler (~> 1.5.1)
55
55
  parallel (~> 1.10)
56
- parser (>= 2.5, != 2.5.1.1)
57
- powerpack (~> 0.1)
56
+ parser (>= 2.6)
58
57
  rainbow (>= 2.2.2, < 4.0)
59
58
  ruby-progressbar (~> 1.7)
60
- unicode-display_width (~> 1.4.0)
61
- ruby-progressbar (1.10.0)
62
- simplecov (0.16.1)
59
+ unicode-display_width (>= 1.4.0, < 1.7)
60
+ ruby-progressbar (1.10.1)
61
+ simplecov (0.17.0)
63
62
  docile (~> 1.1)
64
63
  json (>= 1.8, < 3)
65
64
  simplecov-html (~> 0.10.0)
66
- simplecov-console (0.4.2)
65
+ simplecov-console (0.5.0)
67
66
  ansi
68
- hirb
69
67
  simplecov
68
+ terminal-table
70
69
  simplecov-html (0.10.2)
70
+ terminal-table (1.8.0)
71
+ unicode-display_width (~> 1.1, >= 1.1.1)
71
72
  thread_safe (0.3.6)
72
- unicode-display_width (1.4.0)
73
+ unicode-display_width (1.6.0)
73
74
  virtus (1.0.5)
74
75
  axiom-types (~> 0.1)
75
76
  coercible (~> 1.0)
data/README.md CHANGED
@@ -79,7 +79,14 @@ Dictionaries:
79
79
  type: 'rubymine'
80
80
  # Optional, by default is '.idea/dictionary.xml'
81
81
  path: '.idea/dictionary.xml'
82
-
82
+
83
+ # Include in this section a file path with a list of custom words or words
84
+ # Note the file must contain a word per line
85
+ # that do not appear in other dictionaries
86
+ WordListFileictionary:
87
+ type: 'word_list'
88
+ path: 'your/word/list/file/path'
89
+
83
90
  # Include in this section a list of custom words or words
84
91
  # that do not appear in other dictionaries
85
92
  WordListDictionary:
@@ -150,72 +157,30 @@ $ echo $?
150
157
 
151
158
  ### Overcommit integration
152
159
 
153
- [Overcommit](https://github.com/sds/overcommit)
154
- is a project whose aim is to provide developers
160
+ Easiest way of use this project is to use [Overcommit](https://github.com/sds/overcommit).
161
+ For those of you that don't know it, it is a project whose aim is to provide developers
155
162
  with tools to check code quality easily.
156
163
 
157
- [Define a new pre-commit hook in your repository](https://github.com/sds/overcommit#repo-specific-hooks):
158
-
159
- Add a file **.git-hooks/pre_commit/alfonsox.rb** with the following contents:
160
-
161
- ```ruby
162
- # frozen_string_literal: true
163
-
164
- module Overcommit::Hook::PreCommit
165
- #
166
- # Spell check of the code.
167
- #
168
- class AlfonsoX < Base
169
- def run
170
- # Create default file config if it does not exist
171
-
172
- # Run rake spellcheck task
173
- args = flags + applicable_files
174
- result = execute('bundle exec alfonsox', args: args)
175
- spellchecking_errors = result.split('\n')
176
-
177
- # Check the if there are spelling errors
178
- return :pass if spellchecking_errors.length.zero?
179
-
180
- error_messages(spellchecking_errors)
181
- end
182
-
183
- private
184
-
185
- # Create the error messages
186
- def error_messages(spellchecking_errors)
187
- messages = []
188
- spellchecking_errors.each do |spellchecking_error_i|
189
- error_location, word = spellchecking_error_i.split(' ')
190
- error_file_path, line = error_location.split(':')
191
- messages << Overcommit::Hook::Message.new(
192
- :error, error_file_path, line, "#{error_location}: #{word}"
193
- )
194
- end
195
- messages
196
- end
197
- end
198
- end
199
- ```
200
-
201
- Make sure you have a configuration in the root directory of your project with
202
- the name **.alfonsox.yml**:
164
+ It has a
165
+ [CodeSpellCheck](https://github.com/sds/overcommit/blob/master/lib/overcommit/hook/pre_commit/code_spell_check.rb)
166
+ pre-commit hook that accepts an Alfonso X configuration, by default is:
203
167
 
204
168
  ```yml
205
169
  Paths:
206
- - '*/**.rb'
170
+ - 'app/*/**.rb'
171
+ - 'lib/**.rb'
172
+ - 'test/**.rb'
207
173
  Dictionaries:
208
174
  EnglishDictionaryFromGem:
209
175
  type: 'hunspell'
210
176
  language: 'en_US'
211
177
  RubymineDictionary:
212
178
  type: 'rubymine'
213
- WordListDictionary:
214
- type: 'word_list'
215
- word_list:
216
- - 'alfonso'
217
179
  ```
218
180
 
181
+ If you want to overwrite it, create an **.alfonsox.yml** file in your
182
+ home directory and write your custom spell-check configuration there.
183
+
219
184
  ### From code
220
185
 
221
186
  #### Load dictionaries
@@ -288,7 +253,7 @@ I accept contribution and feature requests via PR (GitHub pull requests).
288
253
  Create an issue or send me an email before making a PR
289
254
  if you are unsure about if your PR is going to be accepted.
290
255
 
291
- Any constructive criticism is welcomed.
256
+ Any suggestion, issue or constructive criticism is also welcomed.
292
257
 
293
258
  ## Why the name?
294
259
 
@@ -3,4 +3,5 @@
3
3
  require 'alfonsox/spellchecker/dictionary/rubymine'
4
4
  require 'alfonsox/spellchecker/dictionary/hunspell'
5
5
  require 'alfonsox/spellchecker/dictionary/word_list'
6
+ require 'alfonsox/spellchecker/dictionary/word_list_file'
6
7
  require 'alfonsox/spellchecker/dictionary/default'
@@ -10,7 +10,7 @@ module AlfonsoX
10
10
  class Hunspell
11
11
  # Default hunspell dictionary path
12
12
  DEFAULT_PATH = "#{AlfonsoX::DICTIONARIES_PATH}/hunspell"
13
- # All atributtes are readable
13
+ # All attributes are readable
14
14
  attr_reader :language, :path
15
15
 
16
16
  # Construct a hunspell dictionary object for this package
@@ -25,14 +25,12 @@ module AlfonsoX
25
25
  new(yml_config['language'], yml_config.fetch('path') { DEFAULT_PATH })
26
26
  end
27
27
 
28
+ # Inform if a word is present in this dictionary.
28
29
  def word_present?(word)
29
30
  @spellchecker.spellcheck(word)
30
31
  end
31
32
 
32
- def similar_words(word)
33
- @spellchecker.suggest(word)
34
- end
35
-
33
+ # Initialize spellchecker attribute
36
34
  def initialize_spellchecker(path)
37
35
  dictionary_finder = DictionaryFinder.new(@language, path)
38
36
  raise "'#{@language}' language Hunspell dictionary not found" unless dictionary_finder.find
@@ -14,23 +14,23 @@ module AlfonsoX
14
14
  DEFAULT_PATH = '.idea/dictionaries'
15
15
  attr_reader :path
16
16
 
17
+ # Initialize Rubymine dictionary
18
+ # If path is not present, it will be loaded from #DEFAULT_PATH.
17
19
  def initialize(path = nil)
18
20
  @path = path || DEFAULT_PATH
19
21
  load_dictionaries
20
22
  end
21
23
 
24
+ # Load configuration from YML
22
25
  def self.from_config(yml_config)
23
26
  new(yml_config.fetch('path') { DEFAULT_PATH })
24
27
  end
25
28
 
29
+ # Inform if a word is present in this dictionary.
26
30
  def word_present?(word)
27
31
  @words.include?(word.downcase)
28
32
  end
29
33
 
30
- def similar_words(_word)
31
- []
32
- end
33
-
34
34
  private
35
35
 
36
36
  def load_dictionaries
@@ -8,16 +8,20 @@ module AlfonsoX
8
8
  module Dictionary
9
9
  # Custom dictionary loader composed by a word list
10
10
  class WordList
11
+ attr_reader :words
12
+
11
13
  # Initialize a AlfonsoX::SpellChecker::Dictionary::WordList
12
14
  # @param [Array<String>] word_list Words that are included in this dictionary
13
15
  def initialize(word_list)
14
16
  @words = word_list.map(&:downcase)
15
17
  end
16
18
 
19
+ # Load from Yml
17
20
  def self.from_config(yml_config)
18
21
  new(yml_config.fetch('word_list') { [] })
19
22
  end
20
23
 
24
+ # Inform if a word is present in this dictionary.
21
25
  def word_present?(word)
22
26
  @words.include?(word.downcase)
23
27
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+
5
+ # Alfonso X module
6
+ module AlfonsoX
7
+ module SpellChecker
8
+ module Dictionary
9
+ # Custom dictionary loader composed by a word list from a file
10
+ class WordListFile
11
+ attr_reader :words
12
+
13
+ # Initialize a AlfonsoX::SpellChecker::Dictionary::WordListFile from a file path.
14
+ # Note the words must be in different lines.
15
+ # @param [String] word_list_file_path Word list file path.
16
+ def initialize(word_list_file_path)
17
+ word_list = ::File.readlines(word_list_file_path).map(&:chomp)
18
+ @words = word_list.map(&:downcase)
19
+ end
20
+
21
+ # Load from Yml
22
+ def self.from_config(yml_config)
23
+ new(yml_config['path'])
24
+ end
25
+
26
+ # Inform if a word is present in this dictionary.
27
+ def word_present?(word)
28
+ @words.include?(word.downcase)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -35,6 +35,7 @@ module AlfonsoX
35
35
  return AlfonsoX::SpellChecker::Dictionary::Hunspell if config_dictionary_type == 'hunspell'
36
36
  return AlfonsoX::SpellChecker::Dictionary::Rubymine if config_dictionary_type == 'rubymine'
37
37
  return AlfonsoX::SpellChecker::Dictionary::WordList if config_dictionary_type == 'word_list'
38
+ return AlfonsoX::SpellChecker::Dictionary::WordListFile if config_dictionary_type == 'word_list_file'
38
39
  raise "Dictionary type #{config_dictionary_type} is not recognized"
39
40
  end
40
41
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AlfonsoX
4
- VERSION = '0.2.7'
4
+ VERSION = '0.2.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alfonsox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego J. Romero López
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-29 00:00:00.000000000 Z
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hunspell
@@ -135,6 +135,7 @@ files:
135
135
  - lib/alfonsox/spellchecker/dictionary/hunspell.rb
136
136
  - lib/alfonsox/spellchecker/dictionary/rubymine.rb
137
137
  - lib/alfonsox/spellchecker/dictionary/word_list.rb
138
+ - lib/alfonsox/spellchecker/dictionary/word_list_file.rb
138
139
  - lib/alfonsox/spellchecker/file.rb
139
140
  - lib/alfonsox/spellchecker/main.rb
140
141
  - lib/alfonsox/spellchecker/word.rb