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

Unable to disable the Layout/CaseIndentation RuboCop linter. #407

Open
mockdeep opened this issue Jun 28, 2023 · 3 comments
Open

Unable to disable the Layout/CaseIndentation RuboCop linter. #407

mockdeep opened this issue Jun 28, 2023 · 3 comments

Comments

@mockdeep
Copy link
Contributor

For some reason after upgrading to version 0.46.0, we're unable to disable the Layout/CaseIndentation lint. We get a lot of reports, but when I add it to the our custom RuboCop overrides, it won't disable it. That appears to be the only rule that won't disable, though. Others work as intended.

@MaxLap
Copy link
Contributor

MaxLap commented Jun 28, 2023

Because of how the new Rubocop system works, some cops are forced in some specific configuration.

This is needed because the way the system works, haml-lint basically converts the HAML to valid ruby, runs rubocop, and then transfers the fixes. Some cops do transformation that ruin the expected structure of the code. CaseIndentation is one such example.

I'm curious, are the errors you mention in regular haml (with - and =) or in a :ruby filter?

You can see all of the forced rubocop configurations, as well as explanations, here:
https://github.com/sds/haml-lint/blob/main/config/forced_rubocop_config.yml

@mockdeep
Copy link
Contributor Author

@MaxLap the problem is that we have nested case statements. E.g.:

    - case sorting.direction
      - when 'asc'
        = icon('caret-up', aria: { label: 'ascending order' }, role: 'img')
      - when 'desc'
        = icon('caret-down', aria: { label: 'descending order' }, role: 'img')

I'm going to try unindenting the blocks, but I'm a little concerned about ambiguity with following blocks:

- case something
- when 'foo'
- when 'bar'
- unless something_else # this looks like it's part of the `case` even though it's completely separate.

@MaxLap
Copy link
Contributor

MaxLap commented Jun 29, 2023

I understand your concern. The effect is less pronounced when you have content in your when, such as:

- case something
- when 'foo'
  abc
- when 'bar'
  def
- unless something_els

The main reason we need to use the non-indented configuration is that HAML fails on this:

- case 1
  - when 1
  - when 2
    foo

For some reason, it inserts an extra end in the generated Ruby code, which is a SyntaxError. So in "indented when" mode, auto-correction could lead to this "valid" HAML that HAML fails to process, which I want to avoid as much as possible.

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

No branches or pull requests

3 participants