SublimeLinter-rubocop icon indicating copy to clipboard operation
SublimeLinter-rubocop copied to clipboard

Shows wrong errors for HAML files

Open palexvs opened this issue 5 years ago • 12 comments

I created a simple correct test HAML file in my rails project test.html.haml:

%div
  - if true
    %b A
  - else
    %b B

but SublimeLinter highlights errors: image

test.html.haml:
 2:4  error  ruby:syntax error  unexpected end-of-input, expecting then or ';' or '\n'
 4:5  error  ruby:syntax error  unexpected else

My config file:

{
  "debug": true,
  "styles": [
    {
      "mark_style": "stippled_underline",
      "priority": 1,
      "scope": "source.ruby.rails keyword.control.ruby",
      "icon": "pointer",
      "types": [
        "warning"
      ]
    }
  ],
  "linters": {
    "rubocop": {
      "use_bundle_exec": true,
      "executable": "/Users/user/.rbenv/shims/rubocop"
    }
  }
}

If I run Rubocop manually I get no errors:

→ /Users/user/.rbenv/shims/rubocop test.html.haml 
Inspecting 0 files


0 files inspected, no offenses detected

palexvs avatar Jun 26 '20 20:06 palexvs

Well that looks like rubocop can lint haml files directly because that's what you do on the command line. Interestingly we explicitly exclude haml portions here in the plugin. Look here https://github.com/SublimeLinter/SublimeLinter-rubocop/blob/9bf25c766db9f61a7f554818c5d63430e4697f8f/linter.py#L27

You can change the selector in the settings though. Maybe "source.ruby, text.haml".

Do you think this is wrong here from the beginning, or has rubocop changed?

kaste avatar Jun 26 '20 21:06 kaste

You can change the selector in the settings though. Maybe "source.ruby, text.haml".

I tried to set source but it does not change anything:

{
...
  "linters": {
    "rubocop": {
...
      "source": "source.ruby, text.haml"
    }
  }
}

Do you think this is wrong here from the beginning, or has rubocop changed?

Tried to say, I have not used HAML for a while and just now tried to migrate on it but this issue blocks me

palexvs avatar Jun 26 '20 21:06 palexvs

You can change the selector in the settings though. Maybe "source.ruby, text.haml".

Sorry, my mistake. If I set selector it makes worsen:

{
...
  "linters": {
    "rubocop": {
...
      "selector": "source.ruby, text.haml"
    }
  }
}
show.html.haml:
  1:1   error    rubocop:E             Lint/Syntax: %div: unknown type of percent-literal (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
  1:6   error    rubocop:E             Lint/Syntax: unexpected token tSTRING_CONTENT (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
  2:3   error    rubocop:E             Lint/Syntax: %div: unknown type of percent-literal (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
...

palexvs avatar Jun 26 '20 22:06 palexvs

I reread your initial post. On the command line you tell it to lint the haml file but it reports 0 files inspected. So it basically ignores the file.

Probably worth it to look at the rubocop repo and even open an issue if this is somehow possible.

kaste avatar Jun 26 '20 22:06 kaste

In command-line Rubocop returns 0 errors but SublimeLinter returns 2

palexvs avatar Jun 26 '20 22:06 palexvs

Yeah sure, but it looks like it actually ignores the file. For that, you could set "exclude" to maybe "*.haml" in the settings.

The question is if we can somehow lint haml files.

kaste avatar Jun 26 '20 22:06 kaste

If Rubocop ignores this file then what has generated these errors ruby: error syntax error - unexpected end-of-input, expecting then or ';' or '\n'?

palexvs avatar Jun 26 '20 22:06 palexvs

The default selector explicitly extracts parts of the haml file, the Ruby parts, and sends them separately to rubocop. It does not send the whole file. I don't know if that makes a lot of sense but it's how it's done here. Maybe a selector "source.ruby - text.haml source.ruby" was actually intended although I'm not 100% sure about the selector semantics from top of my head.

kaste avatar Jun 27 '20 13:06 kaste

My current config SublimeLinter.sublime-settings:

{
  "debug": true,
  "styles": [
    {
      "mark_style": "stippled_underline",
      "priority": 1,
      "scope": "source.ruby.rails keyword.control.ruby",
      "icon": "pointer",
      "types": [
        "warning"
      ]
    }
  ],
  "linters": {
    "rubocop": {
      "use_bundle_exec": true,
      "executable": "/Users/palexvs/.rbenv/shims/rubocop",
      "selector": "source.ruby - text.haml source.ruby"
    }
  }
}

But still see image

I have installed SublimeLinter-haml-lint but see no changes.

palexvs avatar Jul 10 '20 06:07 palexvs

Adding "excludes": "*/*.html.haml" has haleped to suppress wrong errors from Ruby and Rubocop. But haml-lint does not work still

Current config:

{
  "debug": true,
  "styles": [
    {
      "mark_style": "stippled_underline",
      "priority": 1,
      "scope": "source.ruby.rails keyword.control.ruby",
      "icon": "pointer",
      "types": [
        "warning"
      ]
    }
  ],
  "linters": {
    "rubocop": {
      "use_bundle_exec": true,
      "executable": "/Users/palexvs/.rbenv/shims/rubocop",
      "selector": "source.ruby",
      "excludes": "*/*.html.haml"
    },
    "ruby": {
      "use_bundle_exec": true,
      "executable": "/Users/palexvs/.rbenv/shims/rubocop",
      "selector": "source.ruby",
      "excludes": "*/*.html.haml"
    }
  }
}

palexvs avatar Jul 10 '20 06:07 palexvs

+1

I tried this with @palexvs config above but am still seeing the errors

eric-norcross avatar Dec 03 '21 22:12 eric-norcross

Well, generally the selector we ship should already exclude haml files as it is source.ruby - text.html - text.haml. That is with the default Ruby HAML syntax shipping with Sublime Text which is the only thing I have.

@palexvs overrides this selector which is probably not what you want. Also the excludes value sets *.html.haml which is a bit idiosyncratic. Maybe you use a different file extension, like just *.haml?

kaste avatar Dec 03 '21 23:12 kaste