haml-lint icon indicating copy to clipboard operation
haml-lint copied to clipboard

Unable to disable the `Layout/CaseIndentation` RuboCop linter.

Open mockdeep opened this issue 1 year ago • 3 comments

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.

mockdeep avatar Jun 28 '23 17:06 mockdeep

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

MaxLap avatar Jun 28 '23 20:06 MaxLap

@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.

mockdeep avatar Jun 29 '23 02:06 mockdeep

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.

MaxLap avatar Jun 29 '23 03:06 MaxLap