sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
296 stars 35 forks source link

`eslint-disable` comments in svelte html don't work with `eslint-plugin-eslint-comments` #328

Open DetachHead opened 1 year ago

DetachHead commented 1 year ago

Before You File a Bug Report Please Confirm You Have Done The Following...

What version of ESLint are you using?

8.30.0

What version of eslint-plugin-svelte are you using?

2.14.1

What did you do?

Configuration ```js module.exports = { root: true, parser: "@typescript-eslint/parser", "extends": ["plugin:svelte/recommended", "plugin:eslint-comments/recommended"], plugins: ["@typescript-eslint"], ignorePatterns: ["*.cjs"], settings: { 'import/parsers': { '@typescript-eslint/parser': [ '.ts', '.tsx', '.cts', '.mts' ], 'espree': [ '.js', 'jsx', '.cjs', '.mjs' ], } }, rules: { 'svelte/html-self-closing':'error', 'eslint-comments/require-description': 'error' }, overrides: [ { files: ["*.svelte"], parser: "svelte-eslint-parser", parserOptions: { parser: "@typescript-eslint/parser", }, }, ] }; ```
<script>
    // error: eslint-comments/require-description
    //eslint-disable-next-line
    console.log(1)
</script>

<!-- no error -->
<!-- eslint-disable-next-line -->
<input value="asdf">

What did you expect to happen?

eslint-comments/require-description error on the html comment

What actually happened?

no error on the html comment

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/DetachHead/eslint-plugin-svelte-issue/tree/d0eb35b9d72cd26928488f7bbe8cb0ee0f0d1222

Additional comments

i'm not sure whether this is an issue with this plugin or eslint-plugin-eslint-comments, so i'm raising it in both projects

https://github.com/mysticatea/eslint-plugin-eslint-comments/issues/74

ota-meshi commented 1 year ago

Thank you for posting the issue. eslint-disable HTML comments provided by eslint-plugin-svelte are completely different from eslint-disable comments provided by ESLint. https://sveltejs.github.io/eslint-plugin-svelte/rules/comment-directive/ Therefore, they are not compatible with eslint-plugin-eslint-comments. If we want to do similar checks, we need to add our own functionality to eslint-plugin-svelte, like the reportUnusedDisableDirectives option. https://sveltejs.github.io/eslint-plugin-svelte/rules/comment-directive/#options

OJFord commented 1 year ago

I'm not using esling-plugin-eslint-comments, but I'm finding that:

    <!-- eslint-disable-next-line svelte/no-at-html-tags -->
    {@html foobar}

doesn't work either. Is that expected? Is there another way to ignore rules from this plugin on specific lines?

(This is one particular case where I do want the tag, and it's guarded by a check that it's been stripped of anything potentially malicious.)

DetachHead commented 1 year ago

@OJFord that works for me. could you share some more info like your eslint config or maybe some of the surrounding code?

attisimon commented 1 year ago

Hello! Just a note that I have tried this out, with a different rule from @intlify and it seems to be working for me, the rule is disabled as expected:

<!-- eslint-disable-next-line @intlify/svelte/no-raw-text -->
<strong>Raw string</strong>