spellr 0.2.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: '08e49a55e37f2b63ecb10f8ce5218b6c1baa2c53'
4
- data.tar.gz: d2d69cdf740d24670efde7b60389494688d42354
3
+ metadata.gz: 90aae5e24ba00624fea110acb2efb0a796cbf154
4
+ data.tar.gz: f46b4df50970c2043937aab35e2771a96ee6a3f9
5
5
  SHA512:
6
- metadata.gz: a2d76f91252a4c97fa202f91c8500d0829dbf2392f7d4b433f42dfcc851b4402681e7104f2d19ba47d81ff0d74fd7bf4d0ca487edfe450563c7a38555bf64cb0
7
- data.tar.gz: 93b0c4758dd2d39fbe50ff9b8434171955fccef32d973998d4a01be4c4f8b2366160e6f6732709ffee77d533601609e68fb43679ab67457b6ca99d6f7af11b10
6
+ metadata.gz: cc31f2cbe8f1870a4eae00d4fcf1dc88eaf905a5fc477605650c67a50768950da5cd3e6e845405c713be073104c778a4c2d50a1d377a2efb5da0329311c4ce09
7
+ data.tar.gz: 58763f377f33faa8465fe69e06558da8ed97eb783d3c814dcb642920aa7ecfa99d6ce6488df8e3acace87a9a8a77875ad278919e475246984354260a79ae69f5
data/.spellr.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  ignore:
3
- - '*.spellr_wordlists'
4
3
  - wordlists/*
5
4
  only:
6
5
  - '*.rb'
@@ -11,9 +10,6 @@ only:
11
10
  - '*.gemspec'
12
11
  - Gemfile
13
12
  languages:
14
- english:
15
- wordlists:
16
- - dictionary.txt
17
13
  ruby:
18
14
  only:
19
15
  - README.md
@@ -1,3 +1,123 @@
1
+ abc
2
+ addable
3
+ arg
4
+ args
5
+ baz
6
+ bundler
7
+ changelog
8
+ charpos
9
+ cli
10
+ cmd
11
+ codebase
12
+ colours
13
+ config
14
+ configs
15
+ css
16
+ customisations
17
+ cyclomatic
18
+ def
19
+ dict
20
+ diffable
21
+ diffs
22
+ dockerfile
23
+ downloader
24
+ env
25
+ eos
26
+ eot
27
+ erb
28
+ exclusions
29
+ exe
30
+ executables
31
+ exitstatus
32
+ ext
33
+ filename
34
+ filenames
35
+ foo
36
+ gemfile
37
+ gemspec
38
+ getch
39
+ git
40
+ github
41
+ gitignore
42
+ gitignored
43
+ gitkeep
44
+ haml
45
+ hashbang
46
+ hashbangs
47
+ hashbangs
48
+ heuristically
49
+ hml
50
+ hostnames
51
+ href
52
+ htt
53
+ ico
54
+ inclusions
55
+ jbuilder
56
+ jpg
1
57
  json
58
+ jsx
59
+ klass
60
+ localhost
61
+ lstripped
62
+ mailto
63
+ marketplacer
64
+ matcher
65
+ matchers
66
+ maths
67
+ merchantability
68
+ multiline
69
+ newlines
70
+ noninfringement
71
+ nonwords
72
+ optparse
73
+ org
74
+ param
75
+ params
76
+ png
77
+ pwd
78
+ rakefile
79
+ rdoc
80
+ readme
81
+ redisplay
82
+ repo
83
+ rspec
84
+ rubocop
85
+ rvm
86
+ scss
87
+ shelljoin
88
+ shellsplit
89
+ shellwords
90
+ sherson
91
+ spellr
92
+ stderr
93
+ stdlib
94
+ stdout
95
+ str
96
+ stringscanner
97
+ strscan
98
+ sublicense
99
+ subwords
100
+ sudo
101
+ svg
102
+ thu
103
+ tlds
104
+ tmp
105
+ todo
106
+ tokenize
107
+ tokenizes
108
+ tsx
109
+ ttf
110
+ txt
111
+ uploader
112
+ uri
113
+ usr
114
+ utf
2
115
  woff
116
+ wordlist
117
+ wordlists
118
+ wordn't
119
+ xdescribe
120
+ xit
3
121
  xlsx
122
+ yardoc
123
+ yml
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.3.0
2
+ - interactive add to wordlist uses consistent letters rather than random numbers as keys
3
+ - additional wordlists per language can no longer be defined
1
4
  # v0.2.0
2
5
  - Supports ruby 2.3 - 2.6
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spellr (0.2.0)
4
+ spellr (0.3.0)
5
5
  fast_ignore
6
6
  parallel
7
7
 
data/lib/.spellr.yml CHANGED
@@ -3,6 +3,7 @@ word_minimum_length: 3
3
3
 
4
4
  ignore: # this list is parsed with the .gitignore format
5
5
  - /.git/
6
+ - .spellr_wordlists/
6
7
  - .DS_Store
7
8
  - Gemfile.lock
8
9
  - .rspec_status
data/lib/spellr/cli.rb CHANGED
@@ -19,6 +19,11 @@ module Spellr
19
19
 
20
20
  def check
21
21
  require_relative 'check'
22
+ unless Spellr.config.valid?
23
+ Spellr.config.print_errors
24
+ exit 1
25
+ end
26
+
22
27
  checker = Spellr::Check.new(files: files)
23
28
  checker.check
24
29
 
data/lib/spellr/config.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../spellr'
4
+ require_relative 'config_loader'
4
5
 
5
6
  module Spellr
6
7
  class Config
@@ -10,8 +11,25 @@ module Spellr
10
11
  alias_method :quiet?, :quiet
11
12
 
12
13
  def initialize
13
- @config_file = ::File.join(Dir.pwd, '.spellr.yml')
14
- load_config
14
+ @config = ConfigLoader.new
15
+ end
16
+
17
+ def valid?
18
+ only_has_one_key_per_language
19
+ keys_are_single_characters
20
+ errors.empty?
21
+ end
22
+
23
+ def print_errors
24
+ if $stderr.tty?
25
+ errors.each { |e| warn "\e[31m#{e}\e[0m" }
26
+ else
27
+ errors.each { |e| warn e }
28
+ end
29
+ end
30
+
31
+ def errors
32
+ @errors ||= []
15
33
  end
16
34
 
17
35
  def word_minimum_length
@@ -33,26 +51,23 @@ module Spellr
33
51
  def clear_cache
34
52
  remove_instance_variable(:@wordlists) if defined?(@wordlists)
35
53
  remove_instance_variable(:@languages) if defined?(@languages)
54
+ remove_instance_variable(:@errors) if defined?(@errors)
36
55
  end
37
56
 
38
57
  def languages
39
58
  require_relative 'language'
40
59
 
41
60
  @languages ||= @config[:languages].map do |key, args|
42
- [key, Spellr::Language.new(key, args)]
43
- end.to_h
61
+ Spellr::Language.new(key, args)
62
+ end
44
63
  end
45
64
 
46
65
  def languages_for(file)
47
- languages.values.select { |l| l.matches?(file) }
66
+ languages.select { |l| l.matches?(file) }
48
67
  end
49
68
 
50
69
  def wordlists
51
- @wordlists ||= languages.values.flat_map(&:wordlists)
52
- end
53
-
54
- def all_wordlist_paths
55
- languages.values.flat_map(&:all_wordlist_paths)
70
+ @wordlists ||= languages.flat_map(&:wordlists)
56
71
  end
57
72
 
58
73
  def wordlists_for(file)
@@ -61,8 +76,7 @@ module Spellr
61
76
 
62
77
  def config_file=(value)
63
78
  ::File.read(value) # raise Errno::ENOENT if the file doesn't exist
64
- @config_file = value
65
- load_config
79
+ @config = ConfigLoader.new(value)
66
80
  end
67
81
 
68
82
  def reporter
@@ -71,52 +85,33 @@ module Spellr
71
85
 
72
86
  private
73
87
 
74
- def default_reporter
75
- require_relative 'reporter'
76
-
77
- Spellr::Reporter.new
78
- end
88
+ def only_has_one_key_per_language
89
+ conflicting_languages = languages
90
+ .group_by(&:key)
91
+ .values.select { |g| g.length > 1 }
79
92
 
80
- def load_config
81
- default_config = load_yaml(::File.join(__dir__, '..', '.spellr.yml'))
82
- project_config = load_yaml(config_file)
93
+ return if conflicting_languages.empty?
83
94
 
84
- @config = merge_config(default_config, project_config)
95
+ conflicting_languages.each do |conflicts|
96
+ errors << "Error: #{conflicts.map(&:name).join(' & ')} share the same language key (#{conflicts.first.key}). "\
97
+ 'Please define one to be different with `key:`'
98
+ end
85
99
  end
86
100
 
87
- def load_yaml(path)
88
- require 'yaml'
101
+ def keys_are_single_characters
102
+ bad_languages = languages.select { |l| l.key.length > 1 }
103
+ return if bad_languages.empty?
89
104
 
90
- return {} unless ::File.exist?(path)
91
-
92
- if RUBY_VERSION >= '2.5'
93
- YAML.safe_load(::File.read(path), symbolize_names: true)
94
- else
95
- symbolize_names!(YAML.safe_load(::File.read(path)))
105
+ bad_languages.each do |language|
106
+ errors << "Error: #{language.name} defines a key that is too long (#{language.key}). "\
107
+ 'Please change it to be a single character'
96
108
  end
97
109
  end
98
110
 
99
- def symbolize_names!(obj)
100
- case obj
101
- when Hash
102
- obj.keys.each do |key|
103
- value = obj.delete(key)
104
- obj[key.to_sym] = symbolize_names!(value)
105
- end
106
- when Array
107
- obj.map! { |ea| symbolize_names!(ea) }
108
- end
109
- obj
110
- end
111
+ def default_reporter
112
+ require_relative 'reporter'
111
113
 
112
- def merge_config(default, project)
113
- if project.is_a?(Array) && default.is_a?(Array)
114
- default | project
115
- elsif project.is_a?(Hash) && default.is_a?(Hash)
116
- default.merge(project) { |_k, d, p| merge_config(d, p) }
117
- else
118
- project
119
- end
114
+ Spellr::Reporter.new
120
115
  end
121
116
  end
122
117
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spellr
4
+ class ConfigLoader
5
+ attr_reader :config_file
6
+
7
+ def initialize(config_file = ::File.join(Dir.pwd, '.spellr.yml'))
8
+ @config_file = config_file
9
+ end
10
+
11
+ def config_file=(value)
12
+ ::File.read(value) # raise Errno::ENOENT if the file doesn't exist
13
+ @config_file = value
14
+ @config = nil
15
+ end
16
+
17
+ def [](value)
18
+ load_config unless @config
19
+ @config[value]
20
+ end
21
+
22
+ private
23
+
24
+ def load_config
25
+ default_config = load_yaml(::File.join(__dir__, '..', '.spellr.yml'))
26
+ project_config = load_yaml(config_file)
27
+
28
+ @config = merge_config(default_config, project_config)
29
+ end
30
+
31
+ def load_yaml(path)
32
+ require 'yaml'
33
+
34
+ return {} unless ::File.exist?(path)
35
+
36
+ if RUBY_VERSION >= '2.5'
37
+ YAML.safe_load(::File.read(path), symbolize_names: true)
38
+ else
39
+ symbolize_names!(YAML.safe_load(::File.read(path)))
40
+ end
41
+ end
42
+
43
+ def symbolize_names!(obj)
44
+ case obj
45
+ when Hash
46
+ obj.keys.each do |key|
47
+ value = obj.delete(key)
48
+ obj[key.to_sym] = symbolize_names!(value)
49
+ end
50
+ when Array
51
+ obj.map! { |ea| symbolize_names!(ea) }
52
+ end
53
+ obj
54
+ end
55
+
56
+ def merge_config(default, project)
57
+ if project.is_a?(Array) && default.is_a?(Array)
58
+ default | project
59
+ elsif project.is_a?(Hash) && default.is_a?(Hash)
60
+ default.merge(project) { |_k, d, p| merge_config(d, p) }
61
+ else
62
+ project
63
+ end
64
+ end
65
+ end
66
+ end
@@ -12,10 +12,6 @@ module Spellr
12
12
  @patterns = patterns
13
13
  end
14
14
 
15
- def wordlist?(file)
16
- Spellr.config.all_wordlist_paths.any? { |w| w == file }
17
- end
18
-
19
15
  def config_only?(file)
20
16
  Spellr.config.only.empty? || Spellr.config.only.any? { |o| file.fnmatch?(o) }
21
17
  end
@@ -31,7 +27,6 @@ module Spellr
31
27
  FastIgnore.new(rules: Spellr.config.ignored, gitignore: gitignore).each do |file|
32
28
  file = Spellr::File.new(file)
33
29
  next unless cli_only?(file)
34
- next if wordlist?(file)
35
30
  next unless config_only?(file)
36
31
 
37
32
  yield(file)
@@ -117,10 +117,10 @@ module Spellr
117
117
  # TODO: handle more than 16 options
118
118
  def handle_add(token) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
119
119
  puts "Add #{red(token)} to wordlist:"
120
- wordlists = Spellr.config.languages_for(token.location.file).flat_map(&:addable_wordlists)
120
+ languages = Spellr.config.languages_for(token.location.file)
121
121
 
122
- wordlists.each_with_index do |wordlist, i|
123
- puts "[#{i.to_s(16)}] #{wordlist.name}"
122
+ languages.each do |wordlist|
123
+ puts "[#{wordlist.key}] #{wordlist.name}"
124
124
  end
125
125
  choice = STDIN.getch
126
126
  clear_current_line
@@ -128,9 +128,8 @@ module Spellr
128
128
  when "\u0003" # ctrl c
129
129
  puts '^C again to exit'
130
130
  call(token)
131
- when /\h/
132
- wl = wordlists[choice.to_i(16)]
133
- return handle_add(token) unless wl
131
+ when *languages.map(&:key)
132
+ wl = languages.find { |w| w.key == choice }.project_wordlist
134
133
 
135
134
  wl.add(token)
136
135
  self.total_added += 1
@@ -5,17 +5,18 @@ require_relative 'wordlist'
5
5
  module Spellr
6
6
  class Language
7
7
  attr_reader :name
8
+ attr_reader :key
8
9
 
9
10
  def initialize(name, # rubocop:disable Metrics/ParameterLists
10
- wordlists: [],
11
+ key: name[0],
11
12
  generate: nil,
12
13
  only: [],
13
14
  description: '',
14
15
  hashbangs: [])
15
16
  @name = name
17
+ @key = key
16
18
  @description = description
17
19
  @generate = generate
18
- @wordlist_paths = wordlists
19
20
  @only = only
20
21
  @hashbangs = hashbangs
21
22
  end
@@ -28,19 +29,9 @@ module Spellr
28
29
  return true if file.hashbang && @hashbangs.any? { |h| file.hashbang.include?(h) }
29
30
  end
30
31
 
31
- def config_wordlists
32
- @config_wordlists ||= @wordlist_paths.map(&Spellr::Wordlist.method(:new))
33
- end
34
-
35
- def all_wordlist_paths
36
- @wordlist_paths + default_wordlists.map(&:path)
37
- end
38
-
39
32
  def wordlists
40
- w = config_wordlists + default_wordlists.select(&:exist?)
41
- return generate_wordlist if w.empty?
42
-
43
- w
33
+ generate_wordlist unless generated_project_wordlist.exist?
34
+ default_wordlists.select(&:exist?)
44
35
  end
45
36
 
46
37
  def generate_wordlist
@@ -52,11 +43,7 @@ module Spellr
52
43
 
53
44
  Spellr::CLI.new(generate.shellsplit)
54
45
 
55
- config_wordlists + default_wordlists
56
- end
57
-
58
- def addable_wordlists
59
- ((config_wordlists - default_wordlists) + [project_wordlist]).uniq(&:path)
46
+ default_wordlists
60
47
  end
61
48
 
62
49
  def gem_wordlist
@@ -88,11 +75,6 @@ module Spellr
88
75
  wordlists.map(&Spellr::Wordlist.method(:new))
89
76
  end
90
77
 
91
- def custom_addable_wordlists(wordlists)
92
- default_paths = default_wordlist_paths
93
- wordlists.map { |w| Spellr::Wordlist.new(w) }.reject { |w| default_paths.include?(w.path) }
94
- end
95
-
96
78
  def default_wordlists
97
79
  [
98
80
  gem_wordlist,
@@ -51,7 +51,7 @@ module Spellr
51
51
  end
52
52
 
53
53
  def normalized_terms
54
- enum_for(:each_term).lazy.map { |t| Token.normalize(t) }.uniq.sort
54
+ enum_for(:each_term).map { |t| Token.normalize(t) }.uniq.sort
55
55
  end
56
56
 
57
57
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spellr
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spellr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dana Sherson
@@ -149,7 +149,6 @@ files:
149
149
  - ".rubocop.yml"
150
150
  - ".ruby-version"
151
151
  - ".spellr.yml"
152
- - ".spellr_wordlists/dictionary.txt"
153
152
  - ".spellr_wordlists/english.txt"
154
153
  - ".spellr_wordlists/lorem.txt"
155
154
  - ".spellr_wordlists/ruby.txt"
@@ -171,6 +170,7 @@ files:
171
170
  - lib/spellr/cli.rb
172
171
  - lib/spellr/column_location.rb
173
172
  - lib/spellr/config.rb
173
+ - lib/spellr/config_loader.rb
174
174
  - lib/spellr/file.rb
175
175
  - lib/spellr/file_list.rb
176
176
  - lib/spellr/interactive.rb
@@ -1,120 +0,0 @@
1
- abc
2
- addable
3
- arg
4
- args
5
- baz
6
- bundler
7
- changelog
8
- charpos
9
- cli
10
- cmd
11
- codebase
12
- colours
13
- config
14
- configs
15
- css
16
- customisations
17
- cyclomatic
18
- def
19
- dict
20
- diffable
21
- diffs
22
- dockerfile
23
- downloader
24
- env
25
- eos
26
- eot
27
- erb
28
- exclusions
29
- exe
30
- executables
31
- exitstatus
32
- ext
33
- filename
34
- filenames
35
- foo
36
- gemfile
37
- gemspec
38
- getch
39
- git
40
- github
41
- gitignore
42
- gitignored
43
- gitkeep
44
- haml
45
- hashbang
46
- hashbangs
47
- hashbangs
48
- heuristically
49
- hml
50
- hostnames
51
- href
52
- htt
53
- ico
54
- inclusions
55
- jbuilder
56
- jpg
57
- jsx
58
- klass
59
- localhost
60
- lstripped
61
- mailto
62
- marketplacer
63
- matcher
64
- matchers
65
- maths
66
- merchantability
67
- multiline
68
- newlines
69
- noninfringement
70
- nonwords
71
- optparse
72
- org
73
- param
74
- params
75
- png
76
- pwd
77
- rakefile
78
- rdoc
79
- readme
80
- redisplay
81
- repo
82
- rspec
83
- rubocop
84
- rvm
85
- scss
86
- shelljoin
87
- shellsplit
88
- shellwords
89
- sherson
90
- spellr
91
- stderr
92
- stdlib
93
- stdout
94
- str
95
- stringscanner
96
- strscan
97
- sublicense
98
- subwords
99
- sudo
100
- svg
101
- thu
102
- tlds
103
- tmp
104
- todo
105
- tokenize
106
- tokenizes
107
- tsx
108
- ttf
109
- txt
110
- uploader
111
- uri
112
- usr
113
- utf
114
- wordlist
115
- wordlists
116
- wordn't
117
- xdescribe
118
- xit
119
- yardoc
120
- yml