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

Add new Layout/EmptyLinesAroundArguments Cop #5074

Closed
garettarrowood opened this issue Nov 19, 2017 · 4 comments
Closed

Add new Layout/EmptyLinesAroundArguments Cop #5074

garettarrowood opened this issue Nov 19, 2017 · 4 comments

Comments

@garettarrowood
Copy link
Contributor

garettarrowood commented Nov 19, 2017

While applying a fix for issue #5052 in PR #5066 , it was discovered that the autocorrection for Style/BracesArondHashParameters is a little aggressive. When I applied changes to stop it from removing legitimate \ns, it created snippets similar to the example below.

Adding this EmptyLine Cop would resolve this scenario and still allow Style/BracesArondHashParameters autocorrection to be improved to cleaner results. The cleaner results I refer to our found in this example, this example and this example.


Desired behavior

For this code snippet register a Stlye/EmptyLinesAroundArguments offense.

foo(

  bar: 1

)

Then, autocorrect that snippet to:

foo(
  bar: 1
)

Actual behavior

Above snippet registers no offense.

Steps to reproduce the problem

See above.

RuboCop version

0.51.0 (using Parser 2.4.0.0, running on ruby 2.3.3 x86_64-darwin15)
@Drenmi
Copy link
Collaborator

Drenmi commented Nov 19, 2017

This cop should go in the Layout department, not Style. 🙂

@garettarrowood garettarrowood changed the title Add new Style/EmptyLinesAroundArguments Cop Add new Layout/EmptyLinesAroundArguments Cop Nov 19, 2017
garettarrowood added a commit to garettarrowood/rubocop that referenced this issue Dec 2, 2017
@bbatsov bbatsov closed this as completed in 7bf6119 Dec 7, 2017
@deepj
Copy link
Contributor

deepj commented Dec 13, 2017

Hm, it seems this doesn't work properly. I have something like

# frozen_string_literal: true

require 'csv'
require_relative '../../importer/base'

module Labels
  module Csv
    class Import < Importer::Base

And that issue occurs on

app/services/labels/csv/import.rb:4:1: C: Layout/EmptyLinesAroundArguments: Empty line detected around arguments.
require_relative '../../importer/base'
^
app/services/labels/csv/import.rb:7:1: C: Layout/EmptyLinesAroundArguments: Empty line detected around arguments.
  module Csv

I guess this is not expected behaviour...

@fotinakis
Copy link

fotinakis commented Dec 15, 2017

We also got this cop triggered on a require line. (and the require line had an underscore in it, similar to the above)

@zhisme
Copy link

zhisme commented Jan 21, 2018

I also had this cop offense in this example.

# bad
config.enabled = Rails.env.in?(%w[production staging])

C: Layout/EmptyLinesAroundArguments: Empty line detected around arguments.

# good
config.enabled = Rails.env.in?(
    %w[production staging]
    )

no offense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants