un-ts / eslint-plugin-import-x

`eslint-plugin-import-x` is a fork of `eslint-plugin-import` that aims to provide a more performant and more lightweight version of the original plugin.
https://npm.im/eslint-plugin-import-x
MIT License
419 stars 21 forks source link

`no-duplicates` false positive without `prefer-inline` #167

Open hyoban opened 1 week ago

hyoban commented 1 week ago
import type * as React from "react"
import type { JSX, PropsWithChildren, ReactNode } from "react"
ocavue commented 1 week ago

Another example:

Given the following file:

// test.ts

import { onMount } from 'svelte';
import { readable, type Readable } from 'svelte/store';

export function main() {
    console.log(onMount);
    console.log(readable);
    let variable: Readable<number> | number = 1;
    variable = 2;
    console.log(variable);
}

and the following config:

import * as importPlugin from 'eslint-plugin-import-x';
import tseslint from 'typescript-eslint';

const config = [
    {
        files: ['test.ts'],
        plugins: { import: importPlugin },
        settings: { 'import-x/resolver': { typescript: true, node: true } },
        rules: {
            'import/no-duplicates': ['warn', { 'prefer-inline': true }]
        }
    }
];

export default tseslint.config(...tseslint.configs.recommended, ...config);

Running eslint --fix test.ts will produce the follow incorrect file:

import { onMount , readable, type Readable } from 'svelte';
...

Reproduction: