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

Not compatible with eslint-plugin-simple-import-sort #199

Closed
2 tasks done
hgiesel opened this issue Jul 26, 2022 · 7 comments
Closed
2 tasks done

Not compatible with eslint-plugin-simple-import-sort #199

hgiesel opened this issue Jul 26, 2022 · 7 comments

Comments

@hgiesel
Copy link

hgiesel commented Jul 26, 2022

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

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

2.2.0

What did you do?

You need a Svelte file with unordered imports in its script component, then execute eslint --fix.

What did you expect to happen?

Would apply the simple-import-sort rules, and sort the imports.

What actually happened?

It reported no errors

Link to Minimal Reproducible Example

// .eslintrc.js
module.exports = {
    extends: "eslint:recommended",
    parser: "@typescript-eslint/parser",
    parserOptions: {
        extraFileExtensions: [".svelte"],
    },
    plugins: [
        "svelte",
        "simple-import-sort",
        "@typescript-eslint",
    ],
    rules: {
        "no-unused-vars": "off",
        "no-undef": "off",
        "no-redeclare": "off",
        "no-inner-declarations": "off",
        "no-self-assign": "off",
    },
    overrides: [
        {
            files: "**/*.svelte",
            parser: "svelte-eslint-parser",
            parserOptions: {
                parser: "@typescript-eslint/parser",
            },
            rules: {
                "simple-import-sort/imports": "warn",
                "simple-import-sort/exports": "warn",
            },
        },
    ],
    env: { browser: true },
    ignorePatterns: ["backend_proto.d.ts", "*.svelte.d.ts"],
    globals: {
        globalThis: false,
        NodeListOf: false,
    },
};

Additional comments

No response

@ota-meshi ota-meshi added the needs repro Need a repository that can reproduce the problem label Jul 26, 2022
@ota-meshi
Copy link
Member

Please provide a github repository that can reproduce the problem.

Why Reproductions are Required

@ToP29
Copy link

ToP29 commented Nov 3, 2022

Same issue here. After adding this plugin, eslint-plugin-simple-import-sort has stopped working.
Any news @hgiesel ? Did you managed to make it work?

@baseballyama
Copy link
Member

@ToP29 I'm happy if you provide a REPL.

@ToP29
Copy link

ToP29 commented Nov 3, 2022

here is repro
you can see for example in file src\routes\+page.svelte that import are not sorted
if you use config from .eslintrc.json - working-sort and run npm run lint then it will sort them. working example uses eslint-plugin-svelte3

@baseballyama
Copy link
Member

@ToP29

Thank you for your REPL.
But you can not use both eslint-plugin-svelte3 and this plugin at the same time.

See: https://github.com/ota-meshi/eslint-plugin-svelte#-attention

@ToP29
Copy link

ToP29 commented Nov 3, 2022

Yea i know, i just created two eslint confings, so you can see it working and broken. if you check .eslintrc.json then you will see there is no eslint-plugin-svelte3 used

@ota-meshi
Copy link
Member

Thank you for sharing the repository.

eslint-plugin-simple-import-sort doesn't seem to work as you say.
I think this is because eslint-plugin-simple-import-sort only checks import nodes of root level node (Program node).
The result of our parser is that the SvelteScriptElement node has import nodes.

I recommend using import/order instead.
https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md

Or ask eslint-plugin-simple-import-sort to handle imports with anything other than the root node.
Because I have the same problem with typescript.
import/order handles the following typescript properly, but eslint-plugin-simple-import-sort does not.

declare module 'my-module' {
    import type { ParsedPath } from 'path';
    import type { CopyOptions } from 'fs';
}

https://github.com/import-js/eslint-plugin-import/blob/c3d14cb920bdc6d277134973d37364db22c3a8b8/tests/src/rules/order.js#L3123-L3140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants