sveltejs / eslint-plugin-svelte3

An ESLint plugin for Svelte v3 components.
MIT License
373 stars 43 forks source link

Template disable directive throws errors with `--report-needless-disables` #26

Closed maxmilton closed 5 years ago

maxmilton commented 5 years ago

Another issue related to ignored rules in svelte template, similar to https://github.com/sveltejs/eslint-plugin-svelte3/issues/22

When running ESLint from the CLI with the --report-needless-disables flag it throws a heap of errors:

  33  -9   error  Unused eslint-disable directive (no problems were reported from 'indent')
  33  -9   error  Unused eslint-disable directive (no problems were reported from 'no-unused-expressions')
  33  -9   error  Unused eslint-disable directive (no problems were reported from 'quotes')

This happens because svelte templates get /* eslint-disable indent, no-unused-expressions, quotes */ injected along in with the transformed code.

A possible fix is to use this instead:

/* eslint indent: "off", no-unused-expressions: "off", quotes: "off" */
Conduitry commented 5 years ago

What I ran into with /* eslint indent: 'off' etc */ was that the rules were actually disabled for the entire file, not just for the code below them. I confirmed in the ESLint Gitter that that is how they're intended to work. The benefit of the /* eslint-disable etc */ is that it only affects the code that follows, and we do want these linting rules in effect for the part in the <script> tag.

I'm not sure what can be done about this. Maybe I'd be able to purposefully put in code that would break those rules so the unused disables errors aren't thrown. Or maybe I'll have to split up the Svelte components into two processed files (one for the script blocks and one for the template expressions), and have those linted separately.

Conduitry commented 5 years ago

This should be fixed in 2.2.2.

maxmilton commented 5 years ago

Confirmed fixed in 2.2.2. Thank you.

I like that you've consolidated all the rule exception handling into one place. The plugin feels cleaner and less hacky :)