dead_end 1.1.7 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +27 -1
  3. data/.github/workflows/check_changelog.yml +14 -7
  4. data/.standard.yml +1 -0
  5. data/CHANGELOG.md +60 -0
  6. data/CODE_OF_CONDUCT.md +2 -2
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +31 -2
  9. data/README.md +122 -35
  10. data/Rakefile +1 -1
  11. data/dead_end.gemspec +12 -12
  12. data/exe/dead_end +4 -67
  13. data/lib/dead_end/{internals.rb → api.rb} +90 -52
  14. data/lib/dead_end/around_block_scan.rb +16 -18
  15. data/lib/dead_end/auto.rb +3 -101
  16. data/lib/dead_end/block_expand.rb +6 -5
  17. data/lib/dead_end/capture_code_context.rb +167 -50
  18. data/lib/dead_end/clean_document.rb +304 -0
  19. data/lib/dead_end/cli.rb +129 -0
  20. data/lib/dead_end/code_block.rb +20 -4
  21. data/lib/dead_end/code_frontier.rb +74 -29
  22. data/lib/dead_end/code_line.rb +176 -87
  23. data/lib/dead_end/code_search.rb +40 -51
  24. data/lib/dead_end/core_ext.rb +35 -0
  25. data/lib/dead_end/display_code_with_line_numbers.rb +7 -8
  26. data/lib/dead_end/display_invalid_blocks.rb +42 -80
  27. data/lib/dead_end/explain_syntax.rb +103 -0
  28. data/lib/dead_end/insertion_sort.rb +46 -0
  29. data/lib/dead_end/left_right_lex_count.rb +168 -0
  30. data/lib/dead_end/lex_all.rb +25 -34
  31. data/lib/dead_end/lex_value.rb +70 -0
  32. data/lib/dead_end/parse_blocks_from_indent_line.rb +3 -4
  33. data/lib/dead_end/pathname_from_message.rb +47 -0
  34. data/lib/dead_end/ripper_errors.rb +36 -0
  35. data/lib/dead_end/version.rb +1 -1
  36. data/lib/dead_end.rb +2 -2
  37. metadata +14 -9
  38. data/.travis.yml +0 -6
  39. data/lib/dead_end/fyi.rb +0 -7
  40. data/lib/dead_end/heredoc_block_parse.rb +0 -30
  41. data/lib/dead_end/trailing_slash_join.rb +0 -53
  42. data/lib/dead_end/who_dis_syntax_error.rb +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49c72ccc76282ed1e7f9256f51f0adc1c886e1a05b3951e8f86d45eca0f22609
4
- data.tar.gz: 2d1fc7eefe0fb741a516adf09ea5c5472d8f678572cc73858a3a1b4468b10457
3
+ metadata.gz: 64abeaee0636d3ded8df0f0dc124674a70f954287b37302dff7151f04b746557
4
+ data.tar.gz: 02e6eea73a9e9e832b898f9294c1ce3f7f38f9b8996554a8f6527abf7027d115
5
5
  SHA512:
6
- metadata.gz: a4007362e70da478bb4590ad7196897b50fe4ab31bf384a4e4a80df44b906cee5faadf992a400a45d85e16b4864a42f17cc49490e8411020a4058310c088d84c
7
- data.tar.gz: 1cd5eaa6385bf7e451801c33d13f89a69c6412608067dc8acc23d7955ecc8ca5796ae839b966767a37f12b48e0d280fb0a1946e9d5e24f92edf14b2913b36c68
6
+ metadata.gz: e7381458f44ef92f5053ac3171ac8bc59e89a805d793dde1c48ce1eda855dcea624ef6dc7a1faa3da9c20abc53983675fc66a7b08e3e02893801b4b4ff0edf65
7
+ data.tar.gz: 8b92dee56fac32777f31b76e25a0b778b2a4ffa1ff6914f24ef835bbf5ab79898f4a3a5607a9bebc641f86b05f2a88224504f0f8aaab83c3262b1d067ea32af0
data/.circleci/config.yml CHANGED
@@ -1,12 +1,17 @@
1
1
  version: 2.1
2
2
  orbs:
3
- ruby: circleci/ruby@1.1.2
3
+ ruby: circleci/ruby@1.2.0
4
4
  references:
5
5
  unit: &unit
6
6
  run:
7
7
  name: Run test suite
8
8
  command: bundle exec rspec spec/
9
9
 
10
+ lint: &lint
11
+ run:
12
+ name: Run linter, fix with `standardrb --fix` locally
13
+ command: bundle exec standardrb
14
+
10
15
  jobs:
11
16
  "ruby-2-5":
12
17
  docker:
@@ -40,6 +45,25 @@ jobs:
40
45
  - ruby/install-deps
41
46
  - <<: *unit
42
47
 
48
+ "ruby-3-1":
49
+ docker:
50
+ - image: 'cimg/base:stable'
51
+ steps:
52
+ - checkout
53
+ - ruby/install:
54
+ version: '3.1.0-preview1'
55
+ - run: ruby -v
56
+ - ruby/install-deps
57
+ - <<: *unit
58
+
59
+ "lint":
60
+ docker:
61
+ - image: circleci/ruby:3.0
62
+ steps:
63
+ - checkout
64
+ - ruby/install-deps
65
+ - <<: *lint
66
+
43
67
  workflows:
44
68
  version: 2
45
69
  build:
@@ -48,3 +72,5 @@ workflows:
48
72
  - "ruby-2-6"
49
73
  - "ruby-2-7"
50
74
  - "ruby-3-0"
75
+ - "ruby-3-1"
76
+ - "lint"
@@ -1,13 +1,20 @@
1
1
  name: Check Changelog
2
2
 
3
3
  on:
4
- pull_request:
5
- types: [opened, reopened, edited, synchronize]
4
+ pull_request:
5
+ types: [opened, reopened, edited, labeled, unlabeled, synchronize]
6
+
6
7
  jobs:
7
- build:
8
+ check-changelog:
8
9
  runs-on: ubuntu-latest
10
+ if: |
11
+ !contains(github.event.pull_request.body, '[skip changelog]') &&
12
+ !contains(github.event.pull_request.body, '[changelog skip]') &&
13
+ !contains(github.event.pull_request.body, '[skip ci]') &&
14
+ !contains(github.event.pull_request.labels.*.name, 'skip changelog')
9
15
  steps:
10
- - uses: actions/checkout@v1
11
- - name: Check that CHANGELOG is touched
12
- run: |
13
- cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
16
+ - uses: actions/checkout@v2.3.5
17
+ - name: Check that CHANGELOG is touched
18
+ run: |
19
+ git fetch origin ${{ github.base_ref }} --depth 1 && \
20
+ git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ ruby_version: 2.5.9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  ## HEAD (unreleased)
2
2
 
3
+ ## 3.1.1
4
+
5
+ - Fix case where Ripper lexing identified incorrect code as a keyword (https://github.com/zombocom/dead_end/pull/122)
6
+
7
+ ## 3.1.0
8
+
9
+ - Add support for Ruby 3.1 by updating `require_relative` logic (https://github.com/zombocom/dead_end/pull/120)
10
+ - Requiring `dead_end/auto` is now deprecated please require `dead_end` instead (https://github.com/zombocom/dead_end/pull/119)
11
+ - Requiring `dead_end/api` now loads code without monkeypatching core extensions (https://github.com/zombocom/dead_end/pull/119)
12
+ - The interface `DeadEnd.handle_error` is declared public and stable (https://github.com/zombocom/dead_end/pull/119)
13
+
14
+ ## 3.0.3
15
+
16
+ - Expand explanations coming from additional Ripper errors (https://github.com/zombocom/dead_end/pull/117)
17
+ - Fix explanation involving shorthand syntax for literals like `%w[]` and `%Q{}` (https://github.com/zombocom/dead_end/pull/116)
18
+
19
+ ## 3.0.2
20
+
21
+ - Fix windows filename detection (https://github.com/zombocom/dead_end/pull/114)
22
+ - Update links on readme and code of conduct (https://github.com/zombocom/dead_end/pull/107)
23
+
24
+ ## 3.0.1
25
+
26
+ - Fix CLI parsing when flags come before filename (https://github.com/zombocom/dead_end/pull/102)
27
+
28
+ ## 3.0.0
29
+
30
+ - [Breaking] CLI now outputs to STDOUT instead of STDERR (https://github.com/zombocom/dead_end/pull/98)
31
+ - [Breaking] Remove previously deprecated `require "dead_end/fyi"` interface (https://github.com/zombocom/dead_end/pull/94)
32
+ - Fix double output bug (https://github.com/zombocom/dead_end/pull/99)
33
+ - Fix bug causing poor results (fix #95, fix #88) (https://github.com/zombocom/dead_end/pull/96)
34
+ - DeadEnd is now fired on EVERY syntax error (https://github.com/zombocom/dead_end/pull/94)
35
+ - Output format changes:
36
+ - Parse errors emitted per-block rather than for the whole document (https://github.com/zombocom/dead_end/pull/94)
37
+ - The "banner" is now based on lexical analysis rather than parser regex (fix #68, fix #87) (https://github.com/zombocom/dead_end/pull/96)
38
+
39
+ ## 2.0.2
40
+
41
+ - Don't print terminal color codes when output is not tty (https://github.com/zombocom/dead_end/pull/91)
42
+
43
+ ## 2.0.1
44
+
45
+ - Reintroduce Ruby 2.5 support (https://github.com/zombocom/dead_end/pull/90)
46
+ - Support naked braces/brackets/parens, invert labels on banner (https://github.com/zombocom/dead_end/pull/89)
47
+ - Handle mismatched end when using rescue without begin (https://github.com/zombocom/dead_end/pull/83)
48
+ - CLI returns non-zero exit code when syntax error is found (https://github.com/zombocom/dead_end/pull/86)
49
+ - Let -v respond with gem version instead of 'unknown' (https://github.com/zombocom/dead_end/pull/82)
50
+
51
+ ## 2.0.0
52
+
53
+ - Support "endless" oneline method definitions for Ruby 3+ (https://github.com/zombocom/dead_end/pull/80)
54
+ - Reduce timeout to 1 second (https://github.com/zombocom/dead_end/pull/79)
55
+ - Logically consecutive lines (such as chained methods are now joined) (https://github.com/zombocom/dead_end/pull/78)
56
+ - Output improvement for cases where the only line is an single `end` (https://github.com/zombocom/dead_end/pull/78)
57
+
58
+ ## 1.2.0
59
+
60
+ - Output improvements via less greedy unmatched kw capture https://github.com/zombocom/dead_end/pull/73
61
+ - Remove NoMethodError patching instead use https://github.com/ruby/error_highlight/ (https://github.com/zombocom/dead_end/pull/71)
62
+
3
63
  ## 1.1.7
4
64
 
5
65
  - Fix sinatra support for `require_relative` (https://github.com/zombocom/dead_end/pull/63)
data/CODE_OF_CONDUCT.md CHANGED
@@ -68,7 +68,7 @@ members of the project's leadership.
68
68
  ## Attribution
69
69
 
70
70
  This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
71
+ available at [https://contributor-covenant.org/version/1/4/code-of-conduct/][version]
72
72
 
73
73
  [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
74
+ [version]: https://contributor-covenant.org/version/1/4/code-of-conduct/
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "rake", "~> 12.0"
9
9
  gem "rspec", "~> 3.0"
10
10
  gem "stackprof"
11
+ gem "standard"
12
+ gem "ruby-prof"
data/Gemfile.lock CHANGED
@@ -1,13 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dead_end (1.1.7)
4
+ dead_end (3.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.2)
9
10
  diff-lcs (1.4.4)
11
+ parallel (1.21.0)
12
+ parser (3.0.2.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
10
15
  rake (12.3.3)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.5)
11
18
  rspec (3.10.0)
12
19
  rspec-core (~> 3.10.0)
13
20
  rspec-expectations (~> 3.10.0)
@@ -21,7 +28,27 @@ GEM
21
28
  diff-lcs (>= 1.2.0, < 2.0)
22
29
  rspec-support (~> 3.10.0)
23
30
  rspec-support (3.10.0)
31
+ rubocop (1.20.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.9.1, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.12.0)
41
+ parser (>= 3.0.1.1)
42
+ rubocop-performance (1.11.5)
43
+ rubocop (>= 1.7.0, < 2.0)
44
+ rubocop-ast (>= 0.4.0)
45
+ ruby-prof (1.4.3)
46
+ ruby-progressbar (1.11.0)
24
47
  stackprof (0.2.16)
48
+ standard (1.3.0)
49
+ rubocop (= 1.20.0)
50
+ rubocop-performance (= 1.11.5)
51
+ unicode-display_width (2.1.0)
25
52
 
26
53
  PLATFORMS
27
54
  ruby
@@ -30,7 +57,9 @@ DEPENDENCIES
30
57
  dead_end!
31
58
  rake (~> 12.0)
32
59
  rspec (~> 3.0)
60
+ ruby-prof
33
61
  stackprof
62
+ standard
34
63
 
35
64
  BUNDLED WITH
36
- 2.2.16
65
+ 2.3.4
data/README.md CHANGED
@@ -2,19 +2,14 @@
2
2
 
3
3
  An error in your code forces you to stop. DeadEnd helps you find those errors to get you back on your way faster.
4
4
 
5
- DeadEnd: Unmatched `end` detected
6
-
7
- This code has an unmatched `end`. Ensure that all `end` lines
8
- in your code have a matching syntax keyword (`def`, `do`, etc.)
9
- and that you don't have any extra `end` lines.
10
-
11
- file: path/to/dog.rb
12
- simplified:
5
+ ```
6
+ Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ?
13
7
 
14
- 3 class Dog
15
- 5 defbark
16
- 7 end
17
- 12 end
8
+ 1 class Dog
9
+ 2 defbark
10
+ 4 end
11
+ 5 end
12
+ ```
18
13
 
19
14
  ## Installation in your codebase
20
15
 
@@ -50,58 +45,112 @@ To get the CLI and manually search for syntax errors (but not automatically anno
50
45
 
51
46
  This gives you the CLI command `$ dead_end` for more info run `$ dead_end --help`.
52
47
 
48
+ ## Editor integration
49
+
50
+ An extension is available for VSCode:
51
+
52
+ - Extension: https://marketplace.visualstudio.com/items?itemName=Zombocom.dead-end-vscode
53
+ - GitHub: https://github.com/zombocom/dead_end-vscode
54
+
53
55
  ## What syntax errors does it handle?
54
56
 
57
+ Dead end will fire against all syntax errors and can isolate any syntax error. In addition, dead_end attempts to produce human readable descriptions of what needs to be done to resolve the issue. For example:
58
+
55
59
  - Missing `end`:
56
60
 
61
+ <!--
57
62
  ```ruby
58
63
  class Dog
59
64
  def bark
60
65
  puts "bark"
61
-
62
- def woof
63
- puts "woof"
64
- end
65
66
  end
66
- # => scratch.rb:8: syntax error, unexpected end-of-input, expecting `end'
67
67
  ```
68
+ -->
68
69
 
69
- - Unexpected `end`
70
+ ```
71
+ Unmatched keyword, missing `end' ?
70
72
 
73
+ ❯ 1 class Dog
74
+ ❯ 2 def bark
75
+ ❯ 4 end
76
+ ```
77
+
78
+ - Missing keyword
79
+ <!--
71
80
  ```ruby
72
81
  class Dog
73
82
  def speak
74
- @sounds.each |sound| # Note the missing `do` here
83
+ @sounds.each |sound|
75
84
  puts sound
76
85
  end
77
86
  end
78
87
  end
79
- # => scratch.rb:7: syntax error, unexpected `end', expecting end-of-input
88
+ ```
89
+ -->
90
+
91
+ ```
92
+ Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ?
93
+
94
+ 1 class Dog
95
+ 2 def speak
96
+ ❯ 3 @sounds.each |sound|
97
+ ❯ 5 end
98
+ 6 end
99
+ 7 end
80
100
  ```
81
101
 
82
- As well as unmatched `|` and unmatched `}`. These errors can be time consuming to debug because Ruby often only tells you the last line in the file. The command `ruby -wc path/to/file.rb` can narrow it down a little bit, but this library does a better job.
102
+ - Missing pair characters (like `{}`, `[]`, `()` , or `|<var>|`)
103
+ <!--
83
104
 
84
- ## What other errors does it handle?
105
+ ```ruby
106
+ class Dog
107
+ def speak(sound
108
+ puts sound
109
+ end
110
+ end
111
+ ```
112
+ -->
85
113
 
86
- In addition to syntax errors, the NoMethodError is annotated to show the line where the error occured, and the surrounding context:
114
+ ```
115
+ Unmatched `(', missing `)' ?
87
116
 
117
+ 1 class Dog
118
+ ❯ 2 def speak(sound
119
+ ❯ 4 end
120
+ 5 end
88
121
  ```
89
- scratch.rb:7:in `call': undefined method `upcase' for nil:NilClass (NoMethodError)
90
122
 
123
+ - Any ambiguous or unknown errors will be annotated by the original ripper error output:
124
+
125
+ <!--
126
+ class Dog
127
+ def meals_last_month
128
+ puts 3 *
129
+ end
130
+ end
131
+ -->
91
132
 
92
- 1 class Pet
93
- 6 def call
94
- ❯ 7 puts "Come here #{@neam.upcase}"
95
- 8 end
96
- 9 end
97
133
  ```
134
+ syntax error, unexpected end-of-input
98
135
 
99
- ## Sounds cool, but why isn't this baked into Ruby directly?
136
+ 1 class Dog
137
+ 2 def meals_last_month
138
+ ❯ 3 puts 3 *
139
+ 4 end
140
+ 5 end
141
+ ```
100
142
 
101
- I would love to get something like this directly in Ruby, but I first need to prove it's useful. The `did_you_mean` functionality started as a gem that was eventually adopted by a bunch of people and then Ruby core liked it enough that they included it in the source. The goal of this gem is to:
143
+ ## How is it better than `ruby -wc`?
102
144
 
103
- 1. Get real world useage and feedback. If we gave you an awful suggestion, let us know! We try to handle lots of cases well, but maybe we could be better.
104
- 2. Prove out demand. If you like this idea, then vote for it by putting it in your Gemfile.
145
+ Ruby allows you to syntax check a file with warnings using `ruby -wc`. This emits a parser error instead of a human focused error. Ruby's parse errors attempt to narrow down the location and can tell you if there is a glaring indentation error involving `end`.
146
+
147
+ The `dead_end` algorithm doesn't just guess at the location of syntax errors, it re-parses the document to prove that it captured them.
148
+
149
+ This library focuses on the human side of syntax errors. It cares less about why the document could not be parsed (computer problem) and more on what the programmer needs (human problem) to fix the problem.
150
+
151
+ ## Sounds cool, but why isn't this baked into Ruby directly?
152
+
153
+ We are now talking about it https://bugs.ruby-lang.org/issues/18159#change-93682.
105
154
 
106
155
  ## Artificial Inteligence?
107
156
 
@@ -117,15 +166,53 @@ Here's an example:
117
166
 
118
167
  ![](assets/syntax_search.gif)
119
168
 
169
+ ## Use internals
170
+
171
+ To use the `dead_end` gem without monkeypatching you can `require 'dead_en/api'`. This will allow you to load `dead_end` and use its internals without mutating `require`.
172
+
173
+ Stable internal interface(s):
174
+
175
+ - `DeadEnd.handle_error(e)`
176
+
177
+ Any other entrypoints are subject to change without warning. If you want to use an internal interface from `dead_end` not on this list, open an issue to explain your use case.
178
+
120
179
  ## Development
121
180
 
122
181
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
123
182
 
124
183
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
125
184
 
185
+ ### How to debug changes to output display
186
+
187
+ You can see changes to output against a variety of invalid code by running specs and using the `DEBUG_DISPLAY=1` environment variable. For example:
188
+
189
+ ```
190
+ $ DEBUG_DISPLAY=1 bundle exec rspec spec/ --format=failures
191
+ ```
192
+
193
+ ### Run profiler
194
+
195
+ You can output profiler data to the `tmp` directory by running:
196
+
197
+ ```
198
+ $ DEBUG_PERF=1 bundle exec rspec spec/integration/dead_end_spec.rb
199
+ ```
200
+
201
+ Some outputs are in text format, some are html, the raw marshaled data is available in `raw.rb.marshal`. See https://ruby-prof.github.io/#reports for more info. One interesting one, is the "kcachegrind" interface. To view this on mac:
202
+
203
+ ```
204
+ $ brew install qcachegrind
205
+ ```
206
+
207
+ Open:
208
+
209
+ ```
210
+ $ qcachegrind tmp/last/profile.callgrind.out.<numbers>
211
+ ```
212
+
126
213
  ## Contributing
127
214
 
128
- Bug reports and pull requests are welcome on GitHub at https://github.com/zombocom/dead_end. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/zombocom/dead_end/blob/master/CODE_OF_CONDUCT.md).
215
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zombocom/dead_end. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/zombocom/dead_end/blob/main/CODE_OF_CONDUCT.md).
129
216
 
130
217
 
131
218
  ## License
@@ -134,4 +221,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
134
221
 
135
222
  ## Code of Conduct
136
223
 
137
- Everyone interacting in the DeadEnd project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zombocom/dead_end/blob/master/CODE_OF_CONDUCT.md).
224
+ Everyone interacting in the DeadEnd project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zombocom/dead_end/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- task :default => :spec
8
+ task default: :spec
data/dead_end.gemspec CHANGED
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/dead_end/version'
3
+ require_relative "lib/dead_end/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "dead_end"
7
- spec.version = DeadEnd::VERSION
8
- spec.authors = ["schneems"]
9
- spec.email = ["richard.schneeman+foo@gmail.com"]
6
+ spec.name = "dead_end"
7
+ spec.version = DeadEnd::VERSION
8
+ spec.authors = ["schneems"]
9
+ spec.email = ["richard.schneeman+foo@gmail.com"]
10
10
 
11
- spec.summary = %q{Find syntax errors in your source in a snap}
12
- spec.description = %q{When you get an "unexpected end" in your syntax this gem helps you find it}
13
- spec.homepage = "https://github.com/zombocom/dead_end.git"
14
- spec.license = "MIT"
11
+ spec.summary = "Find syntax errors in your source in a snap"
12
+ spec.description = 'When you get an "unexpected end" in your syntax this gem helps you find it'
13
+ spec.homepage = "https://github.com/zombocom/dead_end.git"
14
+ spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
23
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|assets)/}) }
24
24
  end
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
  end
data/exe/dead_end CHANGED
@@ -1,70 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'pathname'
4
- require "optparse"
5
- require_relative "../lib/dead_end.rb"
3
+ require_relative "../lib/dead_end"
6
4
 
7
- options = {}
8
- options[:terminal] = true
9
- options[:record_dir] = ENV["DEAD_END_RECORD_DIR"]
10
-
11
- parser = OptionParser.new do |opts|
12
- opts.banner = <<~EOM
13
- Usage: dead_end <file> [options]
14
-
15
- Parses a ruby source file and searches for syntax error(s) such as
16
- unexpected `end', expecting end-of-input.
17
-
18
- Example:
19
-
20
- $ dead_end dog.rb
21
-
22
- # ...
23
-
24
- ❯ 10 defdog
25
- ❯ 15 end
26
- ❯ 16
27
-
28
- Env options:
29
-
30
- DEAD_END_RECORD_DIR=<dir>
31
-
32
- When enabled, records the steps used to search for a syntax error to the
33
- given directory
34
-
35
- Options:
36
- EOM
37
-
38
- opts.on("--help", "Help - displays this message") do |v|
39
- puts opts
40
- exit
41
- end
42
-
43
- opts.on("--record <dir>", "When enabled, records the steps used to search for a syntax error to the given directory") do |v|
44
- options[:record_dir] = v
45
- end
46
-
47
- opts.on("--no-terminal", "Disable terminal highlighting") do |v|
48
- options[:terminal] = false
49
- end
50
- end
51
- parser.parse!
52
-
53
- file = ARGV[0]
54
-
55
- if file.nil? || file.empty?
56
- # Display help if raw command
57
- parser.parse! %w[--help]
58
- end
59
-
60
- file = Pathname(file)
61
- options[:record_dir] = "tmp" if ENV["DEBUG"]
62
-
63
- $stderr.puts "Record dir: #{options[:record_dir]}" if options[:record_dir]
64
-
65
- DeadEnd.call(
66
- source: file.read,
67
- filename: file.expand_path,
68
- terminal: options[:terminal],
69
- record_dir: options[:record_dir]
70
- )
5
+ DeadEnd::Cli.new(
6
+ argv: ARGV
7
+ ).call