Skip to content

Allow mapping of expected extensions in import/extension rule #2030

Closed
@pwhissell

Description

@pwhissell

Context:

I have a typescript project for a node application using ESM (ecmascript modules)
Because node requires that file extensions be specified for relative imports when using esm, typescript files must import relative modules with the ".js" extension. Using a typescript resolver enables linting to resolve these modules well, but when trying to enforce file extensions using the import/extensions rule, the linter expects the file extensions to be ".ts".
I would like a way to configure the rule to assert that extension rather be ".js"

Repro :

applying linting rules

npx eslint .

in the following gist
https://gist.github.com/pwhissell/165232e5fdd62641efa771f000f1e651

Current output:

1:31 error Missing file extension "ts" for "./other.js" import/extensions 2:33 error Missing file extension "ts" for "./another" import/extensions

Expected:

2:33 error Missing file extension "js" for "./another" import/extensions

Example usage:

rules: { import/extensions: ["error", {"ts", "ignorePackages", "js"}] #<-- this would tell the linter that modules defined in ts files should always be imported with the .js extension }

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