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

Disable rule inline over multiple lines #234

Open
Blacksmoke16 opened this issue May 8, 2021 · 5 comments
Open

Disable rule inline over multiple lines #234

Blacksmoke16 opened this issue May 8, 2021 · 5 comments
Labels

Comments

@Blacksmoke16
Copy link
Contributor

Blacksmoke16 commented May 8, 2021

Related to #233.

Because # ameba:disable only disablse the rule on the next line, I'm not able to apply it to the whole heredoc to get linting to pass. I also can't add it at the end of the line as that makes the spec fail due to expecting the actual string to contain # ameba:disable Layout/TrailingWhitespace.

It would be a nice feature to be able to disable a rule over a multi line range. E.g.

# ameba:disable Layout/TrailingWhitespace
output = <<-OUTPUT

                
  Hello there!. 
                


OUTPUT
# ameba:enable Layout/TrailingWhitespace
@straight-shoota
Copy link
Contributor

Alternatively / in addition, it might be useful if a non-ranged disable would affect an entire expression, even if it spans over multiple lines.

@straight-shoota
Copy link
Contributor

straight-shoota commented Apr 8, 2022

Instead of changing the semantics of ameba:disable as in #265, what about keeping it that way, and add a different name for pragmas that span multiple lines?

# ameba:disable_block Layout/TrailingWhitespace
output = <<-OUTPUT

                
  Hello there!. 
                


OUTPUT
# ameba:enable_block Layout/TrailingWhitespace

This would avoid a breaking change for ameba:disable. And I think it makes sense to use the shorter name for single instances, and a longer name for spanning multiple lines.

@straight-shoota
Copy link
Contributor

I also doubt whether there's an actual need to have two different pragmas for applying to the same line (ameba:disable_line in #265) or the following (ameba:disable_next_line). It could just be a single name (ameba:disable per previous comment) which applies to the same name if it's a trailing comment and the next line if the line is empty except for the comment (and leading white space). It's not as explicit, but the semantics seem pretty natural to me. And there should be no relevant use case where an explicit disambiguation would be necessary.

@straight-shoota
Copy link
Contributor

Btw. that's exactly what rubocop does. I would just do it exactly that way.
https://docs.rubocop.org/rubocop/1.27/configuration.html#disabling-cops-within-source-code

@veelenga
Copy link
Member

veelenga commented Apr 22, 2022

There are long-running uncontinuous discussions on GitHub on how to improve what currently rubocop does in terms of cop disabling. I don't think it is a silver bullet.

However, I would appreciate any help on this. Thanks

@Sija Sija added the feature label Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants