spellr 0.8.1 → 0.8.2

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: 0e045b4e7f76fa43573c0e28564a4f532dbcc9b35f05ca682e7302274ce0bdbc
4
- data.tar.gz: 2918d1f1c2a41c681dc7370180ead18a63a86f991032140f0dea1ac92faad3b0
3
+ metadata.gz: 8ed59cf5b3c7a98c77565b63809433c16e16e9f6445f911623d8f73aab0a42b3
4
+ data.tar.gz: 20d9208eb6ee13445bf14bf51ae87ef3e4f034bdaab63e2e45614488dbecf3e1
5
5
  SHA512:
6
- metadata.gz: d44c69a61badacc0a792f2ec60794847ea722101fc46e5fdce717562e2f3923ce6d95624af75d6c31e4cdcf2e6b017aaa7aa87c28a3f3b3761591658fcea6770
7
- data.tar.gz: a607bcdf971179b58c7a1fc4fbf433ef4312724910c74f3731dd5df1127ccc2c9059d836564f00456656d19dfad39b62707663baffd1349bb93352a20f83f9b8
6
+ metadata.gz: 5b947e61408ed87bc8651f8f608550f8520cfbbcedbe22a7323a6dd385aff59bea8bae48d26812e042386bdd29e2cdfb3bbdcc2f4105ba99af2fe14ba5dd542a
7
+ data.tar.gz: 6cddbbc490a53949a5656ede17c1330dca3d8d1d94b25a3661dfae6c050116824116468890408dfca87d01b24cfe6946a9b3fe62e0965f79402ab800b3b4a649
@@ -1,3 +1,10 @@
1
+ # v0.8.2
2
+ - Massive test refactor
3
+ - Spellr now only pays attention to Spellr.pwd. Dir.pwd can be whatever
4
+ - All output goes through Spellr.config.output. Now we can override it.
5
+ - tests are twice as fast. Fewer warnings
6
+ - upgrade fast_ignore dependency
7
+
1
8
  # v0.8.1
2
9
  - use refinements for backports so that RakeTask doesn't conflict with Rubocop::RakeTask
3
10
 
data/exe/spellr CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  require_relative '../lib/spellr/cli'
5
5
 
6
- Spellr::CLI.new(ARGV)
6
+ exit Spellr::CLI.new(ARGV).run
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'spellr/backports'
4
4
  require_relative 'spellr/config'
5
+ require_relative 'spellr/pwd'
5
6
 
6
7
  module Spellr
7
8
  class Error < StandardError; end
@@ -27,4 +28,8 @@ module Spellr
27
28
  def config
28
29
  @config ||= Spellr::Config.new
29
30
  end
31
+
32
+ def exit(status = 0)
33
+ throw(:spellr_exit, status)
34
+ end
30
35
  end
@@ -40,7 +40,7 @@ module Spellr
40
40
  end
41
41
 
42
42
  def output
43
- @output ||= Spellr::Output.new
43
+ @output ||= Spellr.config.output
44
44
  end
45
45
 
46
46
  def counts
@@ -16,7 +16,7 @@ module Spellr
16
16
  def initialize(files: [], reporter: Spellr.config.reporter)
17
17
  @files = files
18
18
 
19
- @main_reporter = @reporter = reporter
19
+ @reporter = reporter
20
20
  end
21
21
 
22
22
  def check
@@ -7,7 +7,7 @@ module Spellr
7
7
  class CheckDryRun < Check
8
8
  def check
9
9
  files.each do |file|
10
- puts file.relative_path
10
+ @reporter.puts file.relative_path
11
11
  end
12
12
  end
13
13
  end
@@ -1,32 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pathname'
3
4
  require_relative '../spellr'
4
5
  require_relative 'cli_options'
5
6
  require_relative 'string_format'
6
7
 
7
8
  module Spellr
8
9
  class CLI
9
- attr_reader :argv
10
-
11
10
  def initialize(argv)
11
+ Spellr.config.reset!
12
12
  @argv = argv
13
- CLI::Options.parse(@argv)
14
- check
15
- rescue Spellr::Error => e
16
- exit_with_error(e.message)
17
13
  end
18
14
 
19
- def exit_with_error(message)
20
- warn Spellr::StringFormat.red(message)
21
- exit 1
15
+ def run
16
+ catch(:spellr_exit) { check }
17
+ rescue Spellr::Error => e
18
+ Spellr.config.output.warn(Spellr::StringFormat.red(e.message)) && 1
19
+ 1
22
20
  end
23
21
 
22
+ private
23
+
24
24
  def check
25
+ CLI::Options.parse(@argv)
25
26
  Spellr.config.valid?
26
27
  checker = Spellr.config.checker.new(files: files)
27
28
  checker.check
28
29
 
29
- exit checker.exit_code
30
+ checker.exit_code
30
31
  end
31
32
 
32
33
  def files
@@ -9,6 +9,8 @@ module Spellr
9
9
  class Options
10
10
  class << self
11
11
  def parse(argv)
12
+ @parallel_option = false
13
+
12
14
  options.parse!(argv)
13
15
  end
14
16
 
@@ -43,7 +45,6 @@ module Spellr
43
45
  end
44
46
 
45
47
  def quiet_option(_)
46
- Spellr.config.quiet = true
47
48
  require_relative 'quiet_reporter'
48
49
  Spellr.config.reporter = Spellr::QuietReporter.new
49
50
  end
@@ -56,7 +57,7 @@ module Spellr
56
57
  end
57
58
 
58
59
  def config_option(file)
59
- file = Pathname.pwd.join(file).expand_path
60
+ file = Spellr.pwd.join(file).expand_path
60
61
 
61
62
  unless ::File.readable?(file)
62
63
  raise Spellr::Config::NotFound, "Config error: #{file} not found or not readable"
@@ -82,15 +83,15 @@ module Spellr
82
83
 
83
84
  def version_option(_)
84
85
  require_relative 'version'
85
- puts(Spellr::VERSION)
86
+ Spellr.config.output.puts(Spellr::VERSION)
86
87
 
87
- exit
88
+ Spellr.exit
88
89
  end
89
90
 
90
91
  def options_help(_)
91
- puts options.help
92
+ Spellr.config.output.puts options.help
92
93
 
93
- exit
94
+ Spellr.exit
94
95
  end
95
96
  end
96
97
  end
@@ -4,6 +4,8 @@ require_relative '../spellr'
4
4
  require_relative 'config_loader'
5
5
  require_relative 'language'
6
6
  require_relative 'config_validator'
7
+ require_relative 'output'
8
+
7
9
  require 'pathname'
8
10
 
9
11
  module Spellr
@@ -11,9 +13,8 @@ module Spellr
11
13
  attr_writer :reporter
12
14
  attr_writer :checker
13
15
  attr_reader :config_file
14
- attr_accessor :quiet
15
- alias_method :quiet?, :quiet
16
16
  attr_accessor :dry_run
17
+ alias_method :dry_run?, :dry_run
17
18
 
18
19
  def initialize
19
20
  @config = ConfigLoader.new
@@ -45,14 +46,6 @@ module Spellr
45
46
  end
46
47
  end
47
48
 
48
- def pwd
49
- @pwd ||= Pathname.new(ENV['SPELLR_TEST_PWD'] || Dir.pwd)
50
- end
51
-
52
- def pwd_s
53
- @pwd_s ||= pwd.to_s
54
- end
55
-
56
49
  def languages_for(file)
57
50
  languages.select { |l| l.matches?(file) }
58
51
  end
@@ -66,12 +59,16 @@ module Spellr
66
59
  @config = ConfigLoader.new(value)
67
60
  end
68
61
 
62
+ def output
63
+ @output ||= Spellr::Output.new
64
+ end
65
+
69
66
  def reporter
70
67
  @reporter ||= default_reporter
71
68
  end
72
69
 
73
70
  def checker
74
- return dry_run_checker if @dry_run
71
+ return dry_run_checker if dry_run?
75
72
 
76
73
  @checker ||= default_checker
77
74
  end
@@ -106,10 +103,5 @@ module Spellr
106
103
  require_relative 'check_parallel'
107
104
  Spellr::CheckParallel
108
105
  end
109
-
110
- def clear_pwd
111
- remove_instance_variable(:@pwd) if defined?(@pwd)
112
- remove_instance_variable(:@pwd_s) if defined?(@pwd_s)
113
- end
114
106
  end
115
107
  end
@@ -11,7 +11,7 @@ module Spellr
11
11
 
12
12
  attr_reader :config_file
13
13
 
14
- def initialize(config_file = ::File.join(Dir.pwd, '.spellr.yml'))
14
+ def initialize(config_file = ::File.join(Spellr.pwd, '.spellr.yml'))
15
15
  @config_file = config_file
16
16
  end
17
17
 
@@ -23,9 +23,9 @@ module Spellr
23
23
 
24
24
  # I have no idea how to check for this other than call it
25
25
  Timeout.timeout(0.0000000000001) do
26
- $stdin.getch
26
+ Spellr.config.output.stdin.getch
27
27
  end
28
- rescue Errno::ENOTTY, Errno::ENODEV
28
+ rescue Errno::ENOTTY, Errno::ENODEV, IOError
29
29
  errors << 'CLI error: --interactive is unavailable in a non-interactive terminal'
30
30
  rescue Timeout::Error
31
31
  nil
@@ -24,7 +24,7 @@ module Spellr
24
24
  end
25
25
 
26
26
  def relative_path
27
- @relative_path ||= relative_path_from(Spellr.config.pwd)
27
+ @relative_path ||= relative_path_from(Spellr.pwd)
28
28
  end
29
29
 
30
30
  def insert(string, range)
@@ -31,7 +31,7 @@ module Spellr
31
31
  ignore_rules: Spellr.config.excludes,
32
32
  include_rules: Spellr.config.includes,
33
33
  argv_rules: @patterns,
34
- root: Spellr.config.pwd_s
34
+ root: Spellr.pwd_s
35
35
  )
36
36
  end
37
37
  end
@@ -126,7 +126,7 @@ module Spellr
126
126
  case stdin_getch("qaAsSrR?h\u0003\u0004")
127
127
  # :nocov:
128
128
  when 'q', "\u0003" # ctrl c
129
- exit 1
129
+ Spellr.exit 1
130
130
  when 'a', 'A'
131
131
  Spellr::InteractiveAdd.new(token, self)
132
132
  when 's', "\u0004" # ctrl d
@@ -15,8 +15,8 @@ module Spellr
15
15
  @key = key
16
16
  @includes = includes
17
17
  @hashbangs = hashbangs
18
- unless hashbangs.empty?
19
- @hashbang_pattern = /\A#!.*\b(?:#{hashbangs.map { |s| Regexp.escape(s) }.join('|')})\b/
18
+ @hashbang_pattern = unless hashbangs.empty?
19
+ /\A#!.*\b(?:#{hashbangs.map { |s| Regexp.escape(s) }.join('|')})\b/
20
20
  end
21
21
  @locales = Array(locale)
22
22
  @addable = addable
@@ -36,7 +36,7 @@ module Spellr
36
36
 
37
37
  def project_wordlist
38
38
  @project_wordlist ||= Spellr::Wordlist.new(
39
- Spellr.config.pwd.join('.spellr_wordlists', "#{name}.txt"),
39
+ Spellr.pwd.join('.spellr_wordlists', "#{name}.txt"),
40
40
  name: name
41
41
  )
42
42
  end
@@ -56,7 +56,7 @@ module Spellr
56
56
  return @hashbangs.empty? if @includes.empty?
57
57
 
58
58
  @fast_ignore ||= FastIgnore.new(
59
- include_rules: @includes, gitignore: false, root: Spellr.config.pwd_s
59
+ include_rules: @includes, gitignore: false, root: Spellr.pwd_s
60
60
  )
61
61
  @fast_ignore.allowed?(file.to_s)
62
62
  end
@@ -10,16 +10,15 @@ require_relative 'token_regexps'
10
10
  module Spellr
11
11
  class LineTokenizer < StringScanner
12
12
  attr_reader :line
13
- attr_accessor :disabled
14
- alias_method :disabled?, :disabled
15
- attr_accessor :skip_key
13
+ attr_reader :skip_key
16
14
  alias_method :skip_key?, :skip_key
17
15
 
18
16
  include TokenRegexps
19
17
 
20
- def initialize(line, skip_key: true)
18
+ def initialize(line, skip_key: false)
21
19
  @line = line
22
20
  @skip_key = skip_key
21
+ @disabled = false
23
22
 
24
23
  super(@line.to_s)
25
24
  end
@@ -32,7 +31,7 @@ module Spellr
32
31
  def each_term
33
32
  until eos?
34
33
  term = next_term
35
- next if !term || disabled?
34
+ next if !term || @disabled
36
35
 
37
36
  yield term
38
37
  end
@@ -42,7 +41,7 @@ module Spellr
42
41
  until eos?
43
42
  term = next_term
44
43
  next unless term
45
- next if disabled? || skip_term_proc&.call(term)
44
+ next if @disabled || skip_term_proc&.call(term)
46
45
 
47
46
  yield Token.new(term, line: line, location: column_location(term))
48
47
  end
@@ -78,6 +77,8 @@ module Spellr
78
77
  end
79
78
 
80
79
  def skip_key_heuristically
80
+ return unless skip_key?
81
+
81
82
  possible_key = check(POSSIBLE_KEY_RE)
82
83
 
83
84
  return unless possible_key
@@ -88,6 +89,7 @@ module Spellr
88
89
 
89
90
  BAYES_KEY_HEURISTIC = NaiveBayes.new
90
91
  def key?(possible_key)
92
+ return unless possible_key.length >= Spellr.config.key_minimum_length
91
93
  # I've come across some large base64 strings by this point they're definitely base64.
92
94
  return true if possible_key.length > 200
93
95
  return unless possible_key.match?(min_alpha_re) # or there's no point
@@ -96,15 +98,15 @@ module Spellr
96
98
  end
97
99
 
98
100
  def skip_and_track_disable
99
- return if disabled?
101
+ return if @disabled
100
102
 
101
- skip(SPELLR_DISABLE_RE) && self.disabled = true
103
+ skip(SPELLR_DISABLE_RE) && @disabled = true
102
104
  end
103
105
 
104
106
  def skip_and_track_enable
105
- return unless disabled?
107
+ return unless @disabled
106
108
 
107
- skip(SPELLR_ENABLE_RE) && self.disabled = false
109
+ skip(SPELLR_ENABLE_RE) && @disabled = false
108
110
  end
109
111
  end
110
112
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Spellr
6
+ module_function
7
+
8
+ def pwd
9
+ @pwd ||= Pathname.pwd
10
+ end
11
+
12
+ def pwd_s
13
+ @pwd_s ||= pwd.to_s
14
+ end
15
+ end
@@ -49,9 +49,8 @@ module Spellr
49
49
  end
50
50
 
51
51
  def run(argv)
52
- Spellr::CLI.new(argv)
53
- rescue SystemExit => e
54
- raise unless e.status == 0
52
+ status = Spellr::CLI.new(argv).run
53
+ exit 1 unless status == 0
55
54
  end
56
55
 
57
56
  def argv_or_default(task_argv)
@@ -39,7 +39,7 @@ module Spellr
39
39
  location.char_offset...(location.char_offset + length)
40
40
  end
41
41
 
42
- def byte_range
42
+ def byte_range # leftovers:allow i don't want to delete this
43
43
  @byte_range ||=
44
44
  location.byte_offset...(location.byte_offset + bytesize)
45
45
  end
@@ -49,7 +49,7 @@ module Spellr
49
49
  location.absolute_char_offset...(location.absolute_char_offset + length)
50
50
  end
51
51
 
52
- def file_byte_range
52
+ def file_byte_range # leftovers:allow i don't want to delete this
53
53
  @file_byte_range ||=
54
54
  location.absolute_byte_offset...(location.absolute_byte_offset + bytesize)
55
55
  end
@@ -23,7 +23,6 @@ module Spellr
23
23
  LEFTOVER_NON_WORD_BITS_RE = %r{[/%#\\]|\d+}.freeze # e.g. a / not starting //a-url.com
24
24
  HEX_RE = /(?:#(?:\h{6}|\h{3})|0x\h+)(?![[:alpha:]])/.freeze
25
25
  SHELL_COLOR_ESCAPE_RE = /\\(?:e|0?33)\[\d+(;\d+)*m/.freeze
26
- PUNYCODE_RE = /xn--[a-v0-9\-]+(?:[[:alpha:]])/.freeze
27
26
  # TODO: hex escapes e.g. \xAA.
28
27
  # TODO: language aware escapes
29
28
  BACKSLASH_ESCAPE_RE = /\\[a-zA-Z]/.freeze
@@ -8,10 +8,6 @@ require_relative 'line_tokenizer'
8
8
  module Spellr
9
9
  class Tokenizer
10
10
  attr_reader :file
11
- attr_reader :start_at
12
-
13
- attr_accessor :disabled
14
- alias_method :disabled?, :disabled
15
11
 
16
12
  def initialize(file, start_at: nil, skip_key: true)
17
13
  @start_at = start_at || ColumnLocation.new(line_location: LineLocation.new(file))
@@ -21,7 +17,7 @@ module Spellr
21
17
  @line_tokenizer = LineTokenizer.new('', skip_key: skip_key)
22
18
  end
23
19
 
24
- def terms
20
+ def terms # leftovers:test
25
21
  enum_for(:each_term).to_a
26
22
  end
27
23
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spellr
4
- VERSION = '0.8.1'
4
+ VERSION = '0.8.2'
5
5
  end
@@ -12,7 +12,7 @@ module Spellr
12
12
 
13
13
  def initialize(file, name: file)
14
14
  path = @file = file
15
- @path = Spellr.config.pwd.join('.spellr_wordlists').join(path).expand_path
15
+ @path = Spellr.pwd.join('.spellr_wordlists').join(path).expand_path
16
16
  @name = name
17
17
  @include = {}
18
18
  end
@@ -6,7 +6,7 @@ require_relative 'base_reporter'
6
6
  module Spellr
7
7
  class WordlistReporter < Spellr::BaseReporter
8
8
  def finish
9
- output.puts words.sort.join
9
+ puts words.sort.join unless words.empty?
10
10
  end
11
11
 
12
12
  def call(token)
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
 
30
30
  spec.add_development_dependency 'bundler', '~> 2.0'
31
+ spec.add_development_dependency 'leftovers', '>= 0.2.2'
31
32
  spec.add_development_dependency 'mime-types', '~> 3.3.1'
32
33
  spec.add_development_dependency 'nokogiri'
33
34
  spec.add_development_dependency 'pry'
@@ -40,6 +41,6 @@ Gem::Specification.new do |spec|
40
41
  spec.add_development_dependency 'tty_string', '>= 0.2.1'
41
42
  spec.add_development_dependency 'webmock', '~> 3.8'
42
43
 
43
- spec.add_dependency 'fast_ignore', '>= 0.6.0'
44
+ spec.add_dependency 'fast_ignore', '>= 0.10.0'
44
45
  spec.add_dependency 'parallel', '~> 1.0'
45
46
  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.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dana Sherson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-18 00:00:00.000000000 Z
11
+ date: 2020-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: leftovers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mime-types
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +198,14 @@ dependencies:
184
198
  requirements:
185
199
  - - ">="
186
200
  - !ruby/object:Gem::Version
187
- version: 0.6.0
201
+ version: 0.10.0
188
202
  type: :runtime
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
- version: 0.6.0
208
+ version: 0.10.0
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: parallel
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -247,6 +261,7 @@ files:
247
261
  - lib/spellr/line_tokenizer.rb
248
262
  - lib/spellr/output.rb
249
263
  - lib/spellr/output_stubbed.rb
264
+ - lib/spellr/pwd.rb
250
265
  - lib/spellr/quiet_reporter.rb
251
266
  - lib/spellr/rake_task.rb
252
267
  - lib/spellr/reporter.rb