SublimeLinter / SublimeLinter-eslint

This linter plugin for SublimeLinter provides an interface to ESLint
MIT License
864 stars 88 forks source link

Issue with eslint-plugin-svelte3 #284

Closed scottdotweb closed 4 years ago

scottdotweb commented 4 years ago

I've installed eslint-plugin-svelte3 and it works correctly on the following example code from the tutorial when I run eslint from the command line. However in Sublime Text I get ParseError - Unexpected token at the start of line 7 (the first letter of const is highlighted).

<script>
    import { onMount } from 'svelte';

    let photos = [];

    onMount(async () => {
        const res = await fetch('https://jsonplaceholder.typicode.com/photos?_limit=20');
        photos = await res.json();
    })
</script>

Using the Show Scope Name command with the cursor at that point results in source.js which I thought meant would trigger JavaScript linting. Am I doing something wrong? Thank you.

kaste commented 4 years ago

I guess the svelte plugin allows eslint to handle the whole file not just its js parts.

By default though, this adapter here only sends the js parts to eslint. I don't know if there is a special Sublime syntax for svelte or if this is just HTML after all, anyway to send the whole buffer/file place the cursor at the first char and run Show Scope from here, then fill in usually the first scope as selector just as described for Vue in the Readme.

Let us know if this works out. A PR for the Readme if yes would be also dope.

scottdotweb commented 4 years ago

Hey, apologies for taking so long to get back to you. The scope at the very first character of the file is text.html and that seems to have done the trick! I'll certainly look at making a PR.

kaste commented 4 years ago

Maybe we can do this automatically 🤔 Since we read the package.json anyway, can't we just look for eslint-plugin-svelte3 in the dependencies or devDependencies section, and allow a different selector if found.

We would need to maintain a hopefully short list of selectors eslint can support with plugins. It could be possible if they don't overlap in weird ways. E.g. if one selector matches subsets of a broader selector it gets messy but if the plugins select whole files ... it is maybe possible or even trivial.

scottdotweb commented 4 years ago

That sounds cool. I made a note in the content of the PR that I just submitted that this situation is correct for the Naomi syntax highlighter set to "HTML 5" - using "JavaScript" it doesn't handle Svelte correctly. So that may complicate matters.