SublimeLinter / SublimeLinter-rubocop

SublimeLinter 3 plugin for Ruby, using rubocop.
MIT License
159 stars 40 forks source link

Shows wrong errors for HAML files #72

Open palexvs opened 4 years ago

palexvs commented 4 years ago

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
kaste commented 4 years ago

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?

palexvs commented 4 years ago

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 commented 4 years ago

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`)
...
kaste commented 4 years ago

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.

palexvs commented 4 years ago

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

kaste commented 4 years ago

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.

palexvs commented 4 years ago

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

kaste commented 4 years ago

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.

palexvs commented 4 years ago

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 commented 4 years ago

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"
    }
  }
}
eric-norcross commented 2 years ago

+1

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

kaste commented 2 years ago

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?