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
405 stars 21 forks source link

`import-x/no-default-export` does not work in typescript #144

Open M-51 opened 1 month ago

M-51 commented 1 month ago

Lets say we have simple (flat) config file eslint.config.js with only one rule 'import-x/no-default-export': 'error',

import eslintPluginImportX from 'eslint-plugin-import-x'
import tsParser from '@typescript-eslint/parser'

export default [
    {
        files: ['**/*.js'],
        languageOptions: {
            ecmaVersion: 'latest',
            sourceType: 'module',
        },
        plugins: {
            'import-x': eslintPluginImportX,
        },
        ignores: ['eslint.config.js'],
        rules: {
            'import-x/no-default-export': 'error',
        },
    },
    {
        files: ['**/*.ts'],
        languageOptions: {
            parser: tsParser,
            ecmaVersion: 'latest',
            sourceType: 'module',
        },
        plugins: {
            'import-x': eslintPluginImportX,
        },
        rules: {
            'import-x/no-default-export': 'error',
        },
        settings: {
            'import-x/resolver': {
                typescript: true,
            },
        },
    },
];
and two files with identical content: foo.js foo.ts
function foo() {
return 'foo';
}

export default foo;
function foo() {
return 'foo';
}

export default foo;

eslint shows correctly 'import-x/no-default-export': 'error' in foo.js file js

while in foo.ts it shows nothing: ts

Here is a repo with replicated problem https://github.com/M-51/default-export-bug


Worth mentioning, other rules, for example opposite rule - import-x/prefer-default-export works correctly (when added) in the same environment in both JavaScript and Typescript. named So it seems, it is only problem with import-x/no-default-export'

hellpirat commented 2 days ago

Yeah I got the same error. no-default-export does not work in my project as well but import-x/prefer-default-export works correctly

jleider commented 1 day ago

Just ran into this issue yesterday as well after converting from the forked import plugin to import-x.