From f62085f1c18924ea8e5710f08cced15cacf4b611 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Sat, 14 Nov 2020 12:03:51 +0100 Subject: [PATCH] Consistent multi-line string concatenation I have suggested some rules for consistent formatting of these strings in https://github.com/rubocop-hq/rubocop/issues/6420, but it seems to be too complicated to have RuboCop enforce them. --- lib/rubocop/cop/rspec/around_block.rb | 2 +- lib/rubocop/cop/rspec/before_after_all.rb | 6 +++--- lib/rubocop/cop/rspec/describe_class.rb | 2 +- lib/rubocop/cop/rspec/describe_method.rb | 2 +- lib/rubocop/cop/rspec/expect_output.rb | 2 +- lib/rubocop/cop/rspec/instance_spy.rb | 2 +- lib/rubocop/cop/rspec/it_behaves_like.rb | 2 +- lib/rubocop/cop/rspec/iterated_expectation.rb | 2 +- lib/rubocop/cop/rspec/message_spies.rb | 4 ++-- lib/rubocop/cop/rspec/multiple_describes.rb | 3 +-- lib/rubocop/cop/rspec/scattered_setup.rb | 2 +- lib/rubocop/cop/rspec/shared_context.rb | 7 ++----- .../cop/rspec/single_argument_message_chain.rb | 2 +- spec/rubocop/cop/rspec/before_after_all_spec.rb | 6 +++--- .../capybara/current_path_expectation_spec.rb | 14 +++++++------- spec/rubocop/cop/rspec/example_wording_spec.rb | 4 ++-- 16 files changed, 29 insertions(+), 33 deletions(-) diff --git a/lib/rubocop/cop/rspec/around_block.rb b/lib/rubocop/cop/rspec/around_block.rb index b3a2148e0..000e43bc8 100644 --- a/lib/rubocop/cop/rspec/around_block.rb +++ b/lib/rubocop/cop/rspec/around_block.rb @@ -27,7 +27,7 @@ module RSpec # end class AroundBlock < Base MSG_NO_ARG = 'Test object should be passed to around block.' - MSG_UNUSED_ARG = 'You should call `%s.call` '\ + MSG_UNUSED_ARG = 'You should call `%s.call` ' \ 'or `%s.run`.' def_node_matcher :hook, <<-PATTERN diff --git a/lib/rubocop/cop/rspec/before_after_all.rb b/lib/rubocop/cop/rspec/before_after_all.rb index 9a9d894da..7813b3d9d 100644 --- a/lib/rubocop/cop/rspec/before_after_all.rb +++ b/lib/rubocop/cop/rspec/before_after_all.rb @@ -24,9 +24,9 @@ module RSpec # after(:each) { Widget.delete_all } # end class BeforeAfterAll < Base - MSG = 'Beware of using `%s` as it may cause state to leak '\ - 'between tests. If you are using `rspec-rails`, and '\ - '`use_transactional_fixtures` is enabled, then records created '\ + MSG = 'Beware of using `%s` as it may cause state to leak ' \ + 'between tests. If you are using `rspec-rails`, and ' \ + '`use_transactional_fixtures` is enabled, then records created ' \ 'in `%s` are not automatically rolled back.' def_node_matcher :before_or_after_all, <<-PATTERN diff --git a/lib/rubocop/cop/rspec/describe_class.rb b/lib/rubocop/cop/rspec/describe_class.rb index 45bb737c4..96bb475b8 100644 --- a/lib/rubocop/cop/rspec/describe_class.rb +++ b/lib/rubocop/cop/rspec/describe_class.rb @@ -37,7 +37,7 @@ module RSpec class DescribeClass < Base include TopLevelGroup - MSG = 'The first argument to describe should be '\ + MSG = 'The first argument to describe should be ' \ 'the class or module being tested.' def_node_matcher :example_group_with_ignored_metadata?, <<~PATTERN diff --git a/lib/rubocop/cop/rspec/describe_method.rb b/lib/rubocop/cop/rspec/describe_method.rb index 2ff64e760..71395aaf0 100644 --- a/lib/rubocop/cop/rspec/describe_method.rb +++ b/lib/rubocop/cop/rspec/describe_method.rb @@ -19,7 +19,7 @@ module RSpec class DescribeMethod < Base include TopLevelGroup - MSG = 'The second argument to describe should be the method '\ + MSG = 'The second argument to describe should be the method ' \ "being tested. '#instance' or '.class'." def_node_matcher :second_argument, <<~PATTERN diff --git a/lib/rubocop/cop/rspec/expect_output.rb b/lib/rubocop/cop/rspec/expect_output.rb index 6c8c92938..96be00184 100644 --- a/lib/rubocop/cop/rspec/expect_output.rb +++ b/lib/rubocop/cop/rspec/expect_output.rb @@ -15,7 +15,7 @@ module RSpec # # good # expect { my_app.print_report }.to output('Hello World').to_stdout class ExpectOutput < Base - MSG = 'Use `expect { ... }.to output(...).to_%s` '\ + MSG = 'Use `expect { ... }.to output(...).to_%s` ' \ 'instead of mutating $%s.' def on_gvasgn(node) diff --git a/lib/rubocop/cop/rspec/instance_spy.rb b/lib/rubocop/cop/rspec/instance_spy.rb index bda0f2ad9..2e76fc24e 100644 --- a/lib/rubocop/cop/rspec/instance_spy.rb +++ b/lib/rubocop/cop/rspec/instance_spy.rb @@ -21,7 +21,7 @@ module RSpec class InstanceSpy < Base extend AutoCorrector - MSG = 'Use `instance_spy` when you check your double '\ + MSG = 'Use `instance_spy` when you check your double ' \ 'with `have_received`.' def_node_search :null_double, <<-PATTERN diff --git a/lib/rubocop/cop/rspec/it_behaves_like.rb b/lib/rubocop/cop/rspec/it_behaves_like.rb index 28bf71123..ceca22406 100644 --- a/lib/rubocop/cop/rspec/it_behaves_like.rb +++ b/lib/rubocop/cop/rspec/it_behaves_like.rb @@ -22,7 +22,7 @@ class ItBehavesLike < Base extend AutoCorrector include ConfigurableEnforcedStyle - MSG = 'Prefer `%s` over `%s` when including '\ + MSG = 'Prefer `%s` over `%s` when including ' \ 'examples in a nested context.' def_node_matcher :example_inclusion_offense, '(send _ % ...)' diff --git a/lib/rubocop/cop/rspec/iterated_expectation.rb b/lib/rubocop/cop/rspec/iterated_expectation.rb index 18be6248a..4d99d9920 100644 --- a/lib/rubocop/cop/rspec/iterated_expectation.rb +++ b/lib/rubocop/cop/rspec/iterated_expectation.rb @@ -17,7 +17,7 @@ module RSpec # end class IteratedExpectation < Base MSG = 'Prefer using the `all` matcher instead ' \ - 'of iterating over an array.' + 'of iterating over an array.' def_node_matcher :each?, <<-PATTERN (block diff --git a/lib/rubocop/cop/rspec/message_spies.rb b/lib/rubocop/cop/rspec/message_spies.rb index fa30d09ee..bfbcc73d3 100644 --- a/lib/rubocop/cop/rspec/message_spies.rb +++ b/lib/rubocop/cop/rspec/message_spies.rb @@ -29,8 +29,8 @@ class MessageSpies < Base MSG_RECEIVE = 'Prefer `receive` for setting message expectations.' - MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message '\ - 'expectations. Setup `%s` as a spy using '\ + MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message ' \ + 'expectations. Setup `%s` as a spy using ' \ '`allow` or `instance_spy`.' SUPPORTED_STYLES = %w[have_received receive].freeze diff --git a/lib/rubocop/cop/rspec/multiple_describes.rb b/lib/rubocop/cop/rspec/multiple_describes.rb index 14c535f45..20662eeba 100644 --- a/lib/rubocop/cop/rspec/multiple_describes.rb +++ b/lib/rubocop/cop/rspec/multiple_describes.rb @@ -25,8 +25,7 @@ module RSpec class MultipleDescribes < Base include TopLevelGroup - MSG = 'Do not use multiple top-level example groups - '\ - 'try to nest them.' + MSG = 'Do not use multiple top-level example groups - try to nest them.' def on_top_level_group(node) top_level_example_groups = diff --git a/lib/rubocop/cop/rspec/scattered_setup.rb b/lib/rubocop/cop/rspec/scattered_setup.rb index 90eea5f24..6d3dbdfb8 100644 --- a/lib/rubocop/cop/rspec/scattered_setup.rb +++ b/lib/rubocop/cop/rspec/scattered_setup.rb @@ -23,7 +23,7 @@ module RSpec # end # class ScatteredSetup < Base - MSG = 'Do not define multiple `%s` hooks in the same '\ + MSG = 'Do not define multiple `%s` hooks in the same ' \ 'example group (also defined on %s).' def on_block(node) diff --git a/lib/rubocop/cop/rspec/shared_context.rb b/lib/rubocop/cop/rspec/shared_context.rb index c15f8a276..c73cecafc 100644 --- a/lib/rubocop/cop/rspec/shared_context.rb +++ b/lib/rubocop/cop/rspec/shared_context.rb @@ -53,11 +53,8 @@ module RSpec class SharedContext < Base extend AutoCorrector - MSG_EXAMPLES = "Use `shared_examples` when you don't "\ - 'define context.' - - MSG_CONTEXT = "Use `shared_context` when you don't "\ - 'define examples.' + MSG_EXAMPLES = "Use `shared_examples` when you don't define context." + MSG_CONTEXT = "Use `shared_context` when you don't define examples." def_node_search :examples?, send_pattern('{#Includes.examples #Examples.all}') diff --git a/lib/rubocop/cop/rspec/single_argument_message_chain.rb b/lib/rubocop/cop/rspec/single_argument_message_chain.rb index 77e8aef27..7e1903b5d 100644 --- a/lib/rubocop/cop/rspec/single_argument_message_chain.rb +++ b/lib/rubocop/cop/rspec/single_argument_message_chain.rb @@ -19,7 +19,7 @@ module RSpec class SingleArgumentMessageChain < Base extend AutoCorrector - MSG = 'Use `%s` instead of calling '\ + MSG = 'Use `%s` instead of calling ' \ '`%s` with a single argument.' def_node_matcher :message_chain, <<-PATTERN diff --git a/spec/rubocop/cop/rspec/before_after_all_spec.rb b/spec/rubocop/cop/rspec/before_after_all_spec.rb index 41618109b..31c2d5cfe 100644 --- a/spec/rubocop/cop/rspec/before_after_all_spec.rb +++ b/spec/rubocop/cop/rspec/before_after_all_spec.rb @@ -2,9 +2,9 @@ RSpec.describe RuboCop::Cop::RSpec::BeforeAfterAll do def message(hook) - "Beware of using `#{hook}` as it may cause state to leak between tests. "\ - 'If you are using `rspec-rails`, and `use_transactional_fixtures` is '\ - "enabled, then records created in `#{hook}` are not automatically rolled "\ + "Beware of using `#{hook}` as it may cause state to leak between tests. " \ + 'If you are using `rspec-rails`, and `use_transactional_fixtures` is ' \ + "enabled, then records created in `#{hook}` are not automatically rolled " \ 'back.' end diff --git a/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb b/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb index 619cf2e9a..f2c1a88c8 100644 --- a/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +++ b/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb @@ -29,37 +29,37 @@ include_examples 'autocorrect', 'expect(current_path).to eq expected_path', - 'expect(page).to have_current_path expected_path, '\ + 'expect(page).to have_current_path expected_path, ' \ 'ignore_query: true' include_examples 'autocorrect', 'expect(current_path).to eq(expected_path)', - 'expect(page).to have_current_path(expected_path, '\ + 'expect(page).to have_current_path(expected_path, ' \ 'ignore_query: true)' include_examples 'autocorrect', 'expect(current_path).to(eq(expected_path))', - 'expect(page).to(have_current_path(expected_path, '\ + 'expect(page).to(have_current_path(expected_path, ' \ 'ignore_query: true))' include_examples 'autocorrect', 'expect(current_path).to eq(expected_path(f: :b))', - 'expect(page).to have_current_path(expected_path(f: :b), '\ + 'expect(page).to have_current_path(expected_path(f: :b), ' \ 'ignore_query: true)' include_examples 'autocorrect', 'expect(page.current_path).to eq(foo(bar).path)', - 'expect(page).to have_current_path(foo(bar).path, '\ + 'expect(page).to have_current_path(foo(bar).path, ' \ 'ignore_query: true)' include_examples 'autocorrect', 'expect(current_path).not_to eq expected_path', - 'expect(page).to have_no_current_path expected_path, '\ + 'expect(page).to have_no_current_path expected_path, ' \ 'ignore_query: true' include_examples 'autocorrect', 'expect(current_path).to_not eq expected_path', - 'expect(page).to have_no_current_path expected_path, '\ + 'expect(page).to have_no_current_path expected_path, ' \ 'ignore_query: true' include_examples 'autocorrect', diff --git a/spec/rubocop/cop/rspec/example_wording_spec.rb b/spec/rubocop/cop/rspec/example_wording_spec.rb index 42dcfe1ee..7112da1eb 100644 --- a/spec/rubocop/cop/rspec/example_wording_spec.rb +++ b/spec/rubocop/cop/rspec/example_wording_spec.rb @@ -152,7 +152,7 @@ it 'flags \-separated multiline strings' do expect_offense(<<-RUBY) - it 'should do something '\\ + it 'should do something ' \\ ^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests. 'and correctly fix' do end @@ -166,7 +166,7 @@ it 'flags \-separated multiline interpolated strings' do expect_offense(<<-'RUBY') - it "should do something "\ + it 'should do something ' \ ^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests. "with #{object}" do end