pronto-spell 0.9.0 → 0.10.0

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
- SHA1:
3
- metadata.gz: b48a03947913a699f51a206f08c8c08e98d77e7e
4
- data.tar.gz: 9c91c12ce5c3c44fa8734bcf2c25a0ab49f97c88
2
+ SHA256:
3
+ metadata.gz: d1f4b64675918e0fa51a628c161e4bbbaf774fca7a1f6508e22d4b9f8f7e8402
4
+ data.tar.gz: 6b6a768dd4ac49a4762334b68d3d8507af3f23567eac72372fcdb6c2c86a9ad8
5
5
  SHA512:
6
- metadata.gz: 7bd867909c671bc2128151eb7e459480a7dc5e0c7729120792784d655d45a1a524cb5a382aced39b4c1f4b5b36b3d9d3886a78107afd066f95a9791a5bbec5b9
7
- data.tar.gz: d81acc29bc13733138f598a36e8770099c5a756322c70119d9ead32b418aadff4124f0e4ad35fda29e0b4e7092e9624d283d23002b6a2882ff26fa36bc20c239
6
+ metadata.gz: 3a0a4d6c9e9eacc0e35fcd3263ae89c00d189b1fc0366666195cdbfe1a01ceb07efe7235eca8516d53cc7a489cb242c414bc3a18df671107907c86b580fe39e7
7
+ data.tar.gz: 557c522a42ae028a0c9db1d5a25267ed07c6b70f17264f815fec6020ee2433257834eda90a5f6db5495a6f92e0faa0bf7b42b9ccd67ad32621363c5754ae558c
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Pronto runner that uses Aspell for spell checking
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/mmozuras/pronto-spell.png)](https://codeclimate.com/github/mmozuras/pronto-spell)
4
- [![Build Status](https://travis-ci.org/mmozuras/pronto-spell.png)](https://travis-ci.org/mmozuras/pronto-spell)
3
+ [![Code Climate](https://codeclimate.com/github/prontolabs/pronto-spell.png)](https://codeclimate.com/github/prontolabs/pronto-spell)
4
+ [![Build Status](https://travis-ci.org/prontolabs/pronto-spell.png)](https://travis-ci.org/prontolabs/pronto-spell)
5
5
  [![Gem Version](https://badge.fury.io/rb/pronto-spell.png)](http://badge.fury.io/rb/pronto-spell)
6
- [![Dependency Status](https://gemnasium.com/mmozuras/pronto-spell.png)](https://gemnasium.com/mmozuras/pronto-spell)
6
+ [![Dependency Status](https://gemnasium.com/prontolabs/pronto-spell.png)](https://gemnasium.com/prontolabs/pronto-spell)
7
7
 
8
- Pronto runner that uses [Aspell](https://github.com/YorickPeterse/ffi-aspell) for spell checking. [What is Pronto?](https://github.com/mmozuras/pronto)
8
+ Pronto runner that uses [Aspell](https://github.com/YorickPeterse/ffi-aspell) for spell checking. [What is Pronto?](https://github.com/prontolabs/pronto)
9
9
 
10
10
  ## Prerequisites
11
11
 
@@ -13,3 +13,30 @@ You'll need to install Aspell:
13
13
 
14
14
  * Arch Linux: `sudo pacman -S aspell`
15
15
  * OS X: (`brew install aspell --lang=en`)
16
+
17
+ ## Configuration
18
+
19
+ In order to change configuration, you need to create `.pronto_spell.yaml` file in your project root directory. Awailable options are:
20
+
21
+ ```YAML
22
+ suggestion_mode: 'fast' # default
23
+ min_word_length: 5 # default
24
+ max_word_length: 999 # default is Infinity
25
+ max_suggestions_number: 3 # default
26
+ ignored_words: # words in this list won't be marked as misspelled
27
+ - aspell
28
+ - boolean
29
+ - datetime
30
+ ```
31
+
32
+ It's also handy to have `.pronto.yml`. Here is configuration, designed for rails project:
33
+ ```YAML
34
+ spell:
35
+ exclude:
36
+ - 'yarn.lock'
37
+ - 'Gemfile.lock'
38
+ - 'Gemfile'
39
+ - 'package.json'
40
+ - '.*.yml'
41
+ - '*.json'
42
+ ```
@@ -3,20 +3,33 @@ require 'ffi/aspell'
3
3
 
4
4
  module Pronto
5
5
  class Spell < Runner
6
+ CONFIG_FILE = '.pronto_spell.yml'.freeze
7
+
8
+ def ignored_words
9
+ @ignored_words ||= begin
10
+ words = (spelling_config['ignored_words'] || []).map(&:downcase)
11
+ Set.new(words)
12
+ end
13
+ end
14
+
6
15
  def run
7
- return [] unless @patches
16
+ return [] if !@patches || @patches.count.zero?
8
17
 
9
- @patches.select { |patch| patch.additions > 0 }
18
+ @patches
19
+ .select { |patch| patch.additions > 0 }
10
20
  .map { |patch| inspect(patch) }
11
21
  .flatten.compact
12
22
  end
13
23
 
24
+ private
25
+
14
26
  def inspect(patch)
15
27
  patch.added_lines.map do |line|
16
- words = line.content.scan(/[0-9a-zA-Z]+/)
17
- words.select { |word| word.length > 4 }
18
- .uniq
19
- .select { |word| !speller.correct?(word) }
28
+ words = line.content.scan(/([A-Z]{2,})|([A-Z]{0,1}[a-z]+)/)
29
+ .flatten.compact.uniq
30
+
31
+ words
32
+ .select { |word| misspelled?(word) }
20
33
  .map { |word| new_message(word, line) }
21
34
  end
22
35
  end
@@ -26,17 +39,51 @@ module Pronto
26
39
  level = :warning
27
40
 
28
41
  suggestions = speller.suggestions(word)
29
- msg = "#{word} might not be spelled correctly. Spelling suggestions: #{suggestions}"
42
+
43
+ msg = %("#{word}" might not be spelled correctly.)
44
+ unless suggestions.empty?
45
+ msg += " Spelling suggestions: #{suggestions[0..2].join(', ')}"
46
+ end
30
47
 
31
48
  Message.new(path, line, level, msg, nil, self.class)
32
49
  end
33
50
 
34
51
  def speller
35
- @speller ||= begin
36
- result = FFI::Aspell::Speller.new('en_US')
37
- result.suggestion_mode = 'fast'
38
- result
52
+ @speller ||= FFI::Aspell::Speller.new(
53
+ 'en_US', :'sug-mode' => suggestion_mode
54
+ )
55
+ end
56
+
57
+ def spelling_config
58
+ @spelling_config ||= begin
59
+ config_path = File.join(repo_path, CONFIG_FILE)
60
+ File.exist?(config_path) ? YAML.load_file(config_path) : {}
39
61
  end
40
62
  end
63
+
64
+ def suggestion_mode
65
+ spelling_config['suggestion_mode'] || 'fast'
66
+ end
67
+
68
+ def min_word_length
69
+ spelling_config['min_word_length'] || 5
70
+ end
71
+
72
+ def max_word_length
73
+ spelling_config['max_word_length'] || Float::INFINITY
74
+ end
75
+
76
+ def max_suggestions_number
77
+ spelling_config['max_suggestions_number'] || 3
78
+ end
79
+
80
+ def misspelled?(word)
81
+ lintable_word?(word) && !speller.correct?(word)
82
+ end
83
+
84
+ def lintable_word?(word)
85
+ (min_word_length..max_word_length).cover?(word.length) &&
86
+ !ignored_words.include?(word.downcase)
87
+ end
41
88
  end
42
89
  end
@@ -1,5 +1,5 @@
1
1
  module Pronto
2
2
  module SpellVersion
3
- VERSION = '0.9.0'.freeze
3
+ VERSION = '0.10.0'.freeze
4
4
  end
5
5
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.summary = 'Pronto runner that uses Aspell for spell checking'
15
15
 
16
16
  s.licenses = ['MIT']
17
- s.required_ruby_version = '>= 2.0.0'
17
+ s.required_ruby_version = '>= 2.3.0'
18
18
  s.rubygems_version = '1.8.23'
19
19
 
20
20
  s.files = `git ls-files`.split($RS).reject do |file|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.extra_rdoc_files = ['LICENSE', 'README.md']
33
33
  s.require_paths = ['lib']
34
34
 
35
- s.add_dependency('pronto', '~> 0.9.0')
35
+ s.add_dependency('pronto', '~> 0.10.0')
36
36
  s.add_dependency('ffi-aspell', '~> 1.1.0')
37
37
  s.add_development_dependency('rake', '~> 12.0')
38
38
  s.add_development_dependency('rspec', '~> 3.4')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-spell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindaugas Mozūras
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pronto
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.0
19
+ version: 0.10.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.0
26
+ version: 0.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ffi-aspell
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -105,15 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: 2.0.0
108
+ version: 2.3.0
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.10
115
+ rubygems_version: 3.0.1
117
116
  signing_key:
118
117
  specification_version: 4
119
118
  summary: Pronto runner that uses Aspell for spell checking