Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ references:
name: Run test suite
command: bundle exec rspec spec/

jobs:
"ruby-2-5":
docker:
- image: circleci/ruby:2.5
steps:
- checkout
- ruby/install-deps
- <<: *unit
lint: &lint
run:
name: Run linter, fix with `standardrb --fix` locally
command: bundle exec standardrb

jobs:
"ruby-2-6":
docker:
- image: circleci/ruby:2.6
Expand All @@ -40,11 +37,19 @@ jobs:
- ruby/install-deps
- <<: *unit

"lint":
docker:
- image: circleci/ruby:3.0
steps:
- checkout
- ruby/install-deps
- <<: *lint

workflows:
version: 2
build:
jobs:
- "ruby-2-5"
- "ruby-2-6"
- "ruby-2-7"
- "ruby-3-0"
- "lint"
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 2.6.6
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gemspec
gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "stackprof"
gem "standard"
29 changes: 28 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
diff-lcs (1.4.4)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
rainbow (3.0.0)
rake (12.3.3)
regexp_parser (2.1.1)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -21,7 +28,26 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.0)
rubocop (1.20.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.12.0)
parser (>= 3.0.1.1)
rubocop-performance (1.11.5)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
stackprof (0.2.16)
standard (1.3.0)
rubocop (= 1.20.0)
rubocop-performance (= 1.11.5)
unicode-display_width (2.1.0)

PLATFORMS
ruby
Expand All @@ -31,6 +57,7 @@ DEPENDENCIES
rake (~> 12.0)
rspec (~> 3.0)
stackprof
standard

BUNDLED WITH
2.2.16
2.2.27
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
24 changes: 12 additions & 12 deletions dead_end.gemspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# frozen_string_literal: true

require_relative 'lib/dead_end/version'
require_relative "lib/dead_end/version"

Gem::Specification.new do |spec|
spec.name = "dead_end"
spec.version = DeadEnd::VERSION
spec.authors = ["schneems"]
spec.email = ["richard.schneeman+foo@gmail.com"]
spec.name = "dead_end"
spec.version = DeadEnd::VERSION
spec.authors = ["schneems"]
spec.email = ["richard.schneeman+foo@gmail.com"]

spec.summary = %q{Find syntax errors in your source in a snap}
spec.description = %q{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.license = "MIT"
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.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"

# 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.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|assets)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
end
6 changes: 3 additions & 3 deletions exe/dead_end
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby

require 'pathname'
require "pathname"
require "optparse"
require_relative "../lib/dead_end.rb"
require_relative "../lib/dead_end"

options = {}
options[:terminal] = true
Expand Down Expand Up @@ -60,7 +60,7 @@ end
file = Pathname(file)
options[:record_dir] = "tmp" if ENV["DEBUG"]

$stderr.puts "Record dir: #{options[:record_dir]}" if options[:record_dir]
warn "Record dir: #{options[:record_dir]}" if options[:record_dir]

DeadEnd.call(
source: file.read,
Expand Down
25 changes: 13 additions & 12 deletions lib/dead_end/around_block_scan.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
#

module DeadEnd
# This class is useful for exploring contents before and after
# a block
Expand Down Expand Up @@ -28,7 +28,7 @@ module DeadEnd
#
# To grab the next surrounding indentation use AroundBlockScan#scan_adjacent_indent
class AroundBlockScan
def initialize(code_lines: , block:)
def initialize(code_lines:, block:)
@code_lines = code_lines
@orig_before_index = block.lines.first.index
@orig_after_index = block.lines.last.index
Expand Down Expand Up @@ -56,7 +56,7 @@ def scan_while(&block)
end_count = 0
@before_index = before_lines.reverse_each.take_while do |line|
next false if stop_next
next true if @skip_array.detect {|meth| line.send(meth) }
next true if @skip_array.detect { |meth| line.send(meth) }

kw_count += 1 if line.is_kw?
end_count += 1 if line.is_end?
Expand All @@ -65,14 +65,14 @@ def scan_while(&block)
end

block.call(line)
end.reverse.first&.index
end.last&.index

stop_next = false
kw_count = 0
end_count = 0
@after_index = after_lines.take_while do |line|
next false if stop_next
next true if @skip_array.detect {|meth| line.send(meth) }
next true if @skip_array.detect { |meth| line.send(meth) }

kw_count += 1 if line.is_kw?
end_count += 1 if line.is_end?
Expand All @@ -89,7 +89,7 @@ def capture_neighbor_context
lines = []
kw_count = 0
end_count = 0
before_lines.reverse.each do |line|
before_lines.reverse_each do |line|
next if line.empty?
break if line.indent < @orig_indent
next if line.indent != @orig_indent
Expand Down Expand Up @@ -124,14 +124,14 @@ def capture_neighbor_context

lines << line
end
lines.select! {|line| !line.is_comment? }
lines.select! { |line| !line.is_comment? }

lines
end

def on_falling_indent
last_indent = @orig_indent
before_lines.reverse.each do |line|
before_lines.reverse_each do |line|
next if line.empty?
if line.indent < last_indent
yield line
Expand All @@ -150,7 +150,7 @@ def on_falling_indent
end

def scan_neighbors
self.scan_while {|line| line.not_empty? && line.indent >= @orig_indent }
scan_while { |line| line.not_empty? && line.indent >= @orig_indent }
end

def next_up
Expand All @@ -167,13 +167,14 @@ def scan_adjacent_indent
before_after_indent << (next_down&.indent || 0)

indent = before_after_indent.min
self.scan_while {|line| line.not_empty? && line.indent >= indent }
scan_while { |line| line.not_empty? && line.indent >= indent }

self
end

def start_at_next_line
before_index; after_index
before_index
after_index
@before_index -= 1
@after_index += 1
self
Expand All @@ -196,7 +197,7 @@ def after_index
end

private def after_lines
@code_lines[after_index.next..-1] || []
@code_lines[after_index.next..] || []
end
end
end
4 changes: 2 additions & 2 deletions lib/dead_end/auto.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
#

require_relative "../dead_end/internals"

# Monkey patch kernel to ensure that all `require` calls call the same
Expand Down Expand Up @@ -40,6 +40,7 @@ def require_relative(file)
# am I doing something different?
class Object
private

def load(path, wrap = false)
Kernel.load(path, wrap)
rescue SyntaxError => e
Expand All @@ -52,4 +53,3 @@ def require(path)
DeadEnd.handle_error(e)
end
end

11 changes: 6 additions & 5 deletions lib/dead_end/block_expand.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module DeadEnd
# This class is responsible for taking a code block that exists
# at a far indentaion and then iteratively increasing the block
Expand Down Expand Up @@ -30,7 +31,7 @@ module DeadEnd
# end
#
class BlockExpand
def initialize(code_lines: )
def initialize(code_lines:)
@code_lines = code_lines
end

Expand All @@ -43,7 +44,7 @@ def call(block)
end

def expand_indent(block)
block = AroundBlockScan.new(code_lines: @code_lines, block: block)
AroundBlockScan.new(code_lines: @code_lines, block: block)
.skip(:hidden?)
.stop_after_kw
.scan_adjacent_indent
Expand All @@ -59,15 +60,15 @@ def expand_neighbors(block, grab_empty: true)
# Slurp up empties
if grab_empty
scan = AroundBlockScan.new(code_lines: @code_lines, block: scan.code_block)
.scan_while {|line| line.empty? || line.hidden? }
.scan_while { |line| line.empty? || line.hidden? }
end

new_block = scan.code_block

if block.lines == new_block.lines
return nil
nil
else
return new_block
new_block
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions lib/dead_end/capture_code_context.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module DeadEnd

# Given a block, this method will capture surrounding
# code to give the user more context for the location of
# the problem.
Expand All @@ -26,7 +25,7 @@ module DeadEnd
class CaptureCodeContext
attr_reader :code_lines

def initialize(blocks: , code_lines:)
def initialize(blocks:, code_lines:)
@blocks = Array(blocks)
@code_lines = code_lines
@visible_lines = @blocks.map(&:visible_lines).flatten
Expand All @@ -45,13 +44,13 @@ def call
@lines_to_output.uniq!
@lines_to_output.sort!

return @lines_to_output
@lines_to_output
end

def capture_falling_indent(block)
AroundBlockScan.new(
block: block,
code_lines: @code_lines,
code_lines: @code_lines
).on_falling_indent do |line|
@lines_to_output << line
end
Expand Down Expand Up @@ -95,7 +94,7 @@ def capture_last_end_same_indent(block)
# (this would return line 4)
#
# end # 4
matching_end = lines.select {|line| line.indent == block.current_indent && line.is_end? }.first
matching_end = lines.find { |line| line.indent == block.current_indent && line.is_end? }
return unless matching_end

@lines_to_output << matching_end
Expand Down
6 changes: 3 additions & 3 deletions lib/dead_end/code_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def ends_at
# populate an array with multiple code blocks then call `sort!`
# on it without having to specify the sorting criteria
def <=>(other)
out = self.current_indent <=> other.current_indent
out = current_indent <=> other.current_indent
return out if out != 0

# Stable sort
self.starts_at <=> other.starts_at
starts_at <=> other.starts_at
end

def current_indent
Expand All @@ -71,7 +71,7 @@ def invalid?

def valid?
return @valid if @valid != UNSET
@valid = DeadEnd.valid?(self.to_s)
@valid = DeadEnd.valid?(to_s)
end

def to_s
Expand Down
Loading