eslint-community / eslint-plugin-n

Additional ESLint rules for Node.js
MIT License
231 stars 41 forks source link

Bug: plugin doesn't seem to work with tsconfig paths #314

Closed AaronPorts closed 3 weeks ago

AaronPorts commented 3 months ago

Environment

Node version: 22.5.1 npm version: 10.2.5 ESLint version: 9.7.0 eslint-plugin-n version: 17.9.0 Operating System: Windows 11

What rule do you want to report?

n/no-missing-import

Link to Minimal Reproducible Example

https://eslint-online-playground.netlify.app/#eNp1U01vGyEQ/SuIS2LJxh+Nm8a+9JB7q0jtpbQRZccOLgsI2MqV5f/egYW1nTgHr2TeezPDm8eBBi+nsBet08BioCuqWmd9vOX0c2ubTgOnozU3dExjkNZs1JbtgjVIPHDPDSGcSts6pcF/cVFZEzhdkYIl9LcI8M3rdMopm6Z+nI5PeO2SYGMbmH+8gKPwW4g9DGExWyyuqJ8gWN2l7u/WcSK+XI6WToc7rsiPNF3/d6pMA3u0g9OflX08qxWiVzLPFH0HBagETpWRumtqUbwwDnJ20VzyiIa+aoaWbjoj0y3I/nZUB/UQO29yp3VWpk/6wT4tijSwEZ2OZL/GkhC0MpENixr2SQzZeNtmExNl4nS3VWaChuF2Cyf+cxCkVy5+zWiVnM4nvTqL3kzwWl7GuEVqZIy9AwfmARPUAtrQjBN3QNC9jRZxekaYDC5m6iF9CNHCbDuxhZLAtOSyYpCt+A4+4PGK3GAxCPEGpT3qhA9Dbs9UiHi7AxlLLC6i3/euxAo9WRsflV+R3kvWQhSsUd6IFhNS6JiRGiacO31HuDQn5B8c/vSucoqSXX2a65WzmNMG/j6CS24YqaBkuiSzrifJfj2wezYrshz2vIFpz3l+3mUp8j6xuwX7cEZ8E5FMm9+zh4t6V2JR6s3YbCK0exFsOb8qKMwlW7I7TvPzSW/i+B8huoFz

What did you expect to happen?

Couldn't get the plugin to work with paths alias in tsconfig. I expected no error to be received since typescript-eslint works correctly.

Participation

Additional comments

No response

scagood commented 3 months ago

Thank you for the report and good example :)


:thinking: This feels like a bug in here:

https://github.com/eslint-community/eslint-plugin-n/blob/master/lib/util/import-target.js#L42-L55

Sparticuz commented 3 months ago

I started getting this after upgrading to typescript-eslint v8. It looks like the example reproduction is also using v8

Sparticuz commented 3 months ago

🤔 This feels like a bug in here:

master/lib/util/import-target.js#L42-L55

I received this as the output of that function: [ { name: '~', alias: [ './src' ] } ]

and my tsconfig is

"paths": {
  "~/*": ["./src/*"]
}
eladchen commented 2 months ago

Any idea what needs to be done here?

scagood commented 2 months ago

Sorry, I just have not had any time to look recently. I don't think I will have time for the a little while. I may try next week, to get some issues resolved, but no promises!


In terms of what this needs first, the most amazing thing would be a set of failing tests to work with.

The two I can see here that I assume are borked: input target
@module ./module/index.ts
~/* ./src/*

From there we can work out how that should be implemented in enhanced-resolve using the Alias option


I am really not a fan of the way tsconfig.json#paths has been implemented. I wonder whether a rule suggesting avoiding tsconfig.json#paths which suggests using package.json#imports instead is a good idea too. 🤔