dead_end 2.0.0 → 2.0.1

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: 9fb84957790492d9f453b8863ea276ffc603ccb365fee3621f322e3f19e172e5
4
- data.tar.gz: 798626bcc0dfa8457ef1fed8fb9ab8c9783a12ee109d94310a0cf787b2a0491a
3
+ metadata.gz: 7d7d236a8a3634efc153e2a20f511072c2b10f97553595ddb3309b88f74dbbb8
4
+ data.tar.gz: 5cb84a34d16f9c7714791f01864cfb1b05095b8eb9587be5cfbc86aed1c31a20
5
5
  SHA512:
6
- metadata.gz: 44624834e772d2c0d5c0035eb373571cb379cf6417a1d3422528f312c06771ef00c45e3c1ceebb8f78fa4ebce232fd99798f957c408a8a3a78710e65f18da7ce
7
- data.tar.gz: 478fce76c26ffcf975111bb51a8ea71c20aa0ecbabb606d621d715e3d7055a818e82e5b1bc11cc7143e5cd4e120da257c1b33dc30a1b07356dacb782ad7299bf
6
+ metadata.gz: 41f2022c9faba2cd907b91f9dbd2200172af5ddaa6117f80c7dc7229665026e89d06284cfd43d439dfe879f541ee77b57cb09334c49d1f7732ba1ab484197852
7
+ data.tar.gz: 667597674b31cda70837d9e11c46ccf3f4d7374445f56d8fc1f1f4fda3bd4cad0fdf2c2517620224aea683be21b7142101787aac0cb40e7a296ac039be2af0d3
data/.circleci/config.yml CHANGED
@@ -13,6 +13,14 @@ references:
13
13
  command: bundle exec standardrb
14
14
 
15
15
  jobs:
16
+ "ruby-2-5":
17
+ docker:
18
+ - image: circleci/ruby:2.5
19
+ steps:
20
+ - checkout
21
+ - ruby/install-deps
22
+ - <<: *unit
23
+
16
24
  "ruby-2-6":
17
25
  docker:
18
26
  - image: circleci/ruby:2.6
@@ -49,6 +57,7 @@ workflows:
49
57
  version: 2
50
58
  build:
51
59
  jobs:
60
+ - "ruby-2-5"
52
61
  - "ruby-2-6"
53
62
  - "ruby-2-7"
54
63
  - "ruby-3-0"
data/.standard.yml CHANGED
@@ -1 +1 @@
1
- ruby_version: 2.6.6
1
+ ruby_version: 2.5.9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## HEAD (unreleased)
2
2
 
3
+ ## 2.0.1
4
+
5
+ - Reintroduce Ruby 2.5 support (https://github.com/zombocom/dead_end/pull/90)
6
+ - Support naked braces/brackets/parens, invert labels on banner (https://github.com/zombocom/dead_end/pull/89)
7
+ - Handle mismatched end when using rescue without begin (https://github.com/zombocom/dead_end/pull/83)
8
+ - CLI returns non-zero exit code when syntax error is found (https://github.com/zombocom/dead_end/pull/86)
9
+ - Let -v respond with gem version instead of 'unknown' (https://github.com/zombocom/dead_end/pull/82)
10
+
3
11
  ## 2.0.0
4
12
 
5
13
  - Support "endless" oneline method definitions for Ruby 3+ (https://github.com/zombocom/dead_end/pull/80)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dead_end (2.0.0)
4
+ dead_end (2.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -60,4 +60,4 @@ DEPENDENCIES
60
60
  standard
61
61
 
62
62
  BUNDLED WITH
63
- 2.2.27
63
+ 2.2.29
data/exe/dead_end CHANGED
@@ -35,6 +35,8 @@ parser = OptionParser.new do |opts|
35
35
  Options:
36
36
  EOM
37
37
 
38
+ opts.version = DeadEnd::VERSION
39
+
38
40
  opts.on("--help", "Help - displays this message") do |v|
39
41
  puts opts
40
42
  exit
@@ -62,9 +64,15 @@ options[:record_dir] = "tmp" if ENV["DEBUG"]
62
64
 
63
65
  warn "Record dir: #{options[:record_dir]}" if options[:record_dir]
64
66
 
65
- DeadEnd.call(
67
+ display = DeadEnd.call(
66
68
  source: file.read,
67
69
  filename: file.expand_path,
68
70
  terminal: options[:terminal],
69
71
  record_dir: options[:record_dir]
70
72
  )
73
+
74
+ if display.document_ok?
75
+ exit(0)
76
+ else
77
+ exit(1)
78
+ end
@@ -194,7 +194,7 @@ module DeadEnd
194
194
  end
195
195
 
196
196
  private def after_lines
197
- @code_lines[after_index.next..] || []
197
+ @code_lines[after_index.next..-1] || []
198
198
  end
199
199
  end
200
200
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeadEnd
4
+ class Banner
5
+ attr_reader :invalid_obj
6
+
7
+ def initialize(invalid_obj:)
8
+ @invalid_obj = invalid_obj
9
+ end
10
+
11
+ def call
12
+ case invalid_obj.error_symbol
13
+ when :missing_end
14
+ <<~EOM
15
+ DeadEnd: Missing `end` detected
16
+
17
+ This code has a missing `end`. Ensure that all
18
+ syntax keywords (`def`, `do`, etc.) have a matching `end`.
19
+ EOM
20
+ when :unmatched_syntax
21
+ case unmatched_symbol
22
+ when :end
23
+ <<~EOM
24
+ DeadEnd: Unmatched `end` detected
25
+
26
+ This code has an unmatched `end`. Ensure that all `end` lines
27
+ in your code have a matching syntax keyword (`def`, `do`, etc.)
28
+ and that you don't have any extra `end` lines.
29
+ EOM
30
+ when :|
31
+ <<~EOM
32
+ DeadEnd: Unmatched `|` character detected
33
+
34
+ Example:
35
+
36
+ `do |x` should be `do |x|`
37
+ EOM
38
+ when *WhoDisSyntaxError::CHARACTERS.keys
39
+ <<~EOM
40
+ DeadEnd: Unmatched `#{unmatched_symbol}` character detected
41
+
42
+ It appears a `#{missing_character}` might be missing.
43
+ EOM
44
+ else
45
+ "DeadEnd: Unmatched `#{unmatched_symbol}` detected"
46
+ end
47
+ end
48
+ end
49
+
50
+ private def unmatched_symbol
51
+ invalid_obj.unmatched_symbol
52
+ end
53
+
54
+ private def missing_character
55
+ WhoDisSyntaxError::CHARACTERS[unmatched_symbol]
56
+ end
57
+ end
58
+ end
@@ -231,7 +231,7 @@ module DeadEnd
231
231
  #
232
232
  def join_consecutive!
233
233
  consecutive_groups = @document.select(&:ignore_newline_not_beg?).map do |code_line|
234
- take_while_including(code_line.index..) do |line|
234
+ take_while_including(code_line.index..-1) do |line|
235
235
  line.ignore_newline_not_beg?
236
236
  end
237
237
  end
@@ -252,7 +252,7 @@ module DeadEnd
252
252
  # expect(lines[1].to_s).to eq("")
253
253
  def join_trailing_slash!
254
254
  trailing_groups = @document.select(&:trailing_slash?).map do |code_line|
255
- take_while_including(code_line.index..) { |x| x.trailing_slash? }
255
+ take_while_including(code_line.index..-1) { |x| x.trailing_slash? }
256
256
  end
257
257
  join_groups(trailing_groups)
258
258
  self
@@ -286,7 +286,7 @@ module DeadEnd
286
286
  )
287
287
 
288
288
  # Hide the rest of the lines
289
- lines[1..].each do |line|
289
+ lines[1..-1].each do |line|
290
290
  # The above lines already have newlines in them, if add more
291
291
  # then there will be double newline, use an empty line instead
292
292
  @document[line.index] = CodeLine.new(line: "", index: line.index, lex: [])
@@ -300,7 +300,7 @@ module DeadEnd
300
300
  # Like `take_while` except when it stops
301
301
  # iterating, it also returns the line
302
302
  # that caused it to stop
303
- def take_while_including(range = 0..)
303
+ def take_while_including(range = 0..-1)
304
304
  take_next_and_stop = false
305
305
  @document[range].take_while do |line|
306
306
  next if take_next_and_stop
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "banner"
3
4
  require_relative "capture_code_context"
4
5
  require_relative "display_code_with_line_numbers"
5
6
 
@@ -21,11 +22,15 @@ module DeadEnd
21
22
  @invalid_obj = invalid_obj
22
23
  end
23
24
 
25
+ def document_ok?
26
+ @blocks.none? { |b| !b.hidden? }
27
+ end
28
+
24
29
  def call
25
- if @blocks.any? { |b| !b.hidden? }
26
- found_invalid_blocks
27
- else
30
+ if document_ok?
28
31
  @io.puts "Syntax OK"
32
+ else
33
+ found_invalid_blocks
29
34
  end
30
35
  self
31
36
  end
@@ -50,43 +55,7 @@ module DeadEnd
50
55
  end
51
56
 
52
57
  def banner
53
- case @invalid_obj.error_symbol
54
- when :missing_end
55
- <<~EOM
56
- DeadEnd: Missing `end` detected
57
-
58
- This code has a missing `end`. Ensure that all
59
- syntax keywords (`def`, `do`, etc.) have a matching `end`.
60
- EOM
61
- when :unmatched_syntax
62
- case @invalid_obj.unmatched_symbol
63
- when :end
64
- <<~EOM
65
- DeadEnd: Unmatched `end` detected
66
-
67
- This code has an unmatched `end`. Ensure that all `end` lines
68
- in your code have a matching syntax keyword (`def`, `do`, etc.)
69
- and that you don't have any extra `end` lines.
70
- EOM
71
- when :|
72
- <<~EOM
73
- DeadEnd: Unmatched `|` character detected
74
-
75
- Example:
76
-
77
- `do |x` should be `do |x|`
78
- EOM
79
- when :"}"
80
- <<~EOM
81
- DeadEnd: Unmatched `}` character detected
82
-
83
- This code has an unmatched `}`. Ensure that opening curly braces are
84
- closed: `{ }`.
85
- EOM
86
- else
87
- "DeadEnd: Unmatched `#{@invalid_obj.unmatched_symbol}` detected"
88
- end
89
- end
58
+ Banner.new(invalid_obj: @invalid_obj).call
90
59
  end
91
60
 
92
61
  def indent(string, with: " ")
@@ -15,7 +15,7 @@ module DeadEnd
15
15
  last_lineno = source_lines.count
16
16
 
17
17
  until lineno >= last_lineno
18
- lines = source_lines[lineno..]
18
+ lines = source_lines[lineno..-1]
19
19
 
20
20
  @lex.concat(Ripper.lex(lines.join, "-", lineno + 1))
21
21
  lineno = @lex.last.first.first + 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeadEnd
4
- VERSION = "2.0.0"
4
+ VERSION = "2.0.1"
5
5
  end
@@ -8,6 +8,7 @@ module DeadEnd
8
8
  # puts WhoDisSyntaxError.new("def foo;").call.error_symbol
9
9
  # # => :missing_end
10
10
  class WhoDisSyntaxError < Ripper
11
+ CHARACTERS = {"{": :"}", "}": :"{", "[": :"]", "]": :"[", "(": :")", ")": :"("}
11
12
  class Null
12
13
  def error_symbol
13
14
  :missing_end
@@ -58,8 +59,16 @@ module DeadEnd
58
59
  when /expecting end-of-input/
59
60
  @unmatched_symbol = :end
60
61
  @error_symbol = :unmatched_syntax
61
- when /unexpected .* expecting '(?<unmatched_symbol>.*)'/
62
- @unmatched_symbol = $1.to_sym if $1
62
+ when /unexpected .* expecting ['`]?(?<unmatched_symbol>[^']*)/
63
+ if $1
64
+ character = $1.to_sym
65
+ @unmatched_symbol = CHARACTERS[character] || character
66
+ @unmatched_symbol = :end if @unmatched_symbol == :keyword_end
67
+ end
68
+ @error_symbol = :unmatched_syntax
69
+ when /unexpected '(?<unmatched_symbol>.*)'/
70
+ @unmatched_symbol = $1.to_sym
71
+ @unmatched_symbol = :end if @unmatched_symbol == :keyword_end
63
72
  @error_symbol = :unmatched_syntax
64
73
  when /unexpected `end'/, # Ruby 2.7 and 3.0
65
74
  /unexpected end/, # Ruby 2.6
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dead_end
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - schneems
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-11 00:00:00.000000000 Z
11
+ date: 2021-10-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: When you get an "unexpected end" in your syntax this gem helps you find
14
14
  it
@@ -38,6 +38,7 @@ files:
38
38
  - lib/dead_end.rb
39
39
  - lib/dead_end/around_block_scan.rb
40
40
  - lib/dead_end/auto.rb
41
+ - lib/dead_end/banner.rb
41
42
  - lib/dead_end/block_expand.rb
42
43
  - lib/dead_end/capture_code_context.rb
43
44
  - lib/dead_end/clean_document.rb