Skip to content

eslint --fix incorrectly changes the wrong line on each block with comment on separate line #327

Closed
sveltejs/svelte-eslint-parser
#262
@DetachHead

Description

@DetachHead

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

  • I have tried restarting my IDE and the issue persists.
  • 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",
  plugins: ["@typescript-eslint"],
  ignorePatterns: ["*.cjs"],
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': [ '.ts', '.tsx', '.cts', '.mts' ],
      'espree': [ '.js', 'jsx', '.cjs', '.mjs' ],
    }
  },
  rules: {
    "spaced-comment": "error"
  },
  overrides: [
    {
      files: ["*.svelte"],
      parser: "svelte-eslint-parser",
      parserOptions: {
        parser: "@typescript-eslint/parser",
      },
    },
  ]
};
{#each f(
//asdf
d) as k}<Csdf></Csdf>{/each}
eslint . --fix

What did you expect to happen?

space added on line 2 after the //

What actually happened?

space added on line 1 after the {#, causing a syntax error:

{# each f(
//asdf
d) as k}<Csdf></Csdf>{/each}
> eslint . --fix

C:\projects\asdf\src\main.svelte
  1:2  error  Parsing error: Expected if, each or await

✖ 1 problem (1 error, 0 warnings)

Link to GitHub Repo with Minimal Reproducible Example

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

also same issue but different rule: https://ota-meshi.github.io/eslint-plugin-svelte/playground/#eJyrVkrOT0lVslKqVk5NTM5QSNOIydPXTyxOSYvJS9FUSCxWyK61cQZy9e2q9UEqapVqAbyyES0=

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions