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

Set Layout/First_#{}_LineBreak lints as disabled in rubocop config #536

Conversation

maddieholtzer
Copy link
Contributor

@maddieholtzer maddieholtzer commented Dec 31, 2024

What

Set 3 of the 4 Layout/First_#{}_LineBreak lints as enabled: false in config/forced_rubocop_config.yml

Leaving 1 of the 4 as is:

Why

These lints run into a conflict with MultilinePipe

One example of this is that the autocorrect changes:

= link_to('View button styleguide',
  style_path('button'),
  target: '_blank',
  rel: 'noopener noreferrer')

to:

= link_to( |
  'View button styleguide', |
  style_path('button'), |
  target: '_blank', |
  rel: 'noopener noreferrer', |
  ) |

It is quite possible that this is showcasing a lack of understanding I have of haml syntax/best practice but I wasn't able to figure out a workaround that can satisfy both lints.

I left out Layout/FirstMethodParameterLineBreak because in order to trigger this (which I couldn't figure out how to do without triggering a syntax error) you are probably doing something you shouldn't in the first place (defining a method inside a haml file is something that comes across to me as bad practice) and an additional safeguard against this is probably a good thing.

**What**

Set 3 of the 4 `Layout/First_#{}_LineBreak` lints as `enabled: false` in
`config/forced_rubocop_config.yml`

- [Layout/FirstArrayElementLineBreak](https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirstarrayelementlinebreak)
- [Layout/FirstHashElementLineBreak](https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirsthashelementlinebreak)
- [Layout/FirstMethodArgumentLineBreak](https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirstmethodargumentlinebreak)

Leaving 1 of the 4 as is:

- [Layout/FirstMethodParameterLineBreak](https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirstmethodparameterlinebreak)

**Why**

These lints run into a conflict with
[MultilinePipe](https://github.com/sds/haml-lint/blob/main/lib/haml_lint/linter/README.md#multilinepipe)

One example of this is that the autocorrect changes:

```
= link_to('View button styleguide',
  style_path('button'),
  target: '_blank',
  rel: 'noopener noreferrer')
```

to:

```
= link_to( |
  'View button styleguide', |
  style_path('button'), |
  target: '_blank', |
  rel: 'noopener noreferrer', |
  ) |
```

It is quite possible that this is showcasing a lack of understanding I have of haml syntax/best
practice but I wasn't able to figure out a workaround that can satisfy both lints.

I left out
[Layout/FirstMethodParameterLineBreak](https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirstmethodparameterlinebreak)
because in order to trigger this (which I couldn't figure out how to do without triggering a syntax
error) you are probably doing something you shouldn't in the first place (defining a method inside a
haml file is something that comes across to me as [bad
practice](https://stackoverflow.com/questions/52117429/haml-how-to-define-a-method)) and an
additional safeguard against this is probably a good thing.
@sds
Copy link
Owner

sds commented Jan 2, 2025

Going to defer to @MaxLap on whether this is the right approach, as the forced_rubocop_config.yml was introduced by them.

@MaxLap
Copy link
Contributor

MaxLap commented Jan 3, 2025

Those basically go against what we would consider good haml syntax. So I think it make sense to add this.

@maddieholtzer
Copy link
Contributor Author

maddieholtzer commented Jan 3, 2025

I've thought through this a tiny bit more and realized that this doesn't apply within :ruby blocks where you can satisfy these lints without running into any issues with MultilinePipe or syntax issues. I'm not sure if that really changes things here though in terms of best path forward as I assume? this would require somehow specifying certain rubocop lints as only applying within :ruby blocks which I'm not sure is something people want to add to the project.

@MaxLap
Copy link
Contributor

MaxLap commented Jan 3, 2025

I've tried using rubocop:disable comments in the past. It caused issues for users that use Style/DisableCopsWithinSourceCodeDirective, see #406. So that's not an option.

I don't see a clean way to handle both styling at the same time. So I guess I would disable the cops. The main issue is if people used to have it active, they will see lots of changes, which is annoying. But I think those changes would be for the better?

@maddieholtzer
Copy link
Contributor Author

That is also a concern for me. I'd be curious to know how/if people really have these active in Haml right now unless they've disabled MultilinePipe or their Haml files are basically just entirely :ruby blocks. I could very well be missing something, though.

@sds sds merged commit 5e594e7 into sds:main Jan 3, 2025
35 checks passed
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

Successfully merging this pull request may close these issues.

3 participants