Skip to content

Commit

Permalink
Rename DeadEnd -> SyntaxSuggest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schneems committed Jul 26, 2022
1 parent 622dfdd commit b57fe7f
Show file tree
Hide file tree
Showing 56 changed files with 199 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .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:
Expand Down
11 changes: 6 additions & 5 deletions 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
Expand All @@ -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

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
dead_end (4.0.0)
syntax_suggest (0.0.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -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
34 changes: 17 additions & 17 deletions 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.) ?
Expand All @@ -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:
Expand All @@ -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.
Expand All @@ -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

Expand All @@ -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`:

Expand Down Expand Up @@ -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.

Expand All @@ -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

Expand All @@ -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:
Expand All @@ -212,12 +212,12 @@ $ qcachegrind tmp/last/profile.callgrind.out.<numbers>

## 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
Expand All @@ -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).
2 changes: 1 addition & 1 deletion 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.
Expand Down
10 changes: 5 additions & 5 deletions 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.
Expand Down
7 changes: 0 additions & 7 deletions exe/dead_end

This file was deleted.

7 changes: 7 additions & 0 deletions exe/syntax_suggest
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

require_relative "../lib/syntax_suggest/api"

SyntaxSuggest::Cli.new(
argv: ARGV
).call
3 changes: 0 additions & 3 deletions lib/dead_end.rb

This file was deleted.

6 changes: 0 additions & 6 deletions lib/dead_end/auto.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/dead_end/version.rb

This file was deleted.

3 changes: 3 additions & 0 deletions lib/syntax_suggest.rb
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative "syntax_suggest/core_ext"
36 changes: 18 additions & 18 deletions lib/dead_end/api.rb → lib/syntax_suggest/api.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -124,26 +124,26 @@ 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

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
Expand All @@ -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
Expand Down
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module DeadEnd
module SyntaxSuggest
# This class is useful for exploring contents before and after
# a block
#
Expand Down

0 comments on commit b57fe7f

Please sign in to comment.