Skip to content

Commit 822df0f

Browse files
author
schneems
committed
Standardize formatting with standardrb gem
1 parent 2890304 commit 822df0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+247
-209
lines changed

.circleci/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ references:
77
name: Run test suite
88
command: bundle exec rspec spec/
99

10+
unit: &lint
11+
run:
12+
name: Run linter, fix with `standardrb --fix` locally
13+
command: bundle exec standardrb
14+
1015
jobs:
1116
"ruby-2-5":
1217
docker:
@@ -40,6 +45,14 @@ jobs:
4045
- ruby/install-deps
4146
- <<: *unit
4247

48+
"lint":
49+
docker:
50+
- image: circleci/ruby:3.0
51+
steps:
52+
- checkout
53+
- ruby/install-deps
54+
- <<: *lint
55+
4356
workflows:
4457
version: 2
4558
build:
@@ -48,3 +61,4 @@ workflows:
4861
- "ruby-2-6"
4962
- "ruby-2-7"
5063
- "ruby-3-0"
64+
- "lint"

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ gemspec
88
gem "rake", "~> 12.0"
99
gem "rspec", "~> 3.0"
1010
gem "stackprof"
11+
gem "standard"

Gemfile.lock

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ PATH
66
GEM
77
remote: https://rubygems.org/
88
specs:
9+
ast (2.4.2)
910
diff-lcs (1.4.4)
11+
parallel (1.21.0)
12+
parser (3.0.2.0)
13+
ast (~> 2.4.1)
14+
rainbow (3.0.0)
1015
rake (12.3.3)
16+
regexp_parser (2.1.1)
17+
rexml (3.2.5)
1118
rspec (3.10.0)
1219
rspec-core (~> 3.10.0)
1320
rspec-expectations (~> 3.10.0)
@@ -21,7 +28,26 @@ GEM
2128
diff-lcs (>= 1.2.0, < 2.0)
2229
rspec-support (~> 3.10.0)
2330
rspec-support (3.10.0)
31+
rubocop (1.20.0)
32+
parallel (~> 1.10)
33+
parser (>= 3.0.0.0)
34+
rainbow (>= 2.2.2, < 4.0)
35+
regexp_parser (>= 1.8, < 3.0)
36+
rexml
37+
rubocop-ast (>= 1.9.1, < 2.0)
38+
ruby-progressbar (~> 1.7)
39+
unicode-display_width (>= 1.4.0, < 3.0)
40+
rubocop-ast (1.12.0)
41+
parser (>= 3.0.1.1)
42+
rubocop-performance (1.11.5)
43+
rubocop (>= 1.7.0, < 2.0)
44+
rubocop-ast (>= 0.4.0)
45+
ruby-progressbar (1.11.0)
2446
stackprof (0.2.16)
47+
standard (1.3.0)
48+
rubocop (= 1.20.0)
49+
rubocop-performance (= 1.11.5)
50+
unicode-display_width (2.1.0)
2551

2652
PLATFORMS
2753
ruby
@@ -31,6 +57,7 @@ DEPENDENCIES
3157
rake (~> 12.0)
3258
rspec (~> 3.0)
3359
stackprof
60+
standard
3461

3562
BUNDLED WITH
36-
2.2.16
63+
2.2.27

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ require "rspec/core/rake_task"
55

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

8-
task :default => :spec
8+
task default: :spec

dead_end.gemspec

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# frozen_string_literal: true
22

3-
require_relative 'lib/dead_end/version'
3+
require_relative "lib/dead_end/version"
44

55
Gem::Specification.new do |spec|
6-
spec.name = "dead_end"
7-
spec.version = DeadEnd::VERSION
8-
spec.authors = ["schneems"]
9-
spec.email = ["richard.schneeman+foo@gmail.com"]
6+
spec.name = "dead_end"
7+
spec.version = DeadEnd::VERSION
8+
spec.authors = ["schneems"]
9+
spec.email = ["richard.schneeman+foo@gmail.com"]
1010

11-
spec.summary = %q{Find syntax errors in your source in a snap}
12-
spec.description = %q{When you get an "unexpected end" in your syntax this gem helps you find it}
13-
spec.homepage = "https://github.com/zombocom/dead_end.git"
14-
spec.license = "MIT"
11+
spec.summary = "Find syntax errors in your source in a snap"
12+
spec.description = 'When you get an "unexpected end" in your syntax this gem helps you find it'
13+
spec.homepage = "https://github.com/zombocom/dead_end.git"
14+
spec.license = "MIT"
1515
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
1616

1717
spec.metadata["homepage_uri"] = spec.homepage
1818
spec.metadata["source_code_uri"] = "https://github.com/zombocom/dead_end.git"
1919

2020
# Specify which files should be added to the gem when it is released.
2121
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
2323
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|assets)/}) }
2424
end
25-
spec.bindir = "exe"
26-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25+
spec.bindir = "exe"
26+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2727
spec.require_paths = ["lib"]
2828
end

exe/dead_end

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env ruby
22

3-
require 'pathname'
3+
require "pathname"
44
require "optparse"
5-
require_relative "../lib/dead_end.rb"
5+
require_relative "../lib/dead_end"
66

77
options = {}
88
options[:terminal] = true
@@ -60,7 +60,7 @@ end
6060
file = Pathname(file)
6161
options[:record_dir] = "tmp" if ENV["DEBUG"]
6262

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

6565
DeadEnd.call(
6666
source: file.read,

lib/dead_end/around_block_scan.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
2-
#
2+
33
module DeadEnd
44
# This class is useful for exploring contents before and after
55
# a block
@@ -28,7 +28,7 @@ module DeadEnd
2828
#
2929
# To grab the next surrounding indentation use AroundBlockScan#scan_adjacent_indent
3030
class AroundBlockScan
31-
def initialize(code_lines: , block:)
31+
def initialize(code_lines:, block:)
3232
@code_lines = code_lines
3333
@orig_before_index = block.lines.first.index
3434
@orig_after_index = block.lines.last.index
@@ -56,7 +56,7 @@ def scan_while(&block)
5656
end_count = 0
5757
@before_index = before_lines.reverse_each.take_while do |line|
5858
next false if stop_next
59-
next true if @skip_array.detect {|meth| line.send(meth) }
59+
next true if @skip_array.detect { |meth| line.send(meth) }
6060

6161
kw_count += 1 if line.is_kw?
6262
end_count += 1 if line.is_end?
@@ -65,14 +65,14 @@ def scan_while(&block)
6565
end
6666

6767
block.call(line)
68-
end.reverse.first&.index
68+
end.last&.index
6969

7070
stop_next = false
7171
kw_count = 0
7272
end_count = 0
7373
@after_index = after_lines.take_while do |line|
7474
next false if stop_next
75-
next true if @skip_array.detect {|meth| line.send(meth) }
75+
next true if @skip_array.detect { |meth| line.send(meth) }
7676

7777
kw_count += 1 if line.is_kw?
7878
end_count += 1 if line.is_end?
@@ -89,7 +89,7 @@ def capture_neighbor_context
8989
lines = []
9090
kw_count = 0
9191
end_count = 0
92-
before_lines.reverse.each do |line|
92+
before_lines.reverse_each do |line|
9393
next if line.empty?
9494
break if line.indent < @orig_indent
9595
next if line.indent != @orig_indent
@@ -124,14 +124,14 @@ def capture_neighbor_context
124124

125125
lines << line
126126
end
127-
lines.select! {|line| !line.is_comment? }
127+
lines.select! { |line| !line.is_comment? }
128128

129129
lines
130130
end
131131

132132
def on_falling_indent
133133
last_indent = @orig_indent
134-
before_lines.reverse.each do |line|
134+
before_lines.reverse_each do |line|
135135
next if line.empty?
136136
if line.indent < last_indent
137137
yield line
@@ -150,7 +150,7 @@ def on_falling_indent
150150
end
151151

152152
def scan_neighbors
153-
self.scan_while {|line| line.not_empty? && line.indent >= @orig_indent }
153+
scan_while { |line| line.not_empty? && line.indent >= @orig_indent }
154154
end
155155

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

169169
indent = before_after_indent.min
170-
self.scan_while {|line| line.not_empty? && line.indent >= indent }
170+
scan_while { |line| line.not_empty? && line.indent >= indent }
171171

172172
self
173173
end
174174

175175
def start_at_next_line
176-
before_index; after_index
176+
before_index
177+
after_index
177178
@before_index -= 1
178179
@after_index += 1
179180
self
@@ -196,7 +197,7 @@ def after_index
196197
end
197198

198199
private def after_lines
199-
@code_lines[after_index.next..-1] || []
200+
@code_lines[after_index.next..] || []
200201
end
201202
end
202203
end

lib/dead_end/auto.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
2-
#
2+
33
require_relative "../dead_end/internals"
44

55
# Monkey patch kernel to ensure that all `require` calls call the same
@@ -40,6 +40,7 @@ def require_relative(file)
4040
# am I doing something different?
4141
class Object
4242
private
43+
4344
def load(path, wrap = false)
4445
Kernel.load(path, wrap)
4546
rescue SyntaxError => e
@@ -52,4 +53,3 @@ def require(path)
5253
DeadEnd.handle_error(e)
5354
end
5455
end
55-

lib/dead_end/block_expand.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
module DeadEnd
34
# This class is responsible for taking a code block that exists
45
# at a far indentaion and then iteratively increasing the block
@@ -30,7 +31,7 @@ module DeadEnd
3031
# end
3132
#
3233
class BlockExpand
33-
def initialize(code_lines: )
34+
def initialize(code_lines:)
3435
@code_lines = code_lines
3536
end
3637

@@ -43,7 +44,7 @@ def call(block)
4344
end
4445

4546
def expand_indent(block)
46-
block = AroundBlockScan.new(code_lines: @code_lines, block: block)
47+
AroundBlockScan.new(code_lines: @code_lines, block: block)
4748
.skip(:hidden?)
4849
.stop_after_kw
4950
.scan_adjacent_indent
@@ -59,15 +60,15 @@ def expand_neighbors(block, grab_empty: true)
5960
# Slurp up empties
6061
if grab_empty
6162
scan = AroundBlockScan.new(code_lines: @code_lines, block: scan.code_block)
62-
.scan_while {|line| line.empty? || line.hidden? }
63+
.scan_while { |line| line.empty? || line.hidden? }
6364
end
6465

6566
new_block = scan.code_block
6667

6768
if block.lines == new_block.lines
68-
return nil
69+
nil
6970
else
70-
return new_block
71+
new_block
7172
end
7273
end
7374
end

lib/dead_end/capture_code_context.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
module DeadEnd
4-
54
# Given a block, this method will capture surrounding
65
# code to give the user more context for the location of
76
# the problem.
@@ -26,7 +25,7 @@ module DeadEnd
2625
class CaptureCodeContext
2726
attr_reader :code_lines
2827

29-
def initialize(blocks: , code_lines:)
28+
def initialize(blocks:, code_lines:)
3029
@blocks = Array(blocks)
3130
@code_lines = code_lines
3231
@visible_lines = @blocks.map(&:visible_lines).flatten
@@ -45,13 +44,13 @@ def call
4544
@lines_to_output.uniq!
4645
@lines_to_output.sort!
4746

48-
return @lines_to_output
47+
@lines_to_output
4948
end
5049

5150
def capture_falling_indent(block)
5251
AroundBlockScan.new(
5352
block: block,
54-
code_lines: @code_lines,
53+
code_lines: @code_lines
5554
).on_falling_indent do |line|
5655
@lines_to_output << line
5756
end
@@ -95,7 +94,7 @@ def capture_last_end_same_indent(block)
9594
# (this would return line 4)
9695
#
9796
# end # 4
98-
matching_end = lines.select {|line| line.indent == block.current_indent && line.is_end? }.first
97+
matching_end = lines.find { |line| line.indent == block.current_indent && line.is_end? }
9998
return unless matching_end
10099

101100
@lines_to_output << matching_end

0 commit comments

Comments
 (0)