Skip to content

Commit

Permalink
Start working on single line curlies
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Phippen committed Mar 18, 2019
1 parent 821ec0b commit ef08de7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
4 changes: 1 addition & 3 deletions fixtures/brace_blocks_with_no_args_expected.rb
@@ -1,5 +1,3 @@
def func
brace_block_with_no_args {
p("hi")
}
brace_block_with_no_args { p("hi") }
end
4 changes: 1 addition & 3 deletions fixtures/lambda_expected.rb
@@ -1,6 +1,4 @@
lambda { |x|
x
}
lambda { |x| x }
-> (arg) { arg }
-> (arg) { arg }
-> (arg) {
Expand Down
4 changes: 1 addition & 3 deletions fixtures/map_curly_expected.rb
@@ -1,7 +1,5 @@
module Foo
def slowest_examples
groups.map { |a, b|
a
}
groups.map { |a, b| a }
end
end
12 changes: 12 additions & 0 deletions fixtures/nested_conditionals_actual.rb
@@ -0,0 +1,12 @@
if a
if c
a
else
if a
b
elsif c
c
end
d
end
end
13 changes: 13 additions & 0 deletions fixtures/nested_conditionals_expected.rb
@@ -0,0 +1,13 @@
if a
if c
a
else
if a
b
elsif c
c
end

d
end
end
15 changes: 4 additions & 11 deletions fixtures/rspec_core_notifications_expected.rb
Expand Up @@ -403,10 +403,7 @@ def duplicate_rerun_locations
locations = RSpec.world.all_examples.map(&:location_rerun_argument)

Set.new.tap do |s|
locations.group_by { |l|
l

}.each do |l, ls|
locations.group_by { |l| l }.each do |l, ls|
s << l if ls.count > 1
end
end
Expand Down Expand Up @@ -470,15 +467,11 @@ def calculate_slowest_groups
hash[:average] = hash[:total_time].to_f / hash[:count]
end

groups = @example_groups.sort_by { |_, hash|
-hash[:average]
}.first(number_of_examples)
groups.map { |group, data|
[
groups = @example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)
groups.map { |group, data| [
group.location,
data,
]
}
] }
end
end

Expand Down
16 changes: 10 additions & 6 deletions src/rubyfmt.rb 100755 → 100644
@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
require 'ripper'
require 'stringio'
require 'pp'
require "ripper"
require "stringio"
require "pp"

MODE = :inline

LineMetadata = Struct.new(:comment_blocks)

class Line
Expand Down Expand Up @@ -35,6 +34,7 @@ def empty?

def to_s
build = @parts.join("")

unless @comments.empty?
build = "#{@comments.join("\n")}\n#{build}"
end
Expand Down Expand Up @@ -76,6 +76,10 @@ def contains_if?
@parts.any? { |x| x == :if }
end

def contains_else?
@parts.any? { |x| x == :else }
end

def contains_unless?
@parts.any? { |x| x == :unless }
end
Expand All @@ -85,7 +89,7 @@ def declares_private?
end

def declares_require?
@parts.any? { |x| x == "require" }
@parts.any? { |x| x == "require" } && @parts.none? { |x| x == "}" }
end

def declares_class_or_module?
Expand All @@ -97,7 +101,7 @@ def contains_while?
end

def surpresses_blankline?
contains_def? || contains_do? || contains_while?
contains_def? || contains_do? || contains_while? || contains_if? || contains_else?
end
end

Expand Down

0 comments on commit ef08de7

Please sign in to comment.