Skip to content

[no-namespace] allow namespace imports for specific modules #1903

@chimericdream

Description

@chimericdream

I want to disallow using namespaces as a rule, but some third-party libraries don't use default exports. The specific one that we use quite a bit in our application is yup. Even if we use TypeScript's allowSyntheticDefaultImports rule, we still have to import the library using import * as yup from 'yup';.

I'd like to be able to do something like the following:

rules: {
    // ...
    'import/no-namespace': ['warn', {allow: ['yup', 'some-lib', '@scoped/lib']}],
    // ...
},

With the above config, the following would be considered correct:

import * as yup from 'yup';
import * as validation from 'yup';
import * as lib from 'some-lib';

And the following would be considered incorrect:

import * as nope from 'not-allowed';

// even though this contains the string "some-lib", it should not be valid; I think the allow list should be exact matches only
import * as stillNope from '@scoped/some-lib';

I came across pull request #1679 from earlier this year, but it appears it was closed without being merged.

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