Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace internal #8695

Merged
merged 4 commits into from Sep 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .rubocop.yml
Expand Up @@ -59,9 +59,8 @@ Layout/ClassStructure:
- protected_methods
- private_methods

# Trailing white space is meaningful in code examples
Layout/TrailingWhitespace:
AllowInHeredoc: true
AllowInHeredoc: false

Lint/AmbiguousBlockAssociation:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/layout/empty_line_between_defs_spec.rb
Expand Up @@ -283,7 +283,7 @@ def a; end; def b; end
RUBY

expect_correction(<<~RUBY)
def a; end;
def a; end;#{trailing_whitespace}

def b; end
RUBY
Expand Down
Expand Up @@ -43,7 +43,7 @@ class Test
something

#{access_modifier}

def test; end
end
RUBY
Expand Down Expand Up @@ -339,7 +339,7 @@ class Test

#{access_modifier}
#{'^' * access_modifier.size} Remove a blank line after `#{access_modifier}`.

def test; end
end
RUBY
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/layout/empty_lines_around_block_body_spec.rb
Expand Up @@ -28,7 +28,7 @@
expect_offense(<<~RUBY)
some_method #{open}
do_something

^{} Extra empty line detected at block body end.
#{close}
RUBY
Expand All @@ -43,7 +43,7 @@
it 'accepts block body starting with a line with spaces' do
expect_no_offenses(<<~RUBY)
some_method #{open}
#{trailing_whitespace}
do_something
#{close}
RUBY
Expand Down
Expand Up @@ -63,7 +63,7 @@ def some_method
expect_offense(<<~RUBY)
def Test.some_method
do_something

#{end_offense_annotation}
end
RUBY
Expand Down
Expand Up @@ -92,7 +92,7 @@

expect(corrected).to eq(<<~RUBY)
a, b,
c =
c =#{trailing_whitespace}
1,
2, 3
RUBY
Expand All @@ -118,7 +118,7 @@

expect(new_source).to eq(<<~RUBY)
a
.c =
.c =#{trailing_whitespace}
1,
2, 3
RUBY
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/layout/first_hash_element_line_break_spec.rb
Expand Up @@ -11,7 +11,7 @@
RUBY

expect_correction(<<~RUBY)
a = {
a = {#{trailing_whitespace}
a: 1,
b: 2 }
RUBY
Expand All @@ -25,7 +25,7 @@
RUBY

expect_correction(<<~RUBY)
method({
method({#{trailing_whitespace}
foo: 1,
bar: 2 })
RUBY
Expand Down
18 changes: 9 additions & 9 deletions spec/rubocop/cop/layout/multiline_block_layout_spec.rb
Expand Up @@ -11,7 +11,7 @@
RUBY

expect_correction(<<~RUBY)
test do
test do#{trailing_whitespace}
foo
end
RUBY
Expand All @@ -26,7 +26,7 @@
RUBY

expect_correction(<<~RUBY)
test {
test {#{trailing_whitespace}
foo
}
RUBY
Expand All @@ -41,7 +41,7 @@
RUBY

expect_correction(<<~RUBY)
test do |x|
test do |x|#{trailing_whitespace}
foo
end
RUBY
Expand All @@ -56,7 +56,7 @@
RUBY

expect_correction(<<~RUBY)
test { |x|
test { |x|#{trailing_whitespace}
foo
}
RUBY
Expand Down Expand Up @@ -150,7 +150,7 @@
RUBY

expect_correction(<<~RUBY)
-> (x) do
-> (x) do#{trailing_whitespace}
foo
bar
end
Expand All @@ -166,7 +166,7 @@
RUBY

expect_correction(<<~RUBY)
-> x do
-> x do#{trailing_whitespace}
foo
bar
end
Expand Down Expand Up @@ -226,7 +226,7 @@
RUBY

expect_correction(<<~RUBY)
test do |foo|
test do |foo|#{trailing_whitespace}
bar
test
end
Expand All @@ -243,7 +243,7 @@
RUBY

expect_correction(<<~RUBY)
x = -> (y) {
x = -> (y) {#{trailing_whitespace}
foo
bar
}
Expand All @@ -260,7 +260,7 @@
RUBY

expect_correction(<<~RUBY)
foo do |o|
foo do |o|#{trailing_whitespace}
(
bar
)
Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/lint/literal_in_interpolation_spec.rb
Expand Up @@ -202,12 +202,12 @@
^^^^^^ Literal interpolation detected.
RUBY

expect_correction(<<~'RUBY')
"this is
expect_correction(<<~RUBY)
"this is#{trailing_whitespace}
silly"
"this is
"this is#{trailing_whitespace}
silly"
"this is
"this is#{trailing_whitespace}
silly"
RUBY
end
Expand Down
16 changes: 8 additions & 8 deletions spec/rubocop/cop/lint/useless_method_definition_spec.rb
Expand Up @@ -18,7 +18,7 @@ def initialize(arg1, arg2)

expect_correction(<<~RUBY)
class Foo
#{trailing_whitespace}
end
RUBY
end
Expand Down Expand Up @@ -102,26 +102,26 @@ def useful_instance_method
do_something
end

#{trailing_whitespace}

#{trailing_whitespace}

def self.useful_class_method
do_something
end

#{trailing_whitespace}

#{trailing_whitespace}

class << self
def self.other_useful_class_method
do_something
end

#{trailing_whitespace}

#{trailing_whitespace}
end
end
RUBY
Expand Down Expand Up @@ -189,7 +189,7 @@ def initialize

expect_correction(<<~RUBY)
class Foo
#{trailing_whitespace}
end
RUBY
end
Expand Down
12 changes: 6 additions & 6 deletions spec/rubocop/cop/style/bisected_attr_accessor_spec.rb
Expand Up @@ -17,7 +17,7 @@ class Foo
expect_correction(<<~RUBY)
class Foo
attr_accessor :bar
#{trailing_whitespace}
other_macro :something
end
RUBY
Expand All @@ -37,7 +37,7 @@ class Foo
expect_correction(<<~RUBY)
class Foo
attr_accessor :bar
#{trailing_whitespace}
other_macro :something
end
RUBY
Expand All @@ -59,7 +59,7 @@ class Foo
class Foo
ATTRIBUTES = %i[foo bar]
attr_accessor *ATTRIBUTES
#{trailing_whitespace}
other_macro :something
end
RUBY
Expand Down Expand Up @@ -106,11 +106,11 @@ class Foo
expect_correction(<<~RUBY)
class Foo
attr_accessor :bar
#{trailing_whitespace}

private

#{trailing_whitespace}
attr_accessor :baz
end
RUBY
Expand Down Expand Up @@ -140,7 +140,7 @@ class Foo

class << self
attr_accessor :baz
#{trailing_whitespace}

private

Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/style/class_methods_definitions_spec.rb
Expand Up @@ -21,7 +21,7 @@ def three

expect_correction(<<~RUBY)
class A
#{trailing_whitespace}
def self.three
end

Expand Down Expand Up @@ -49,7 +49,7 @@ def two

expect_correction(<<~RUBY)
class A
#{trailing_whitespace}
# Multiline
# comment.
def self.two
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/style/line_end_concatenation_spec.rb
Expand Up @@ -192,7 +192,7 @@
# whitespace in this cop.
it 'autocorrects a + with trailing whitespace to \\' do
expect_offense(<<~RUBY)
top = "test" +
top = "test" +#{trailing_whitespace}
^ Use `\\` instead of `+` or `<<` to concatenate those strings.
"top"
RUBY
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/style/method_def_parentheses_spec.rb
Expand Up @@ -149,7 +149,7 @@ def func()
RUBY

expect_correction(<<~RUBY)
def func
def func#{trailing_whitespace}
end
RUBY
end
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/style/mixin_grouping_spec.rb
Expand Up @@ -206,7 +206,7 @@ class Foo
class Foo
prepend Qux, Baz, Bar
do_something_else
#{trailing_whitespace}
end
RUBY
end
Expand All @@ -229,7 +229,7 @@ class Foo
prepend Qux, Bar
Other.prepend Baz
do_something_else
#{trailing_whitespace}
end
RUBY
end
Expand Down
Expand Up @@ -189,7 +189,6 @@

context 'parentheses in multiline conditions are not allowed' do
let(:cop_config) { { 'AllowInMultilineConditions' => false } }
let(:trailing_whitespace) { ' ' }

it 'registers an offense for parentheses around multiline condition' do
expect_offense(<<~RUBY)
Expand Down