From b57fe7fc1d6b928c8f34cde0590e698350284da7 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 26 Jul 2022 13:59:01 -0500 Subject: [PATCH] Rename DeadEnd -> SyntaxSuggest Based on this conversation (https://bugs.ruby-lang.org/issues/18159#note-29) I was asked to change the name of DeadEnd because it might sound scary. This name is more meaningful as it represents what it does. It suggests the location of syntax errors. --- .circleci/config.yml | 2 +- CHANGELOG.md | 11 ++--- Gemfile.lock | 4 +- README.md | 34 +++++++------- bin/console | 2 +- dead_end.gemspec | 10 ++--- exe/dead_end | 7 --- exe/syntax_suggest | 7 +++ lib/dead_end.rb | 3 -- lib/dead_end/auto.rb | 6 --- lib/dead_end/version.rb | 5 --- lib/syntax_suggest.rb | 3 ++ lib/{dead_end => syntax_suggest}/api.rb | 36 +++++++-------- .../around_block_scan.rb | 2 +- .../block_expand.rb | 4 +- .../capture_code_context.rb | 4 +- .../clean_document.rb | 2 +- lib/{dead_end => syntax_suggest}/cli.rb | 20 ++++----- .../code_block.rb | 4 +- .../code_frontier.rb | 6 +-- lib/{dead_end => syntax_suggest}/code_line.rb | 2 +- .../code_search.rb | 8 ++-- lib/{dead_end => syntax_suggest}/core_ext.rb | 44 +++++++++---------- .../display_code_with_line_numbers.rb | 2 +- .../display_invalid_blocks.rb | 2 +- .../explain_syntax.rb | 2 +- .../left_right_lex_count.rb | 2 +- lib/{dead_end => syntax_suggest}/lex_all.rb | 2 +- lib/{dead_end => syntax_suggest}/lex_value.rb | 2 +- .../parse_blocks_from_indent_line.rb | 2 +- .../pathname_from_message.rb | 10 ++--- .../priority_engulf_queue.rb | 2 +- .../priority_queue.rb | 2 +- .../ripper_errors.rb | 2 +- .../unvisited_lines.rb | 2 +- lib/syntax_suggest/version.rb | 5 +++ spec/fixtures/this_project_extra_def.rb.txt | 2 +- spec/integration/exe_cli_spec.rb | 8 ++-- spec/integration/ruby_command_line_spec.rb | 34 +++++++------- ...ead_end_spec.rb => syntax_suggest_spec.rb} | 22 +++++----- spec/spec_helper.rb | 6 +-- spec/unit/api_spec.rb | 20 ++++----- spec/unit/around_block_scan_spec.rb | 2 +- spec/unit/block_expand_spec.rb | 2 +- spec/unit/capture_code_context_spec.rb | 2 +- spec/unit/clean_document_spec.rb | 4 +- spec/unit/cli_spec.rb | 14 +++--- spec/unit/code_block_spec.rb | 2 +- spec/unit/code_frontier_spec.rb | 2 +- spec/unit/code_line_spec.rb | 8 ++-- spec/unit/code_search_spec.rb | 2 +- spec/unit/display_invalid_blocks_spec.rb | 2 +- spec/unit/explain_syntax_spec.rb | 2 +- spec/unit/lex_all_spec.rb | 2 +- spec/unit/pathname_from_message_spec.rb | 2 +- spec/unit/priority_queue_spec.rb | 2 +- 56 files changed, 199 insertions(+), 204 deletions(-) delete mode 100755 exe/dead_end create mode 100755 exe/syntax_suggest delete mode 100644 lib/dead_end.rb delete mode 100644 lib/dead_end/auto.rb delete mode 100644 lib/dead_end/version.rb create mode 100644 lib/syntax_suggest.rb rename lib/{dead_end => syntax_suggest}/api.rb (84%) rename lib/{dead_end => syntax_suggest}/around_block_scan.rb (99%) rename lib/{dead_end => syntax_suggest}/block_expand.rb (95%) rename lib/{dead_end => syntax_suggest}/capture_code_context.rb (98%) rename lib/{dead_end => syntax_suggest}/clean_document.rb (99%) rename lib/{dead_end => syntax_suggest}/cli.rb (84%) rename lib/{dead_end => syntax_suggest}/code_block.rb (96%) rename lib/{dead_end => syntax_suggest}/code_frontier.rb (98%) rename lib/{dead_end => syntax_suggest}/code_line.rb (99%) rename lib/{dead_end => syntax_suggest}/code_search.rb (94%) rename lib/{dead_end => syntax_suggest}/core_ext.rb (53%) rename lib/{dead_end => syntax_suggest}/display_code_with_line_numbers.rb (98%) rename lib/{dead_end => syntax_suggest}/display_invalid_blocks.rb (98%) rename lib/{dead_end => syntax_suggest}/explain_syntax.rb (99%) rename lib/{dead_end => syntax_suggest}/left_right_lex_count.rb (99%) rename lib/{dead_end => syntax_suggest}/lex_all.rb (98%) rename lib/{dead_end => syntax_suggest}/lex_value.rb (98%) rename lib/{dead_end => syntax_suggest}/parse_blocks_from_indent_line.rb (98%) rename lib/{dead_end => syntax_suggest}/pathname_from_message.rb (82%) rename lib/{dead_end => syntax_suggest}/priority_engulf_queue.rb (98%) rename lib/{dead_end => syntax_suggest}/priority_queue.rb (98%) rename lib/{dead_end => syntax_suggest}/ripper_errors.rb (97%) rename lib/{dead_end => syntax_suggest}/unvisited_lines.rb (97%) create mode 100644 lib/syntax_suggest/version.rb rename spec/integration/{dead_end_spec.rb => syntax_suggest_spec.rb} (93%) diff --git a/.circleci/config.yml b/.circleci/config.yml index ba9b24a..0c842bd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 orbs: - ruby: circleci/ruby@1.2.0 + ruby: circleci/ruby@1.8.0 references: unit: &unit run: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0400161..8070b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,16 @@ ## HEAD (unreleased) -- [Breaking] Lazy loading moved from `autoload` to manually checking for constants and requiring `dead_end/api`. To manually use any DeadEnd internals you MUST require `dead_end/api`, otherwise it will be lazy loaded on syntax error (https://github.com/zombocom/dead_end/pull/148) +- [Breaking] Rename `dead_end` to `syntax_suggest` (https://github.com/zombocom/dead_end/pull/154) +- [Breaking] Lazy loading moved from `autoload` to manually checking for constants and requiring `dead_end/api`. To manually use any SyntaxSuggest internals you MUST require `dead_end/api`, otherwise it will be lazy loaded on syntax error (https://github.com/zombocom/dead_end/pull/148) - Default to highlighted output on Ruby 3.2 (https://github.com/zombocom/dead_end/pull/150) -- Debug functionality enabled by `DEBUG=1` env var is now under `DEAD_END_DEBUG=1`. Note this is not a stable interface or feature. Output content is subject to change without major version change (https://github.com/zombocom/dead_end/pull/149) +- Debug functionality enabled by `DEBUG=1` env var is now under `SYNTAX_SUGGEST_DEBUG=1`. Note this is not a stable interface or feature. Output content is subject to change without major version change (https://github.com/zombocom/dead_end/pull/149) - Enable/Disable dead_end by using the `dead_end` kwarg in `detailed_message` (https://github.com/zombocom/dead_end/pull/147) - Respect `highlight` kwarg in Ruby 3.2's `detailed_message` to enable/disable control characters (https://github.com/zombocom/dead_end/pull/147) ## 4.0.0 - Code that does not have an associated file (eval and streamed) no longer produce a warning saying that the file could not be found. To produce a warning with these code types run with DEBUG=1 environment variable. (https://github.com/zombocom/dead_end/pull/143) -- [Breaking] Lazy load DeadEnd internals only if there is a Syntax error. Use `require "dead_end"; require "dead_end/api"` to load eagerly all internals. Otherwise `require "dead_end"` will set up an autoload for the first time the DeadEnd module is used in code. This should only happen on a syntax error. (https://github.com/zombocom/dead_end/pull/142) +- [Breaking] Lazy load SyntaxSuggest internals only if there is a Syntax error. Use `require "dead_end"; require "dead_end/api"` to load eagerly all internals. Otherwise `require "dead_end"` will set up an autoload for the first time the SyntaxSuggest module is used in code. This should only happen on a syntax error. (https://github.com/zombocom/dead_end/pull/142) - Monkeypatch `SyntaxError#detailed_message` in Ruby 3.2+ instead of `require`, `load`, and `require_relative` (https://github.com/zombocom/dead_end/pull/139) ## 3.1.2 @@ -25,7 +26,7 @@ - Add support for Ruby 3.1 by updating `require_relative` logic (https://github.com/zombocom/dead_end/pull/120) - Requiring `dead_end/auto` is now deprecated please require `dead_end` instead (https://github.com/zombocom/dead_end/pull/119) - Requiring `dead_end/api` now loads code without monkeypatching core extensions (https://github.com/zombocom/dead_end/pull/119) -- The interface `DeadEnd.handle_error` is declared public and stable (https://github.com/zombocom/dead_end/pull/119) +- The interface `SyntaxSuggest.handle_error` is declared public and stable (https://github.com/zombocom/dead_end/pull/119) ## 3.0.3 @@ -47,7 +48,7 @@ - [Breaking] Remove previously deprecated `require "dead_end/fyi"` interface (https://github.com/zombocom/dead_end/pull/94) - Fix double output bug (https://github.com/zombocom/dead_end/pull/99) - Fix bug causing poor results (fix #95, fix #88) (https://github.com/zombocom/dead_end/pull/96) -- DeadEnd is now fired on EVERY syntax error (https://github.com/zombocom/dead_end/pull/94) +- SyntaxSuggest is now fired on EVERY syntax error (https://github.com/zombocom/dead_end/pull/94) - Output format changes: - Parse errors emitted per-block rather than for the whole document (https://github.com/zombocom/dead_end/pull/94) - The "banner" is now based on lexical analysis rather than parser regex (fix #68, fix #87) (https://github.com/zombocom/dead_end/pull/96) diff --git a/Gemfile.lock b/Gemfile.lock index 9a6cbc2..5bd05a7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dead_end (4.0.0) + syntax_suggest (0.0.1) GEM remote: https://rubygems.org/ @@ -56,12 +56,12 @@ PLATFORMS DEPENDENCIES benchmark-ips - dead_end! rake (~> 12.0) rspec (~> 3.0) ruby-prof stackprof standard + syntax_suggest! BUNDLED WITH 2.3.14 diff --git a/README.md b/README.md index c6536e5..5c2086e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# DeadEnd +# SyntaxSuggest -An error in your code forces you to stop. DeadEnd helps you find those errors to get you back on your way faster. +An error in your code forces you to stop. SyntaxSuggest helps you find those errors to get you back on your way faster. ``` Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ? @@ -16,7 +16,7 @@ Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ? To automatically annotate errors when they happen, add this to your Gemfile: ```ruby -gem 'dead_end' +gem 'syntax_suggest' ``` And then execute: @@ -26,13 +26,13 @@ And then execute: If your application is not calling `Bundler.require` then you must manually add a require: ```ruby -require "dead_end" +require "syntax_suggest" ``` If you're using rspec add this to your `.rspec` file: ``` ---require dead_end +--require syntax_suggest ``` > This is needed because people can execute a single test file via `bundle exec rspec path/to/file_spec.rb` and if that file has a syntax error, it won't load `spec_helper.rb` to trigger any requires. @@ -41,9 +41,9 @@ If you're using rspec add this to your `.rspec` file: To get the CLI and manually search for syntax errors (but not automatically annotate them), you can manually install the gem: - $ gem install dead_end + $ gem install syntax_suggest -This gives you the CLI command `$ dead_end` for more info run `$ dead_end --help`. +This gives you the CLI command `$ syntax_suggest` for more info run `$ syntax_suggest --help`. ## Editor integration @@ -54,7 +54,7 @@ An extension is available for VSCode: ## What syntax errors does it handle? -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: +Syntax suggest will fire against all syntax errors and can isolate any syntax error. In addition, syntax_suggest attempts to produce human readable descriptions of what needs to be done to resolve the issue. For example: - Missing `end`: @@ -144,7 +144,7 @@ syntax error, unexpected end-of-input 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`. -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. +The `syntax_suggest` algorithm doesn't just guess at the location of syntax errors, it re-parses the document to prove that it captured them. 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. @@ -168,13 +168,13 @@ Here's an example: ## Use internals -To use the `dead_end` gem without monkeypatching you can `require 'dead_end/api'`. This will allow you to load `dead_end` and use its internals without mutating `require`. +To use the `syntax_suggest` gem without monkeypatching you can `require 'syntax_suggest/api'`. This will allow you to load `syntax_suggest` and use its internals without mutating `require`. Stable internal interface(s): -- `DeadEnd.handle_error(e)` +- `SyntaxSuggest.handle_error(e)` -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. +Any other entrypoints are subject to change without warning. If you want to use an internal interface from `syntax_suggest` not on this list, open an issue to explain your use case. ## Development @@ -195,7 +195,7 @@ $ DEBUG_DISPLAY=1 bundle exec rspec spec/ --format=failures You can output profiler data to the `tmp` directory by running: ``` -$ DEBUG_PERF=1 bundle exec rspec spec/integration/dead_end_spec.rb +$ DEBUG_PERF=1 bundle exec rspec spec/integration/syntax_suggest_spec.rb ``` 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: @@ -212,12 +212,12 @@ $ qcachegrind tmp/last/profile.callgrind.out. ## Environment variables -- `DEAD_END_DEBUG` - Enables debug output to STDOUT/STDERR and/or disk at `./tmp`. The contents of debugging output are not stable and may change. If you would like stability, please open an issue to explain your use case. -- `DEAD_END_TIMEOUT` - Changes the default timeout value to the number set (in seconds). +- `SYNTAX_SUGGEST_DEBUG` - Enables debug output to STDOUT/STDERR and/or disk at `./tmp`. The contents of debugging output are not stable and may change. If you would like stability, please open an issue to explain your use case. +- `SYNTAX_SUGGEST_TIMEOUT` - Changes the default timeout value to the number set (in seconds). ## Contributing -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). +Bug reports and pull requests are welcome on GitHub at https://github.com/zombocom/syntax_suggest. 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/syntax_suggest/blob/main/CODE_OF_CONDUCT.md). ## License @@ -226,4 +226,4 @@ The gem is available as open source under the terms of the [MIT License](https:/ ## Code of Conduct -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). +Everyone interacting in the SyntaxSuggest project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zombocom/syntax_suggest/blob/main/CODE_OF_CONDUCT.md). diff --git a/bin/console b/bin/console index b3c0995..c889cb8 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require "bundler/setup" -require "dead_end" +require "syntax_suggest" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. diff --git a/dead_end.gemspec b/dead_end.gemspec index 4268ea7..acf9be7 100644 --- a/dead_end.gemspec +++ b/dead_end.gemspec @@ -1,25 +1,25 @@ # frozen_string_literal: true begin - require_relative "lib/dead_end/version" + require_relative "lib/syntax_suggest/version" rescue LoadError # Fallback to load version file in ruby core repository require_relative "version" end Gem::Specification.new do |spec| - spec.name = "dead_end" - spec.version = DeadEnd::VERSION + spec.name = "syntax_suggest" + spec.version = SyntaxSuggest::VERSION spec.authors = ["schneems"] spec.email = ["richard.schneeman+foo@gmail.com"] spec.summary = "Find syntax errors in your source in a snap" spec.description = 'When you get an "unexpected end" in your syntax this gem helps you find it' - spec.homepage = "https://github.com/zombocom/dead_end.git" + spec.homepage = "https://github.com/zombocom/syntax_suggest.git" spec.license = "MIT" spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0") spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/zombocom/dead_end.git" + spec.metadata["source_code_uri"] = "https://github.com/zombocom/syntax_suggest.git" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. diff --git a/exe/dead_end b/exe/dead_end deleted file mode 100755 index db44d5d..0000000 --- a/exe/dead_end +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env ruby - -require_relative "../lib/dead_end/api" - -DeadEnd::Cli.new( - argv: ARGV -).call diff --git a/exe/syntax_suggest b/exe/syntax_suggest new file mode 100755 index 0000000..e4a0b0b --- /dev/null +++ b/exe/syntax_suggest @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +require_relative "../lib/syntax_suggest/api" + +SyntaxSuggest::Cli.new( + argv: ARGV +).call diff --git a/lib/dead_end.rb b/lib/dead_end.rb deleted file mode 100644 index 1467770..0000000 --- a/lib/dead_end.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -require_relative "dead_end/core_ext" diff --git a/lib/dead_end/auto.rb b/lib/dead_end/auto.rb deleted file mode 100644 index c96fe2d..0000000 --- a/lib/dead_end/auto.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -require_relative "../dead_end" -require_relative "core_ext" - -warn "Calling `require 'dead_end/auto'` is deprecated, please `require 'dead_end'` instead." diff --git a/lib/dead_end/version.rb b/lib/dead_end/version.rb deleted file mode 100644 index 4210eff..0000000 --- a/lib/dead_end/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -module DeadEnd - VERSION = "4.0.0" -end diff --git a/lib/syntax_suggest.rb b/lib/syntax_suggest.rb new file mode 100644 index 0000000..1a45dfa --- /dev/null +++ b/lib/syntax_suggest.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require_relative "syntax_suggest/core_ext" diff --git a/lib/dead_end/api.rb b/lib/syntax_suggest/api.rb similarity index 84% rename from lib/dead_end/api.rb rename to lib/syntax_suggest/api.rb index 402f5e3..5b725e1 100644 --- a/lib/dead_end/api.rb +++ b/lib/syntax_suggest/api.rb @@ -8,15 +8,15 @@ require "ripper" require "timeout" -module DeadEnd +module SyntaxSuggest # Used to indicate a default value that cannot # be confused with another input. DEFAULT_VALUE = Object.new.freeze class Error < StandardError; end - TIMEOUT_DEFAULT = ENV.fetch("DEAD_END_TIMEOUT", 1).to_i + TIMEOUT_DEFAULT = ENV.fetch("SYNTAX_SUGGEST_TIMEOUT", 1).to_i - # DeadEnd.handle_error [Public] + # SyntaxSuggest.handle_error [Public] # # Takes a `SyntaxError` exception, uses the # error message to locate the file. Then the file @@ -28,7 +28,7 @@ class Error < StandardError; end # begin # require 'bad_file' # rescue => e - # DeadEnd.handle_error(e) + # SyntaxSuggest.handle_error(e) # end # # By default it will re-raise the exception unless @@ -40,7 +40,7 @@ class Error < StandardError; end # `re_raise: false`). def self.handle_error(e, re_raise: true, io: $stderr) unless e.is_a?(SyntaxError) - io.puts("DeadEnd: Must pass a SyntaxError, got: #{e.class}") + io.puts("SyntaxSuggest: Must pass a SyntaxError, got: #{e.class}") raise e end @@ -58,7 +58,7 @@ def self.handle_error(e, re_raise: true, io: $stderr) raise e if re_raise end - # DeadEnd.call [Private] + # SyntaxSuggest.call [Private] # # Main private interface def self.call(source:, filename: DEFAULT_VALUE, terminal: DEFAULT_VALUE, record_dir: DEFAULT_VALUE, timeout: TIMEOUT_DEFAULT, io: $stderr) @@ -78,11 +78,11 @@ def self.call(source:, filename: DEFAULT_VALUE, terminal: DEFAULT_VALUE, record_ code_lines: search.code_lines ).call rescue Timeout::Error => e - io.puts "Search timed out DEAD_END_TIMEOUT=#{timeout}, run with DEBUG=1 for more info" + io.puts "Search timed out SYNTAX_SUGGEST_TIMEOUT=#{timeout}, run with DEBUG=1 for more info" io.puts e.backtrace.first(3).join($/) end - # DeadEnd.record_dir [Private] + # SyntaxSuggest.record_dir [Private] # # Used to generate a unique directory to record # search steps for debugging @@ -95,7 +95,7 @@ def self.record_dir(dir) } end - # DeadEnd.valid_without? [Private] + # SyntaxSuggest.valid_without? [Private] # # This will tell you if the `code_lines` would be valid # if you removed the `without_lines`. In short it's a @@ -108,12 +108,12 @@ def self.record_dir(dir) # CodeLine.new(line: "end\n", index: 2) # ] # - # DeadEnd.valid_without?( + # SyntaxSuggest.valid_without?( # without_lines: code_lines[1], # code_lines: code_lines # ) # => true # - # DeadEnd.valid?(code_lines) # => false + # SyntaxSuggest.valid?(code_lines) # => false def self.valid_without?(without_lines:, code_lines:) lines = code_lines - Array(without_lines).flatten @@ -124,9 +124,9 @@ def self.valid_without?(without_lines:, code_lines:) end end - # DeadEnd.invalid? [Private] + # SyntaxSuggest.invalid? [Private] # - # Opposite of `DeadEnd.valid?` + # Opposite of `SyntaxSuggest.valid?` def self.invalid?(source) source = source.join if source.is_a?(Array) source = source.to_s @@ -134,16 +134,16 @@ def self.invalid?(source) Ripper.new(source).tap(&:parse).error? end - # DeadEnd.valid? [Private] + # SyntaxSuggest.valid? [Private] # # Returns truthy if a given input source is valid syntax # - # DeadEnd.valid?(<<~EOM) # => true + # SyntaxSuggest.valid?(<<~EOM) # => true # def foo # end # EOM # - # DeadEnd.valid?(<<~EOM) # => false + # SyntaxSuggest.valid?(<<~EOM) # => false # def foo # def bar # Syntax error here # end @@ -152,14 +152,14 @@ def self.invalid?(source) # You can also pass in an array of lines and they'll be # joined before evaluating # - # DeadEnd.valid?( + # SyntaxSuggest.valid?( # [ # "def foo\n", # "end\n" # ] # ) # => true # - # DeadEnd.valid?( + # SyntaxSuggest.valid?( # [ # "def foo\n", # " def bar\n", # Syntax error here diff --git a/lib/dead_end/around_block_scan.rb b/lib/syntax_suggest/around_block_scan.rb similarity index 99% rename from lib/dead_end/around_block_scan.rb rename to lib/syntax_suggest/around_block_scan.rb index 8c12c68..2a57d1b 100644 --- a/lib/dead_end/around_block_scan.rb +++ b/lib/syntax_suggest/around_block_scan.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # This class is useful for exploring contents before and after # a block # diff --git a/lib/dead_end/block_expand.rb b/lib/syntax_suggest/block_expand.rb similarity index 95% rename from lib/dead_end/block_expand.rb rename to lib/syntax_suggest/block_expand.rb index 7f3396f..396b2c3 100644 --- a/lib/dead_end/block_expand.rb +++ b/lib/syntax_suggest/block_expand.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # This class is responsible for taking a code block that exists # at a far indentaion and then iteratively increasing the block # so that it captures everything within the same indentation block. @@ -68,7 +68,7 @@ def expand_neighbors(block) # Managable rspec errors def inspect - "#" + "#" end end end diff --git a/lib/dead_end/capture_code_context.rb b/lib/syntax_suggest/capture_code_context.rb similarity index 98% rename from lib/dead_end/capture_code_context.rb rename to lib/syntax_suggest/capture_code_context.rb index 4134a39..c74a366 100644 --- a/lib/dead_end/capture_code_context.rb +++ b/lib/syntax_suggest/capture_code_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Turns a "invalid block(s)" into useful context # # There are three main phases in the algorithm: @@ -137,7 +137,7 @@ def capture_before_after_kws(block) # puts "woof" # 3 # end # 4 # - # However due to https://github.com/zombocom/dead_end/issues/32 + # However due to https://github.com/zombocom/syntax_suggest/issues/32 # the problem line will be identified as: # # ❯ class Dog # 1 diff --git a/lib/dead_end/clean_document.rb b/lib/syntax_suggest/clean_document.rb similarity index 99% rename from lib/dead_end/clean_document.rb rename to lib/syntax_suggest/clean_document.rb index e4c5f18..b572189 100644 --- a/lib/dead_end/clean_document.rb +++ b/lib/syntax_suggest/clean_document.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Parses and sanitizes source into a lexically aware document # # Internally the document is represented by an array with each diff --git a/lib/dead_end/cli.rb b/lib/syntax_suggest/cli.rb similarity index 84% rename from lib/dead_end/cli.rb rename to lib/syntax_suggest/cli.rb index 6ea3aba..b89fa5d 100644 --- a/lib/dead_end/cli.rb +++ b/lib/syntax_suggest/cli.rb @@ -3,8 +3,8 @@ require "pathname" require "optparse" -module DeadEnd - # All the logic of the exe/dead_end CLI in one handy spot +module SyntaxSuggest + # All the logic of the exe/syntax_suggest CLI in one handy spot # # Cli.new(argv: ["--help"]).call # Cli.new(argv: [".rb"]).call @@ -20,9 +20,9 @@ class Cli def initialize(argv:, exit_obj: Kernel, io: $stdout, env: ENV) @options = {} @parser = nil - options[:record_dir] = env["DEAD_END_RECORD_DIR"] + options[:record_dir] = env["SYNTAX_SUGGEST_RECORD_DIR"] options[:record_dir] = "tmp" if env["DEBUG"] - options[:terminal] = DeadEnd::DEFAULT_VALUE + options[:terminal] = SyntaxSuggest::DEFAULT_VALUE @io = io @argv = argv @@ -56,11 +56,11 @@ def call @io.puts "Record dir: #{options[:record_dir]}" if options[:record_dir] - display = DeadEnd.call( + display = SyntaxSuggest.call( io: @io, source: file.read, filename: file.expand_path, - terminal: options.fetch(:terminal, DeadEnd::DEFAULT_VALUE), + terminal: options.fetch(:terminal, SyntaxSuggest::DEFAULT_VALUE), record_dir: options[:record_dir] ) @@ -80,14 +80,14 @@ def parse def parser @parser ||= OptionParser.new do |opts| opts.banner = <<~EOM - Usage: dead_end [options] + Usage: syntax_suggest [options] Parses a ruby source file and searches for syntax error(s) such as unexpected `end', expecting end-of-input. Example: - $ dead_end dog.rb + $ syntax_suggest dog.rb # ... @@ -96,7 +96,7 @@ def parser ENV options: - DEAD_END_RECORD_DIR= + SYNTAX_SUGGEST_RECORD_DIR= Records the steps used to search for a syntax error to the given directory @@ -104,7 +104,7 @@ def parser Options: EOM - opts.version = DeadEnd::VERSION + opts.version = SyntaxSuggest::VERSION opts.on("--help", "Help - displays this message") do |v| @io.puts opts diff --git a/lib/dead_end/code_block.rb b/lib/syntax_suggest/code_block.rb similarity index 96% rename from lib/dead_end/code_block.rb rename to lib/syntax_suggest/code_block.rb index dc14c56..61e7986 100644 --- a/lib/dead_end/code_block.rb +++ b/lib/syntax_suggest/code_block.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Multiple lines form a singular CodeBlock # # Source code is made of multiple CodeBlocks. @@ -86,7 +86,7 @@ def valid? @valid = if lines.all? { |l| l.hidden? || l.empty? } true else - DeadEnd.valid?(lines.map(&:original).join) + SyntaxSuggest.valid?(lines.map(&:original).join) end else @valid diff --git a/lib/dead_end/code_frontier.rb b/lib/syntax_suggest/code_frontier.rb similarity index 98% rename from lib/dead_end/code_frontier.rb rename to lib/syntax_suggest/code_frontier.rb index 0309770..8e93b32 100644 --- a/lib/dead_end/code_frontier.rb +++ b/lib/syntax_suggest/code_frontier.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # The main function of the frontier is to hold the edges of our search and to # evaluate when we can stop searching. @@ -93,7 +93,7 @@ def holds_all_syntax_errors?(block_array = @queue, can_cache: true) block.lines end - DeadEnd.valid_without?( + SyntaxSuggest.valid_without?( without_lines: without_lines, code_lines: @code_lines ) @@ -115,7 +115,7 @@ def expand? frontier_indent = @queue.peek.current_indent unvisited_indent = next_indent_line.indent - if ENV["DEAD_END_DEBUG"] + if ENV["SYNTAX_SUGGEST_DEBUG"] puts "```" puts @queue.peek.to_s puts "```" diff --git a/lib/dead_end/code_line.rb b/lib/syntax_suggest/code_line.rb similarity index 99% rename from lib/dead_end/code_line.rb rename to lib/syntax_suggest/code_line.rb index 6520518..dc738ab 100644 --- a/lib/dead_end/code_line.rb +++ b/lib/syntax_suggest/code_line.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Represents a single line of code of a given source file # # This object contains metadata about the line such as diff --git a/lib/dead_end/code_search.rb b/lib/syntax_suggest/code_search.rb similarity index 94% rename from lib/dead_end/code_search.rb rename to lib/syntax_suggest/code_search.rb index db0df0b..2a86dfe 100644 --- a/lib/dead_end/code_search.rb +++ b/lib/syntax_suggest/code_search.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Searches code for a syntax error # # There are three main phases in the algorithm: @@ -43,13 +43,13 @@ class CodeSearch def initialize(source, record_dir: DEFAULT_VALUE) record_dir = if record_dir == DEFAULT_VALUE - ENV["DEAD_END_RECORD_DIR"] || ENV["DEAD_END_DEBUG"] ? "tmp" : nil + ENV["SYNTAX_SUGGEST_RECORD_DIR"] || ENV["SYNTAX_SUGGEST_DEBUG"] ? "tmp" : nil else record_dir end if record_dir - @record_dir = DeadEnd.record_dir(record_dir) + @record_dir = SyntaxSuggest.record_dir(record_dir) @write_count = 0 end @@ -70,7 +70,7 @@ def record(block:, name: "record") return unless @record_dir @name_tick[name] += 1 filename = "#{@write_count += 1}-#{name}-#{@name_tick[name]}-(#{block.starts_at}__#{block.ends_at}).txt" - if ENV["DEAD_END_DEBUG"] + if ENV["SYNTAX_SUGGEST_DEBUG"] puts "\n\n==== #{filename} ====" puts "\n```#{block.starts_at}..#{block.ends_at}" puts block.to_s diff --git a/lib/dead_end/core_ext.rb b/lib/syntax_suggest/core_ext.rb similarity index 53% rename from lib/dead_end/core_ext.rb rename to lib/syntax_suggest/core_ext.rb index 884cb1d..40f5fe1 100644 --- a/lib/dead_end/core_ext.rb +++ b/lib/syntax_suggest/core_ext.rb @@ -2,7 +2,7 @@ # Ruby 3.2+ has a cleaner way to hook into Ruby that doesn't use `require` if SyntaxError.method_defined?(:detailed_message) - module DeadEnd + module SyntaxSuggest class MiniStringIO def initialize(isatty: $stderr.isatty) @string = +"" @@ -19,22 +19,22 @@ def puts(value = $/, **) end SyntaxError.prepend Module.new { - def detailed_message(highlight: true, dead_end: true, **kwargs) - return super unless dead_end + def detailed_message(highlight: true, syntax_suggest: true, **kwargs) + return super unless syntax_suggest - require "dead_end/api" unless defined?(DeadEnd::DEFAULT_VALUE) + require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE) message = super file = if highlight - DeadEnd::PathnameFromMessage.new(super(highlight: false, **kwargs)).call.name + SyntaxSuggest::PathnameFromMessage.new(super(highlight: false, **kwargs)).call.name else - DeadEnd::PathnameFromMessage.new(message).call.name + SyntaxSuggest::PathnameFromMessage.new(message).call.name end - io = DeadEnd::MiniStringIO.new + io = SyntaxSuggest::MiniStringIO.new if file - DeadEnd.call( + SyntaxSuggest.call( io: io, source: file.read, filename: file, @@ -47,7 +47,7 @@ def detailed_message(highlight: true, dead_end: true, **kwargs) message end rescue => e - if ENV["DEAD_END_DEBUG"] + if ENV["SYNTAX_SUGGEST_DEBUG"] $stderr.warn(e.message) $stderr.warn(e.backtrace) end @@ -64,38 +64,38 @@ def detailed_message(highlight: true, dead_end: true, **kwargs) module Kernel module_function - alias_method :dead_end_original_require, :require - alias_method :dead_end_original_require_relative, :require_relative - alias_method :dead_end_original_load, :load + alias_method :syntax_suggest_original_require, :require + alias_method :syntax_suggest_original_require_relative, :require_relative + alias_method :syntax_suggest_original_load, :load def load(file, wrap = false) - dead_end_original_load(file) + syntax_suggest_original_load(file) rescue SyntaxError => e - require "dead_end/api" unless defined?(DeadEnd::DEFAULT_VALUE) + require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE) - DeadEnd.handle_error(e) + SyntaxSuggest.handle_error(e) end def require(file) - dead_end_original_require(file) + syntax_suggest_original_require(file) rescue SyntaxError => e - require "dead_end/api" unless defined?(DeadEnd::DEFAULT_VALUE) + require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE) - DeadEnd.handle_error(e) + SyntaxSuggest.handle_error(e) end def require_relative(file) if Pathname.new(file).absolute? - dead_end_original_require file + syntax_suggest_original_require file else relative_from = caller_locations(1..1).first relative_from_path = relative_from.absolute_path || relative_from.path - dead_end_original_require File.expand_path("../#{file}", relative_from_path) + syntax_suggest_original_require File.expand_path("../#{file}", relative_from_path) end rescue SyntaxError => e - require "dead_end/api" unless defined?(DeadEnd::DEFAULT_VALUE) + require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE) - DeadEnd.handle_error(e) + SyntaxSuggest.handle_error(e) end end end diff --git a/lib/dead_end/display_code_with_line_numbers.rb b/lib/syntax_suggest/display_code_with_line_numbers.rb similarity index 98% rename from lib/dead_end/display_code_with_line_numbers.rb rename to lib/syntax_suggest/display_code_with_line_numbers.rb index 0e12860..23f4b2d 100644 --- a/lib/dead_end/display_code_with_line_numbers.rb +++ b/lib/syntax_suggest/display_code_with_line_numbers.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Outputs code with highlighted lines # # Whatever is passed to this class will be rendered diff --git a/lib/dead_end/display_invalid_blocks.rb b/lib/syntax_suggest/display_invalid_blocks.rb similarity index 98% rename from lib/dead_end/display_invalid_blocks.rb rename to lib/syntax_suggest/display_invalid_blocks.rb index fff6023..bc1143f 100644 --- a/lib/dead_end/display_invalid_blocks.rb +++ b/lib/syntax_suggest/display_invalid_blocks.rb @@ -3,7 +3,7 @@ require_relative "capture_code_context" require_relative "display_code_with_line_numbers" -module DeadEnd +module SyntaxSuggest # Used for formatting invalid blocks class DisplayInvalidBlocks attr_reader :filename diff --git a/lib/dead_end/explain_syntax.rb b/lib/syntax_suggest/explain_syntax.rb similarity index 99% rename from lib/dead_end/explain_syntax.rb rename to lib/syntax_suggest/explain_syntax.rb index 5b12425..142ed2e 100644 --- a/lib/dead_end/explain_syntax.rb +++ b/lib/syntax_suggest/explain_syntax.rb @@ -2,7 +2,7 @@ require_relative "left_right_lex_count" -module DeadEnd +module SyntaxSuggest # Explains syntax errors based on their source # # example: diff --git a/lib/dead_end/left_right_lex_count.rb b/lib/syntax_suggest/left_right_lex_count.rb similarity index 99% rename from lib/dead_end/left_right_lex_count.rb rename to lib/syntax_suggest/left_right_lex_count.rb index 3b71ade..6fcae74 100644 --- a/lib/dead_end/left_right_lex_count.rb +++ b/lib/syntax_suggest/left_right_lex_count.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Find mis-matched syntax based on lexical count # # Used for detecting missing pairs of elements diff --git a/lib/dead_end/lex_all.rb b/lib/syntax_suggest/lex_all.rb similarity index 98% rename from lib/dead_end/lex_all.rb rename to lib/syntax_suggest/lex_all.rb index ec62461..132cba9 100644 --- a/lib/dead_end/lex_all.rb +++ b/lib/syntax_suggest/lex_all.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Ripper.lex is not guaranteed to lex the entire source document # # lex = LexAll.new(source: source) diff --git a/lib/dead_end/lex_value.rb b/lib/syntax_suggest/lex_value.rb similarity index 98% rename from lib/dead_end/lex_value.rb rename to lib/syntax_suggest/lex_value.rb index 8bb07b8..008cc10 100644 --- a/lib/dead_end/lex_value.rb +++ b/lib/syntax_suggest/lex_value.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Value object for accessing lex values # # This lex: diff --git a/lib/dead_end/parse_blocks_from_indent_line.rb b/lib/syntax_suggest/parse_blocks_from_indent_line.rb similarity index 98% rename from lib/dead_end/parse_blocks_from_indent_line.rb rename to lib/syntax_suggest/parse_blocks_from_indent_line.rb index 11fa2b8..d107173 100644 --- a/lib/dead_end/parse_blocks_from_indent_line.rb +++ b/lib/syntax_suggest/parse_blocks_from_indent_line.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # This class is responsible for generating initial code blocks # that will then later be expanded. # diff --git a/lib/dead_end/pathname_from_message.rb b/lib/syntax_suggest/pathname_from_message.rb similarity index 82% rename from lib/dead_end/pathname_from_message.rb rename to lib/syntax_suggest/pathname_from_message.rb index f2cc597..ea1a908 100644 --- a/lib/dead_end/pathname_from_message.rb +++ b/lib/syntax_suggest/pathname_from_message.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Converts a SyntaxError message to a path # # Handles the case where the filename has a colon in it - # such as on a windows file system: https://github.com/zombocom/dead_end/issues/111 + # such as on a windows file system: https://github.com/zombocom/syntax_suggest/issues/111 # # Example: # @@ -27,8 +27,8 @@ def initialize(message, io: $stderr) def call if skip_missing_file_name? - if ENV["DEAD_END_DEBUG"] - @io.puts "DeadEnd: Could not find filename from #{@line.inspect}" + if ENV["SYNTAX_SUGGEST_DEBUG"] + @io.puts "SyntaxSuggest: Could not find filename from #{@line.inspect}" end else until stop? @@ -37,7 +37,7 @@ def call end if @parts.empty? - @io.puts "DeadEnd: Could not find filename from #{@line.inspect}" + @io.puts "SyntaxSuggest: Could not find filename from #{@line.inspect}" @name = nil end end diff --git a/lib/dead_end/priority_engulf_queue.rb b/lib/syntax_suggest/priority_engulf_queue.rb similarity index 98% rename from lib/dead_end/priority_engulf_queue.rb rename to lib/syntax_suggest/priority_engulf_queue.rb index 6254609..2d1e9b1 100644 --- a/lib/dead_end/priority_engulf_queue.rb +++ b/lib/syntax_suggest/priority_engulf_queue.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Keeps track of what elements are in the queue in # priority and also ensures that when one element # engulfs/covers/eats another that the larger element diff --git a/lib/dead_end/priority_queue.rb b/lib/syntax_suggest/priority_queue.rb similarity index 98% rename from lib/dead_end/priority_queue.rb rename to lib/syntax_suggest/priority_queue.rb index 3621e70..1abda2a 100644 --- a/lib/dead_end/priority_queue.rb +++ b/lib/syntax_suggest/priority_queue.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Holds elements in a priority heap on insert # # Instead of constantly calling `sort!`, put diff --git a/lib/dead_end/ripper_errors.rb b/lib/syntax_suggest/ripper_errors.rb similarity index 97% rename from lib/dead_end/ripper_errors.rb rename to lib/syntax_suggest/ripper_errors.rb index 78fd2ea..48eb206 100644 --- a/lib/dead_end/ripper_errors.rb +++ b/lib/syntax_suggest/ripper_errors.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Capture parse errors from ripper # # Example: diff --git a/lib/dead_end/unvisited_lines.rb b/lib/syntax_suggest/unvisited_lines.rb similarity index 97% rename from lib/dead_end/unvisited_lines.rb rename to lib/syntax_suggest/unvisited_lines.rb index 3f5b496..32808db 100644 --- a/lib/dead_end/unvisited_lines.rb +++ b/lib/syntax_suggest/unvisited_lines.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DeadEnd +module SyntaxSuggest # Tracks which lines various code blocks have expanded to # and which are still unexplored class UnvisitedLines diff --git a/lib/syntax_suggest/version.rb b/lib/syntax_suggest/version.rb new file mode 100644 index 0000000..a5176dc --- /dev/null +++ b/lib/syntax_suggest/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module SyntaxSuggest + VERSION = "0.0.1" +end diff --git a/spec/fixtures/this_project_extra_def.rb.txt b/spec/fixtures/this_project_extra_def.rb.txt index 23369f7..e62fd3f 100644 --- a/spec/fixtures/this_project_extra_def.rb.txt +++ b/spec/fixtures/this_project_extra_def.rb.txt @@ -17,7 +17,7 @@ module SyntaxErrorSearch def call @io.puts <<~EOM - DeadEnd: A syntax error was detected + SyntaxSuggest: A syntax error was detected This code has an unmatched `end` this is caused by either missing a syntax keyword (`def`, `do`, etc.) or inclusion diff --git a/spec/integration/exe_cli_spec.rb b/spec/integration/exe_cli_spec.rb index 90f9983..79e659a 100644 --- a/spec/integration/exe_cli_spec.rb +++ b/spec/integration/exe_cli_spec.rb @@ -2,21 +2,21 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe "exe" do def exe_path - root_dir.join("exe").join("dead_end") + root_dir.join("exe").join("syntax_suggest") end def exe(cmd) out = run!("#{exe_path} #{cmd}", raise_on_nonzero_exit: false) - puts out if ENV["DEAD_END_DEBUG"] + puts out if ENV["SYNTAX_SUGGEST_DEBUG"] out end it "prints the version" do out = exe("-v") - expect(out.strip).to include(DeadEnd::VERSION) + expect(out.strip).to include(SyntaxSuggest::VERSION) end end end diff --git a/spec/integration/ruby_command_line_spec.rb b/spec/integration/ruby_command_line_spec.rb index 90d0cc4..7a1c5c6 100644 --- a/spec/integration/ruby_command_line_spec.rb +++ b/spec/integration/ruby_command_line_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe "Requires with ruby cli" do it "namespaces all monkeypatched methods" do Dir.mktmpdir do |dir| @@ -12,32 +12,32 @@ module DeadEnd puts Kernel.private_methods EOM - dead_end_methods_file = tmpdir.join("dead_end_methods.txt") + syntax_suggest_methods_file = tmpdir.join("syntax_suggest_methods.txt") api_only_methods_file = tmpdir.join("api_only_methods.txt") kernel_methods_file = tmpdir.join("kernel_methods.txt") - d_pid = Process.spawn("ruby -I#{lib_dir} -rdead_end #{script} 2>&1 > #{dead_end_methods_file}") + d_pid = Process.spawn("ruby -I#{lib_dir} -rsyntax_suggest #{script} 2>&1 > #{syntax_suggest_methods_file}") k_pid = Process.spawn("ruby #{script} 2>&1 >> #{kernel_methods_file}") - r_pid = Process.spawn("ruby -I#{lib_dir} -rdead_end/api #{script} 2>&1 > #{api_only_methods_file}") + r_pid = Process.spawn("ruby -I#{lib_dir} -rsyntax_suggest/api #{script} 2>&1 > #{api_only_methods_file}") Process.wait(k_pid) Process.wait(d_pid) Process.wait(r_pid) kernel_methods_array = kernel_methods_file.read.strip.lines.map(&:strip) - dead_end_methods_array = dead_end_methods_file.read.strip.lines.map(&:strip) + syntax_suggest_methods_array = syntax_suggest_methods_file.read.strip.lines.map(&:strip) api_only_methods_array = api_only_methods_file.read.strip.lines.map(&:strip) # In ruby 3.1.0-preview1 the `timeout` file is already required # we can remove it if it exists to normalize the output for # all ruby versions - [dead_end_methods_array, kernel_methods_array, api_only_methods_array].each do |array| + [syntax_suggest_methods_array, kernel_methods_array, api_only_methods_array].each do |array| array.delete("timeout") end - methods = (dead_end_methods_array - kernel_methods_array).sort + methods = (syntax_suggest_methods_array - kernel_methods_array).sort if methods.any? - expect(methods).to eq(["dead_end_original_load", "dead_end_original_require", "dead_end_original_require_relative"]) + expect(methods).to eq(["syntax_suggest_original_load", "syntax_suggest_original_require", "syntax_suggest_original_require_relative"]) end methods = (api_only_methods_array - kernel_methods_array).sort @@ -67,7 +67,7 @@ module DeadEnd load "#{script.expand_path}" EOM - out = `ruby -I#{lib_dir} -rdead_end #{require_rb} 2>&1` + out = `ruby -I#{lib_dir} -rsyntax_suggest #{require_rb} 2>&1` expect($?.success?).to be_falsey expect(out).to include('❯ 5 it "flerg"').once @@ -95,7 +95,7 @@ module DeadEnd end EOM - out = `ruby -I#{lib_dir} -rdead_end #{script} 2>&1` + out = `ruby -I#{lib_dir} -rsyntax_suggest #{script} 2>&1` expect($?.success?).to be_falsey expect(out).to include('❯ 5 it "flerg"').once @@ -110,10 +110,10 @@ module DeadEnd class Dog end - if defined?(DeadEnd::DEFAULT_VALUE) - puts "DeadEnd is loaded" + if defined?(SyntaxSuggest::DEFAULT_VALUE) + puts "SyntaxSuggest is loaded" else - puts "DeadEnd is NOT loaded" + puts "SyntaxSuggest is NOT loaded" end EOM @@ -122,10 +122,10 @@ class Dog load "#{script.expand_path}" EOM - out = `ruby -I#{lib_dir} -rdead_end #{require_rb} 2>&1` + out = `ruby -I#{lib_dir} -rsyntax_suggest #{require_rb} 2>&1` expect($?.success?).to be_truthy - expect(out).to include("DeadEnd is NOT loaded").once + expect(out).to include("SyntaxSuggest is NOT loaded").once end end @@ -138,12 +138,12 @@ class Dog eval("def lol") EOM - out = `ruby -I#{lib_dir} -rdead_end #{script} 2>&1` + out = `ruby -I#{lib_dir} -rsyntax_suggest #{script} 2>&1` expect($?.success?).to be_falsey expect(out).to include("(eval):1") - expect(out).to_not include("DeadEnd") + expect(out).to_not include("SyntaxSuggest") expect(out).to_not include("Could not find filename") end end diff --git a/spec/integration/dead_end_spec.rb b/spec/integration/syntax_suggest_spec.rb similarity index 93% rename from spec/integration/dead_end_spec.rb rename to spec/integration/syntax_suggest_spec.rb index 926383a..a7287ff 100644 --- a/spec/integration/dead_end_spec.rb +++ b/spec/integration/syntax_suggest_spec.rb @@ -2,10 +2,10 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe "Integration tests that don't spawn a process (like using the cli)" do it "does not timeout on massive files" do - next unless ENV["DEAD_END_TIMEOUT"] + next unless ENV["SYNTAX_SUGGEST_TIMEOUT"] file = fixtures_dir.join("syntax_tree.rb.txt") lines = file.read.lines @@ -15,7 +15,7 @@ module DeadEnd benchmark = Benchmark.measure do debug_perf do - DeadEnd.call( + SyntaxSuggest.call( io: io, source: lines.join, filename: file @@ -42,7 +42,7 @@ module DeadEnd debug_perf do benchmark = Benchmark.measure do - DeadEnd.call( + SyntaxSuggest.call( io: io, source: file.read, filename: file @@ -65,7 +65,7 @@ module DeadEnd source = fixtures_dir.join("routes.rb.txt").read io = StringIO.new - DeadEnd.call( + SyntaxSuggest.call( io: io, source: source ) @@ -84,7 +84,7 @@ module DeadEnd source = fixtures_dir.join("webmock.rb.txt").read io = StringIO.new - DeadEnd.call( + SyntaxSuggest.call( io: io, source: source ) @@ -106,7 +106,7 @@ module DeadEnd source = fixtures_dir.join("derailed_require_tree.rb.txt").read io = StringIO.new - DeadEnd.call( + SyntaxSuggest.call( io: io, source: source ) @@ -130,7 +130,7 @@ module DeadEnd lines = fixtures_dir.join("rexe.rb.txt").read.lines lines.delete_at(85 - 1) io = StringIO.new - DeadEnd.call( + SyntaxSuggest.call( io: io, source: lines.join ) @@ -153,7 +153,7 @@ module DeadEnd source = lines.join io = StringIO.new - DeadEnd.call( + SyntaxSuggest.call( io: io, source: source ) @@ -176,7 +176,7 @@ def call # 0 end # two # 3 EOM io = StringIO.new - DeadEnd.call( + SyntaxSuggest.call( io: io, source: source ) @@ -196,7 +196,7 @@ def bark end EOM io = StringIO.new - DeadEnd.call( + SyntaxSuggest.call( io: io, source: source ) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 31c3635..33f3ef3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "bundler/setup" -require "dead_end/api" +require "syntax_suggest/api" require "benchmark" require "tempfile" @@ -44,7 +44,7 @@ def fixtures_dir end def code_line_array(source) - DeadEnd::CleanDocument.new(source: source).call.lines + SyntaxSuggest::CleanDocument.new(source: source).call.lines end autoload :RubyProf, "ruby-prof" @@ -58,7 +58,7 @@ def debug_perf out = yield end - dir = DeadEnd.record_dir("tmp") + dir = SyntaxSuggest.record_dir("tmp") printer = RubyProf::MultiPrinter.new(result, [:flat, :graph, :graph_html, :tree, :call_tree, :stack, :dot]) printer.print(path: dir, profile: "profile") diff --git a/spec/unit/api_spec.rb b/spec/unit/api_spec.rb index 13a20d8..284a4cd 100644 --- a/spec/unit/api_spec.rb +++ b/spec/unit/api_spec.rb @@ -3,8 +3,8 @@ require_relative "../spec_helper" require "ruby-prof" -module DeadEnd - RSpec.describe "Top level DeadEnd api" do +module SyntaxSuggest + RSpec.describe "Top level SyntaxSuggest api" do it "has a `handle_error` interface" do fake_error = Object.new def fake_error.message @@ -16,7 +16,7 @@ def fake_error.is_a?(v) end io = StringIO.new - DeadEnd.handle_error( + SyntaxSuggest.handle_error( fake_error, re_raise: false, io: io @@ -29,7 +29,7 @@ def fake_error.is_a?(v) error = NameError.new("blerg") io = StringIO.new expect { - DeadEnd.handle_error( + SyntaxSuggest.handle_error( error, re_raise: false, io: io @@ -48,7 +48,7 @@ def fake_error.message io = StringIO.new expect { - DeadEnd.handle_error( + SyntaxSuggest.handle_error( fake_error, re_raise: false, io: io @@ -64,10 +64,10 @@ def fake_error.message error = SyntaxError.new("#{fixtures_dir.join("this_project_extra_def.rb.txt")}:1 ") - require "dead_end/core_ext" + require "syntax_suggest/core_ext" - expect(error.detailed_message(highlight: true)).to include(DeadEnd::DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT) - expect(error.detailed_message(highlight: false)).to_not include(DeadEnd::DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT) + expect(error.detailed_message(highlight: true)).to include(SyntaxSuggest::DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT) + expect(error.detailed_message(highlight: false)).to_not include(SyntaxSuggest::DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT) end it "can be disabled via falsey kwarg" do @@ -75,9 +75,9 @@ def fake_error.message error = SyntaxError.new("#{fixtures_dir.join("this_project_extra_def.rb.txt")}:1 ") - require "dead_end/core_ext" + require "syntax_suggest/core_ext" - expect(error.detailed_message(dead_end: true)).to_not eq(error.detailed_message(dead_end: false)) + expect(error.detailed_message(syntax_suggest: true)).to_not eq(error.detailed_message(syntax_suggest: false)) end end end diff --git a/spec/unit/around_block_scan_spec.rb b/spec/unit/around_block_scan_spec.rb index 8016b7f..6053c39 100644 --- a/spec/unit/around_block_scan_spec.rb +++ b/spec/unit/around_block_scan_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe AroundBlockScan do it "continues scan from last location even if scan is false" do source = <<~'EOM' diff --git a/spec/unit/block_expand_spec.rb b/spec/unit/block_expand_spec.rb index dc4dade..ba0b045 100644 --- a/spec/unit/block_expand_spec.rb +++ b/spec/unit/block_expand_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe BlockExpand do it "captures multiple empty and hidden lines" do source_string = <<~EOM diff --git a/spec/unit/capture_code_context_spec.rb b/spec/unit/capture_code_context_spec.rb index 9b77348..e1bc281 100644 --- a/spec/unit/capture_code_context_spec.rb +++ b/spec/unit/capture_code_context_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe CaptureCodeContext do it "capture_before_after_kws" do source = <<~'EOM' diff --git a/spec/unit/clean_document_spec.rb b/spec/unit/clean_document_spec.rb index bcd0e9f..fa049ad 100644 --- a/spec/unit/clean_document_spec.rb +++ b/spec/unit/clean_document_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe CleanDocument do it "heredocs" do source = fixtures_dir.join("this_project_extra_def.rb.txt").read @@ -11,7 +11,7 @@ module DeadEnd expect(code_lines[18 - 1].to_s).to eq(<<-'EOL') @io.puts <<~EOM - DeadEnd: A syntax error was detected + SyntaxSuggest: A syntax error was detected This code has an unmatched `end` this is caused by either missing a syntax keyword (`def`, `do`, etc.) or inclusion diff --git a/spec/unit/cli_spec.rb b/spec/unit/cli_spec.rb index 8925eb4..fecf3e3 100644 --- a/spec/unit/cli_spec.rb +++ b/spec/unit/cli_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest class FakeExit def initialize @called = false @@ -126,16 +126,16 @@ def called? exit_obj: exit_obj ).parser - expect(parser.version).to include(DeadEnd::VERSION.to_s) + expect(parser.version).to include(SyntaxSuggest::VERSION.to_s) end - it "DEAD_END_RECORD_DIR" do + it "SYNTAX_SUGGEST_RECORD_DIR" do io = StringIO.new exit_obj = FakeExit.new cli = Cli.new( io: io, argv: [], - env: {"DEAD_END_RECORD_DIR" => "hahaha"}, + env: {"SYNTAX_SUGGEST_RECORD_DIR" => "hahaha"}, exit_obj: exit_obj ).parse @@ -166,7 +166,7 @@ def called? ).parse expect(exit_obj.called?).to be_falsey - expect(cli.options[:terminal]).to eq(DeadEnd::DEFAULT_VALUE) + expect(cli.options[:terminal]).to eq(SyntaxSuggest::DEFAULT_VALUE) end it "--terminal" do @@ -205,7 +205,7 @@ def called? ).call expect(exit_obj.called?).to be_truthy - expect(io.string).to include("Usage: dead_end [options]") + expect(io.string).to include("Usage: syntax_suggest [options]") end it " outputs help" do @@ -218,7 +218,7 @@ def called? ).call expect(exit_obj.called?).to be_truthy - expect(io.string).to include("Usage: dead_end [options]") + expect(io.string).to include("Usage: syntax_suggest [options]") end end end diff --git a/spec/unit/code_block_spec.rb b/spec/unit/code_block_spec.rb index 41b2096..3ab2751 100644 --- a/spec/unit/code_block_spec.rb +++ b/spec/unit/code_block_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe CodeBlock do it "can detect if it's valid or not" do code_lines = code_line_array(<<~EOM) diff --git a/spec/unit/code_frontier_spec.rb b/spec/unit/code_frontier_spec.rb index a0e3aeb..c9aba7c 100644 --- a/spec/unit/code_frontier_spec.rb +++ b/spec/unit/code_frontier_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe CodeFrontier do it "detect_bad_blocks" do code_lines = code_line_array(<<~EOM) diff --git a/spec/unit/code_line_spec.rb b/spec/unit/code_line_spec.rb index cf3e75d..cc4fa48 100644 --- a/spec/unit/code_line_spec.rb +++ b/spec/unit/code_line_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe CodeLine do it "bug in keyword detection" do lines = CodeLine.from_source(<<~'EOM') @@ -104,7 +104,7 @@ def foo end EOM - expect(DeadEnd.valid?(code_lines)).to be_falsey + expect(SyntaxSuggest.valid?(code_lines)).to be_falsey expect(code_lines.join).to eq(<<~EOM) def foo Array(value) |x| @@ -125,7 +125,7 @@ def foo Array(value) |x| end EOM - expect(DeadEnd.valid?(code_lines)).to be_falsey + expect(SyntaxSuggest.valid?(code_lines)).to be_falsey end it "knows empty lines" do @@ -137,7 +137,7 @@ def foo expect(code_lines.map(&:empty?)).to eq([false, true, false]) expect(code_lines.map(&:not_empty?)).to eq([true, false, true]) - expect(code_lines.map { |l| DeadEnd.valid?(l) }).to eq([true, true, true]) + expect(code_lines.map { |l| SyntaxSuggest.valid?(l) }).to eq([true, true, true]) end it "counts indentations" do diff --git a/spec/unit/code_search_spec.rb b/spec/unit/code_search_spec.rb index 8f3ca19..b62b2c0 100644 --- a/spec/unit/code_search_spec.rb +++ b/spec/unit/code_search_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe CodeSearch do it "rexe regression" do lines = fixtures_dir.join("rexe.rb.txt").read.lines diff --git a/spec/unit/display_invalid_blocks_spec.rb b/spec/unit/display_invalid_blocks_spec.rb index 887f30e..c696132 100644 --- a/spec/unit/display_invalid_blocks_spec.rb +++ b/spec/unit/display_invalid_blocks_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe DisplayInvalidBlocks do it "works with valid code" do syntax_string = <<~EOM diff --git a/spec/unit/explain_syntax_spec.rb b/spec/unit/explain_syntax_spec.rb index 277bab5..394981d 100644 --- a/spec/unit/explain_syntax_spec.rb +++ b/spec/unit/explain_syntax_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe "ExplainSyntax" do it "handles shorthand syntaxes with non-bracket characters" do source = <<~EOM diff --git a/spec/unit/lex_all_spec.rb b/spec/unit/lex_all_spec.rb index ffcf243..0c0df7c 100644 --- a/spec/unit/lex_all_spec.rb +++ b/spec/unit/lex_all_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe "EndBlockParse" do it "finds blocks based on `end` keyword" do source = <<~EOM diff --git a/spec/unit/pathname_from_message_spec.rb b/spec/unit/pathname_from_message_spec.rb index c12aeeb..76756ef 100644 --- a/spec/unit/pathname_from_message_spec.rb +++ b/spec/unit/pathname_from_message_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest RSpec.describe "PathnameFromMessage" do it "handles filenames with colons in them" do Dir.mktmpdir do |dir| diff --git a/spec/unit/priority_queue_spec.rb b/spec/unit/priority_queue_spec.rb index 7381559..1736183 100644 --- a/spec/unit/priority_queue_spec.rb +++ b/spec/unit/priority_queue_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" -module DeadEnd +module SyntaxSuggest class CurrentIndex attr_reader :current_indent