eslint-plugin-svelte icon indicating copy to clipboard operation
eslint-plugin-svelte copied to clipboard

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

Open DetachHead opened this issue 3 years ago • 4 comments

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

  • [X] I have tried restarting my IDE and the issue persists.
  • [X] I have updated to the latest version of the packages.

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

DetachHead avatar Dec 19 '22 00:12 DetachHead

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

ota-meshi avatar Dec 19 '22 14:12 ota-meshi

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.)

OJFord avatar Feb 05 '23 21:02 OJFord

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

DetachHead avatar Feb 06 '23 00:02 DetachHead

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>

attisimon avatar Apr 24 '23 14:04 attisimon