eslint-config icon indicating copy to clipboard operation
eslint-config copied to clipboard

[Feature Request] disable use globals var `__dirname` `__filename` in nodejs esm mode

Open BobDu opened this issue 1 year ago • 3 comments

Clear and concise description of the problem

disable use globals var __dirname __filename in nodejs esm mode

These CommonJS variables are not available in ES modules. https://nodejs.org/api/esm.html#no-__filename-or-__dirname

Suggest use import.meta.filename import.meta.dirname instead

Link: eslint-community/eslint-plugin-n#164

Suggested solution

N/A

Alternative

No response

Additional context

No response

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guide.
  • [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

BobDu avatar Jan 10 '24 08:01 BobDu

@antfu I'm very sorry to disturb you. I hope this doesn't cause any inconvenience for you. I would like to know if this feature request is easy to implement. Is it possible that it will be supported?

BobDu avatar Jan 29 '24 10:01 BobDu

I'd be happy to disallow __dirname et al., but I am not sure if we should recommend import.meta.filename as it would be still runtime-specific. I usually use new URL('../', import.meta.url) to make it work cross platform.

antfu avatar Jan 29 '24 12:01 antfu

Sorry, I am not an experienced front-end developer. I trust that the usage you recommended is surely better.

The idea behind this feature request originated from a bug I encountered during a migration from CommonJS to ESM.

Ref: https://github.com/Kerwin1202/chatgpt-web/issues/405

BobDu avatar Jan 29 '24 13:01 BobDu

I think currently I don't want to have a strict rule for that - feel free to disable it on userland.

antfu avatar Apr 22 '24 11:04 antfu