mysticatea / eslint-plugin-node

Additional ESLint's rules for Node.js
MIT License
958 stars 167 forks source link

feat: `file-extension-in-import` to consider exports map #258

Open privatenumber opened 3 years ago

privatenumber commented 3 years ago

When importing an extension-less path, I'd like for file-extension-in-import to check if the path exists in the target package's exports map. If it exists, it should not error.

eg.

import * as assert from 'uvu/assert';

Given the following export map.


Related https://github.com/mysticatea/eslint-plugin-node/issues/255

privatenumber commented 3 years ago

Happy to open a PR if feature request is approved

jaydenseric commented 2 years ago

This issue should be labeled a bug, not an enhancement. The node/file-extension-in-import rule is straight-up broken, reporting false errors that are impossible to fix without using // eslint-disable-next-line node/file-extension-in-import. The package exports field is not some optional, exotic feature. It's core functionality for all the current stable Node.js versions (claimed to be supported by eslint-plugin-node) and in use by all sorts of popular packages.

Here is a situation I run into a lot:

// eslint-disable-next-line node/file-extension-in-import
import { red } from "kleur/colors";