dead_end 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f04f0b2618c6787e30d722b387fe19eb026923d588abf15d676566a3496970f7
4
+ data.tar.gz: 9ea352efa6c3622eb9097a33f79db08219e4d156ea5ccbcfab3777e8e176472e
5
+ SHA512:
6
+ metadata.gz: 1dd513cdeba2f2e560eacd2113660e77f3eea9c0f0947629fe5c0e7352d2fcbf2178107fead38d7e7a32ead25e803b324809863af151eff70fb9831ffd43c8ec
7
+ data.tar.gz: e377f56853a8fd6e72afd9bb262965876dfa0242158a7a7327523825a3e1c008173bf1c2d6b1bf25b5a79c51711326e6cae098cfe4b363407929ccbf7ae8ad78
@@ -0,0 +1,41 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@1.1.2
4
+ references:
5
+ unit: &unit
6
+ run:
7
+ name: Run test suite
8
+ command: bundle exec rspec spec/
9
+
10
+ jobs:
11
+ "ruby-2-5":
12
+ docker:
13
+ - image: circleci/ruby:2.5
14
+ steps:
15
+ - checkout
16
+ - ruby/install-deps
17
+ - <<: *unit
18
+
19
+ "ruby-2-6":
20
+ docker:
21
+ - image: circleci/ruby:2.6
22
+ steps:
23
+ - checkout
24
+ - ruby/install-deps
25
+ - <<: *unit
26
+
27
+ "ruby-2-7":
28
+ docker:
29
+ - image: circleci/ruby:2.7
30
+ steps:
31
+ - checkout
32
+ - ruby/install-deps
33
+ - <<: *unit
34
+
35
+ workflows:
36
+ version: 2
37
+ build:
38
+ jobs:
39
+ - "ruby-2-5"
40
+ - "ruby-2-6"
41
+ - "ruby-2-7"
@@ -0,0 +1,13 @@
1
+ name: Check Changelog
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened, edited, synchronize]
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ 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
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ scratch.rb
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .DS_Store
14
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,39 @@
1
+ ## HEAD (unreleased)
2
+
3
+ ## 1.0.0
4
+
5
+ - Gem name changed from `syntax_search` to `dead_end` (https://github.com/zombocom/syntax_search/pull/30)
6
+ - Moved `syntax_search/auto` behavior to top level require (https://github.com/zombocom/syntax_search/pull/30)
7
+ - Error banner now indicates when missing a `|` or `}` in addition to `end` (https://github.com/zombocom/syntax_search/pull/29)
8
+ - Trailing slashes are now handled (joined) before the code search (https://github.com/zombocom/syntax_search/pull/28)
9
+
10
+ ## 0.2.0
11
+
12
+ - Simplify large file output so minimal context around the invalid section is shown (https://github.com/zombocom/syntax_search/pull/26)
13
+ - Block expansion is now lexically aware of keywords (def/do/end etc.) (https://github.com/zombocom/syntax_search/pull/24)
14
+ - Fix bug where not all of a source is lexed which is used in heredoc detection/removal (https://github.com/zombocom/syntax_search/pull/23)
15
+
16
+ ## 0.1.5
17
+
18
+ - Strip out heredocs in documents first (https://github.com/zombocom/syntax_search/pull/19)
19
+
20
+ ## 0.1.4
21
+
22
+ - Parser gem replaced with Ripper (https://github.com/zombocom/syntax_search/pull/17)
23
+
24
+ ## 0.1.3
25
+
26
+ - Internal refactor (https://github.com/zombocom/syntax_search/pull/13)
27
+
28
+ ## 0.1.2
29
+
30
+ - Codeblocks in output are now indented with 4 spaces and "code fences" are removed (https://github.com/zombocom/syntax_search/pull/11)
31
+ - "Unmatched end" and "missing end" not generate different error text instructions (https://github.com/zombocom/syntax_search/pull/10)
32
+
33
+ ## 0.1.1
34
+
35
+ - Fire search on both unexpected end-of-input and unexected end (https://github.com/zombocom/syntax_search/pull/8)
36
+
37
+ ## 0.1.0
38
+
39
+ - Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at richard.schneeman+foo@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
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]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dead_end.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 12.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "stackprof"
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dead_end (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ rake (12.3.3)
11
+ rspec (3.10.0)
12
+ rspec-core (~> 3.10.0)
13
+ rspec-expectations (~> 3.10.0)
14
+ rspec-mocks (~> 3.10.0)
15
+ rspec-core (3.10.0)
16
+ rspec-support (~> 3.10.0)
17
+ rspec-expectations (3.10.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-mocks (3.10.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-support (3.10.0)
24
+ stackprof (0.2.16)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ dead_end!
31
+ rake (~> 12.0)
32
+ rspec (~> 3.0)
33
+ stackprof
34
+
35
+ BUNDLED WITH
36
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 schneems
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,122 @@
1
+ # DeadEnd
2
+
3
+ An AI powered library to find syntax errors in your source code:
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:
13
+
14
+ 3 class Dog
15
+ ❯ 5 defbark
16
+ ❯ 7 end
17
+ 12 end
18
+
19
+ ## Installation in your codebase
20
+
21
+ To automatically search syntax errors when they happen, add this to your Gemfile:
22
+
23
+ ```ruby
24
+ gem 'dead_end'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle install
30
+
31
+ If your application is not calling `Bundler.require` then you must manually add a require:
32
+
33
+ ```ruby
34
+ require "dead_end"
35
+ ```
36
+
37
+ If you're using rspec add this to your `.rspec` file:
38
+
39
+ ```
40
+ --require dead_end
41
+ ```
42
+
43
+ > 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.
44
+
45
+ ## Install the CLI
46
+
47
+ To get the CLI and manually search for syntax errors, install the gem:
48
+
49
+ $ gem install dead_end
50
+
51
+ This gives you the CLI command `$ dead_end` for more info run `$ dead_end --help`.
52
+
53
+ ## What syntax errors does it handle?
54
+
55
+ - Missing `end`:
56
+
57
+ ```
58
+ class Dog
59
+ def bark
60
+ puts "bark"
61
+
62
+ def woof
63
+ puts "woof"
64
+ end
65
+ end
66
+ # => scratch.rb:8: syntax error, unexpected end-of-input, expecting `end'
67
+ ```
68
+
69
+ - Unexpected `end`
70
+
71
+ ```
72
+ class Dog
73
+ def speak
74
+ @sounds.each |sound| # Note the missing `do` here
75
+ puts sound
76
+ end
77
+ end
78
+ end
79
+ # => scratch.rb:7: syntax error, unexpected `end', expecting end-of-input
80
+ ```
81
+
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.
83
+
84
+ ## Sounds cool, but why isn't this baked into Ruby directly?
85
+
86
+ 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:
87
+
88
+ 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.
89
+ 2. Prove out demand. If you like this idea, then vote for it by putting it in your Gemfile.
90
+
91
+ ## Artificial Inteligence?
92
+
93
+ This library uses a goal-seeking algorithm similar to that of a path-finding search. For more information [read the blog post about how it works under the hood](https://schneems.com/2020/12/01/squash-unexpectedend-errors-with-syntaxsearch/).
94
+
95
+ ## How does it detect syntax error locations?
96
+
97
+ We know that source code that does not contain a syntax error can be parsed. We also know that code with a syntax error contains both valid code and invalid code. If you remove the invalid code, then we can programatically determine that the code we removed contained a syntax error. We can do this detection by generating small code blocks and searching for which blocks need to be removed to generate valid source code.
98
+
99
+ Since there can be multiple syntax errors in a document it's not good enough to check individual code blocks, we've got to check multiple at the same time. We will keep creating and adding new blocks to our search until we detect that our "frontier" (which contains all of our blocks) contains the syntax error. After this, we can stop our search and instead focus on filtering to find the smallest subset of blocks that contain the syntax error.
100
+
101
+ Here's an example:
102
+
103
+ ![](assets/syntax_search.gif)
104
+
105
+ ## Development
106
+
107
+ 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.
108
+
109
+ 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).
110
+
111
+ ## Contributing
112
+
113
+ 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).
114
+
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
119
+
120
+ ## Code of Conduct
121
+
122
+ 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).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
Binary file
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dead_end"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/dead_end/version'
4
+
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"]
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"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/zombocom/dead_end.git"
19
+
20
+ # Specify which files should be added to the gem when it is released.
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
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end