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

Shows wrong errors for HAML files #72

Open
palexvs opened this issue Jun 26, 2020 · 12 comments
Open

Shows wrong errors for HAML files #72

palexvs opened this issue Jun 26, 2020 · 12 comments

Comments

@palexvs
Copy link

palexvs commented Jun 26, 2020

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
Copy link
Contributor

kaste commented Jun 26, 2020

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

'selector': 'source.ruby - text.html - text.haml'

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
Copy link
Author

palexvs commented Jun 26, 2020

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
Copy link
Author

palexvs commented Jun 26, 2020

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
Copy link
Contributor

kaste commented Jun 26, 2020

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
Copy link
Author

palexvs commented Jun 26, 2020

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

@kaste
Copy link
Contributor

kaste commented Jun 26, 2020

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
Copy link
Author

palexvs commented Jun 26, 2020

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
Copy link
Contributor

kaste commented Jun 27, 2020

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
Copy link
Author

palexvs commented Jul 10, 2020

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
Copy link
Author

palexvs commented Jul 10, 2020

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
Copy link

eric-norcross commented Dec 3, 2021

+1

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

@kaste
Copy link
Contributor

kaste commented Dec 3, 2021

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?

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

No branches or pull requests

3 participants