spellr 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -0
- data/lib/.spellr.yml +2 -0
- data/lib/spellr/backports.rb +4 -0
- data/lib/spellr/check.rb +1 -0
- data/lib/spellr/config.rb +8 -4
- data/lib/spellr/file_list.rb +7 -1
- data/lib/spellr/interactive_add.rb +7 -3
- data/lib/spellr/key_tuner/naive_bayes.rb +7 -3
- data/lib/spellr/language.rb +6 -1
- data/lib/spellr/token.rb +2 -1
- data/lib/spellr/tokenizer.rb +5 -1
- data/lib/spellr/version.rb +1 -1
- data/lib/spellr/wordlist.rb +14 -17
- data/spellr.gemspec +1 -1
- data/wordlists/spellr.txt +17 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ab2e491fac49775163c74ab18787f8abed0b46f96de0bbcb2fa00d02c3ebe89
|
4
|
+
data.tar.gz: b6fcd62fb1a090e9f82e6d7b591eb44156f0a000ef1f7e74417a6d0cef9b8e8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be574430d9bd37fb857670e4e555e5c90559a62749e788af6e844c24a56f4c08aaeee5b7498f10c3a7edce39cf0393927e9439871ae59569e46e84f719569467
|
7
|
+
data.tar.gz: b711c144f99e37d96bf789caa3dcabb36273218f6b02c02f368c2164575a41e99a0b32c2382c66679f3583ffc6ca85f1600e4aff59690de42af7f858f0aea929
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Spellr
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/spellr.svg)](https://rubygems.org/gems/spellr)
|
3
4
|
[![Build Status](https://travis-ci.org/robotdana/spellr.svg?branch=master)](https://travis-ci.org/robotdana/spellr)
|
4
5
|
|
5
6
|
Spell check your source code for fun and occasionally finding bugs
|
data/lib/.spellr.yml
CHANGED
@@ -29,6 +29,8 @@ excludes: # this list is parsed with the .gitignore format
|
|
29
29
|
languages:
|
30
30
|
english:
|
31
31
|
locale: US # options US, CA, AU, GBs (GB with -ise endings), GBz (GB with -ize endings)
|
32
|
+
spellr:
|
33
|
+
addable: false
|
32
34
|
ruby:
|
33
35
|
includes: # Filtered using gitignore format
|
34
36
|
- '*.rb'
|
data/lib/spellr/backports.rb
CHANGED
data/lib/spellr/check.rb
CHANGED
data/lib/spellr/config.rb
CHANGED
@@ -61,7 +61,7 @@ module Spellr
|
|
61
61
|
|
62
62
|
def languages
|
63
63
|
@languages ||= @config[:languages].map do |key, args|
|
64
|
-
Spellr::Language.new(key, args)
|
64
|
+
Spellr::Language.new(key, **args)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -89,14 +89,18 @@ module Spellr
|
|
89
89
|
private
|
90
90
|
|
91
91
|
def only_has_one_key_per_language
|
92
|
-
|
93
|
-
|
94
|
-
conflicting_languages.each do |conflicts|
|
92
|
+
languages_with_conflicting_keys.each do |conflicts|
|
95
93
|
errors << "Error: #{conflicts.map(&:name).join(' & ')} share the same language key "\
|
96
94
|
"(#{conflicts.first.key}). Please define one to be different with `key:`"
|
97
95
|
end
|
98
96
|
end
|
99
97
|
|
98
|
+
def languages_with_conflicting_keys
|
99
|
+
languages.select(&:addable?).group_by(&:key).values.select do |g|
|
100
|
+
g.length > 1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
100
104
|
def keys_are_single_characters
|
101
105
|
bad_languages = languages.select { |l| l.key.length > 1 }
|
102
106
|
|
data/lib/spellr/file_list.rb
CHANGED
@@ -14,6 +14,8 @@ module Spellr
|
|
14
14
|
|
15
15
|
def each
|
16
16
|
fast_ignore.each do |file|
|
17
|
+
next unless cli_patterns_ignore.allowed?(file)
|
18
|
+
|
17
19
|
file = Spellr::File.new(file)
|
18
20
|
|
19
21
|
yield(file)
|
@@ -41,9 +43,13 @@ module Spellr
|
|
41
43
|
def fast_ignore
|
42
44
|
FastIgnore.new(
|
43
45
|
ignore_rules: Spellr.config.excludes,
|
44
|
-
include_rules: Spellr.config.includes
|
46
|
+
include_rules: Spellr.config.includes,
|
45
47
|
gitignore: gitignore_path
|
46
48
|
)
|
47
49
|
end
|
50
|
+
|
51
|
+
def cli_patterns_ignore
|
52
|
+
@cli_patterns_ignore ||= FastIgnore.new(include_rules: cli_patterns, gitignore: false)
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
@@ -19,14 +19,18 @@ module Spellr
|
|
19
19
|
@languages ||= Spellr.config.languages_for(token.location.file.to_path)
|
20
20
|
end
|
21
21
|
|
22
|
+
def addable_languages
|
23
|
+
languages.select(&:addable?)
|
24
|
+
end
|
25
|
+
|
22
26
|
def language_keys
|
23
|
-
@language_keys ||=
|
27
|
+
@language_keys ||= addable_languages.map(&:key)
|
24
28
|
end
|
25
29
|
|
26
30
|
def ask_wordlist
|
27
31
|
puts "Add #{red(token)} to wordlist:"
|
28
32
|
|
29
|
-
|
33
|
+
addable_languages.each do |language|
|
30
34
|
puts "[#{language.key}] #{language.name}"
|
31
35
|
end
|
32
36
|
|
@@ -50,7 +54,7 @@ module Spellr
|
|
50
54
|
end
|
51
55
|
|
52
56
|
def add_to_wordlist(choice)
|
53
|
-
wordlist =
|
57
|
+
wordlist = addable_languages.find { |w| w.key == choice }.project_wordlist
|
54
58
|
wordlist << token
|
55
59
|
reporter.increment(:total_added)
|
56
60
|
puts "Added #{red(token)} to #{wordlist.name} wordlist"
|
@@ -11,10 +11,10 @@ class NaiveBayes
|
|
11
11
|
|
12
12
|
def initialize(path = YAML_PATH)
|
13
13
|
load_from_yaml(path) if File.exist?(path)
|
14
|
+
@key = {}
|
14
15
|
end
|
15
16
|
|
16
17
|
def key?(string)
|
17
|
-
@key ||= {}
|
18
18
|
@key.fetch(string) do
|
19
19
|
@key[string] = classify(PossibleKey.new(string).features).start_with?('key')
|
20
20
|
end
|
@@ -92,7 +92,7 @@ class NaiveBayes
|
|
92
92
|
# value: the value of the feature for which we are finding the probability
|
93
93
|
# class_name: name of the class in consideration
|
94
94
|
def feature_probability(feature, value, class_name)
|
95
|
-
Stats.gaussian_probability(value, feature_set[class_name][feature])
|
95
|
+
Stats.gaussian_probability(value, **feature_set[class_name][feature])
|
96
96
|
end
|
97
97
|
|
98
98
|
# multiply together the feature probabilities for all of the
|
@@ -103,12 +103,16 @@ class NaiveBayes
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
def heuristic_weight
|
107
|
+
@heuristic_weight ||= 10**Spellr.config.key_heuristic_weight
|
108
|
+
end
|
109
|
+
|
106
110
|
# this is where we compute the final naive Bayesian probability
|
107
111
|
# for a given set of features being a part of a given class.
|
108
112
|
def class_probability(features, class_name)
|
109
113
|
class_fraction = 1.0 / num_classes
|
110
114
|
feature_bayes = feature_multiplication(features, class_name)
|
111
|
-
feature_bayes *=
|
115
|
+
feature_bayes *= heuristic_weight if class_name.start_with?('key_')
|
112
116
|
feature_bayes * class_fraction
|
113
117
|
end
|
114
118
|
|
data/lib/spellr/language.rb
CHANGED
@@ -7,12 +7,17 @@ module Spellr
|
|
7
7
|
attr_reader :name
|
8
8
|
attr_reader :key
|
9
9
|
|
10
|
-
def initialize(name, key: name[0], includes: [], hashbangs: [], locale: [])
|
10
|
+
def initialize(name, key: name[0], includes: [], hashbangs: [], locale: [], addable: true) # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
|
11
11
|
@name = name
|
12
12
|
@key = key
|
13
13
|
@includes = includes
|
14
14
|
@hashbangs = hashbangs
|
15
15
|
@locales = Array(locale)
|
16
|
+
@addable = addable
|
17
|
+
end
|
18
|
+
|
19
|
+
def addable?
|
20
|
+
@addable
|
16
21
|
end
|
17
22
|
|
18
23
|
def matches?(file)
|
data/lib/spellr/token.rb
CHANGED
@@ -4,8 +4,9 @@ require_relative 'column_location'
|
|
4
4
|
require_relative 'string_format'
|
5
5
|
|
6
6
|
class String
|
7
|
+
@@spellr_normalize = {} # rubocop:disable Style/ClassVars # I want to share this with subclasses
|
8
|
+
|
7
9
|
def spellr_normalize
|
8
|
-
@@spellr_normalize ||= {} # rubocop:disable Style/ClassVars # I want to share this with subclasses
|
9
10
|
@@spellr_normalize.fetch(to_s) do |term|
|
10
11
|
@@spellr_normalize[term] = "#{term.strip.downcase.unicode_normalize.tr('’', "'")}\n"
|
11
12
|
end
|
data/lib/spellr/tokenizer.rb
CHANGED
@@ -19,7 +19,7 @@ module Spellr
|
|
19
19
|
@file = file.is_a?(StringIO) || file.is_a?(IO) ? file : ::File.new(file)
|
20
20
|
@file.pos = @start_at.line_location.byte_offset
|
21
21
|
|
22
|
-
@line_tokenizer = LineTokenizer.new(skip_key: skip_key)
|
22
|
+
@line_tokenizer = LineTokenizer.new('', skip_key: skip_key)
|
23
23
|
end
|
24
24
|
|
25
25
|
def terms
|
@@ -34,6 +34,8 @@ module Spellr
|
|
34
34
|
file.each_line do |line|
|
35
35
|
prepare_tokenizer_for_line(line).each_term(&block)
|
36
36
|
end
|
37
|
+
ensure
|
38
|
+
file.close
|
37
39
|
end
|
38
40
|
|
39
41
|
def each_token(skip_term_proc: nil) # rubocop:disable Metrics/MethodLength
|
@@ -64,6 +66,8 @@ module Spellr
|
|
64
66
|
char_offset += line.length
|
65
67
|
byte_offset += line.bytesize
|
66
68
|
end
|
69
|
+
ensure
|
70
|
+
file.close
|
67
71
|
end
|
68
72
|
|
69
73
|
def normalized_terms
|
data/lib/spellr/version.rb
CHANGED
data/lib/spellr/wordlist.rb
CHANGED
@@ -14,6 +14,7 @@ module Spellr
|
|
14
14
|
path = @file = file
|
15
15
|
@path = Pathname.pwd.join('.spellr_wordlists').join(path).expand_path
|
16
16
|
@name = name
|
17
|
+
@include = {}
|
17
18
|
end
|
18
19
|
|
19
20
|
def each(&block)
|
@@ -29,20 +30,24 @@ module Spellr
|
|
29
30
|
# significantly faster than default Enumerable#include?
|
30
31
|
# requires terms to have been sorted
|
31
32
|
def include?(term)
|
32
|
-
|
33
|
+
term = term.spellr_normalize
|
34
|
+
@include.fetch(term) do
|
35
|
+
@include[term] = words.bsearch { |value| term <=> value }
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
def <<(term)
|
36
40
|
term = term.spellr_normalize
|
37
41
|
touch
|
38
|
-
|
42
|
+
@include[term] = true
|
39
43
|
insert_sorted(term)
|
40
|
-
@path.write(
|
44
|
+
@path.write(words.join) # we don't need to clear the cache
|
41
45
|
end
|
42
46
|
|
43
|
-
def
|
44
|
-
@
|
47
|
+
def words
|
48
|
+
@words ||= (exist? ? @path.readlines : [])
|
45
49
|
end
|
50
|
+
alias_method :to_a, :words
|
46
51
|
|
47
52
|
def clean(file = @path)
|
48
53
|
require_relative 'tokenizer'
|
@@ -78,21 +83,13 @@ module Spellr
|
|
78
83
|
private
|
79
84
|
|
80
85
|
def insert_sorted(term)
|
81
|
-
insert_at =
|
82
|
-
insert_at ?
|
83
|
-
end
|
84
|
-
|
85
|
-
def include_cache
|
86
|
-
@include_cache ||= Hash.new do |cache, term|
|
87
|
-
cache[term] = to_a.bsearch do |value|
|
88
|
-
term <=> value
|
89
|
-
end
|
90
|
-
end
|
86
|
+
insert_at = words.bsearch_index { |value| value >= term }
|
87
|
+
insert_at ? words.insert(insert_at, term) : words.push(term)
|
91
88
|
end
|
92
89
|
|
93
90
|
def clear_cache
|
94
|
-
@
|
95
|
-
@include =
|
91
|
+
@words = nil
|
92
|
+
@include = {}
|
96
93
|
remove_instance_variable(:@exist) if defined?(@exist)
|
97
94
|
end
|
98
95
|
|
data/spellr.gemspec
CHANGED
@@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'rubocop-rspec'
|
35
35
|
spec.add_development_dependency 'terminal-table'
|
36
36
|
spec.add_development_dependency 'tty_string'
|
37
|
-
spec.add_dependency 'fast_ignore', '~> 0.
|
37
|
+
spec.add_dependency 'fast_ignore', '~> 0.5.1'
|
38
38
|
spec.add_dependency 'parallel', '~> 1.0'
|
39
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spellr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 0.5.1
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.5.1
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: parallel
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,6 +228,7 @@ files:
|
|
228
228
|
- wordlists/javascript.txt
|
229
229
|
- wordlists/ruby.txt
|
230
230
|
- wordlists/shell.txt
|
231
|
+
- wordlists/spellr.txt
|
231
232
|
homepage: http://github.com/robotdana/spellr
|
232
233
|
licenses:
|
233
234
|
- MIT
|