Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments are outdented incorrectly in script blocks #557

Open
2 tasks done
garraflavatra opened this issue Aug 4, 2023 · 1 comment
Open
2 tasks done

Comments are outdented incorrectly in script blocks #557

garraflavatra opened this issue Aug 4, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@garraflavatra
Copy link

garraflavatra commented Aug 4, 2023

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

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

2.32.4

What did you do?

I linted the following outdented code using the enclosed ESLint configuration.

<script>

function demo1() {
// This should be indented with 4 spaces
console.log('ok');
}

function demo2() {
// This should be indented with 4 spaces
}

function demo3() {
// This should be indented with 4 spaces
// Another line
console.log('ok');
}

function demo4() {
// This should be indented with 4 spaces
// Another line
}

demo1();
demo2();
demo3();
demo4();

</script>
{
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },
  "ignorePatterns": [
    "/expected.svelte",
    "/original.svelte"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:svelte/recommended"
  ],
  "plugins": [
    "svelte"
  ],
  "rules": {
    "svelte/indent": "error"
  }
}

What did you expect to happen?

I expected ESLint to indent the code correctly; in my opinion, that is:

<script>

  function demo1() {
    // This should be indented with 4 spaces
    console.log('ok');
  }

  function demo2() {
    // This should be indented with 4 spaces
  }

  function demo3() {
    // This should be indented with 4 spaces
    // Another line
    console.log('ok');
  }

  function demo4() {
    // This should be indented with 4 spaces
    // Another line
  }

  demo1();
  demo2();
  demo3();
  demo4();

</script>

What actually happened?

Fixing it by running eslint --fix changed it to the following:

<script>

  function demo1() {
    // This should be indented with 4 spaces
    console.log('ok');
  }

  function demo2() {
  // This should be indented with 4 spaces
  }

  function demo3() {
    // This should be indented with 4 spaces
    // Another line
    console.log('ok');
  }

  function demo4() {
  // This should be indented with 4 spaces
    // Another line
  }

  demo1();
  demo2();
  demo3();
  demo4();

</script>

Link to GitHub Repo with Minimal Reproducible Example

Repository: https://github.com/garraflavatra/svelte-eslint-comment-repro.

The original code is in original.svelte, the expected result is in expected.svelte, and the actual output is in actual.svelte. The .eslintrc.json file contains the used (minimal) configuration.

Additional comments

I tried looking for similar issues before creating this one, but found none.

Thank you for maintaining this plugin. I use it frequently, and this is the only issue I've encountered.

@thenbe
Copy link

thenbe commented Dec 11, 2023

In objects, this bug only happens on the first commented out key.

Here, it will complain only about the c key.

Repro

<script>
  /* eslint svelte/indent: "error" */
  const obj1 = {
    a: '',
    b: '',
    // c: '',
    // d: '',
    // e: '',
  }
</script>
  • EXPECTED: 'svelte/indent' should not complain about indent level.
  • ACTUAL: 'svelte/indent' has one complaint. It complains about the indent level for line number 6 (the line containing the c key). 'svelte/indent' wants line number 6 to be indented one level less than line number 5 and one level less than line number 7.

I tried creating a playground link but the indent rule doesn't work at all there (I disabled all rules except svelte/indent). But if you paste my snippet into the rule's example page you can reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants