Skip to content

rule default should ignore import commonjs? #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JounQin opened this issue May 20, 2025 · 3 comments
Open

rule default should ignore import commonjs? #334

JounQin opened this issue May 20, 2025 · 3 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed PR welcome

Comments

@JounQin
Copy link
Member

JounQin commented May 20, 2025

https://github.com/un-ts/eslint-plugin-import-x/blob/v4.12.2/docs/rules/default.md#rule-details

import baz from './baz'

Otherwise, what's the replacement?

cc @SukkaW

Copy link

The rule default in the eslint-plugin-import-x is designed to enforce certain import/export conventions. If you are using CommonJS modules and want to ignore the import statement for them, you might need to adjust your ESLint configuration or use a different approach to handle CommonJS imports.

In CommonJS, the equivalent of the ES6 import statement would typically be:

const baz = require('./baz');

If you want to continue using import statements while working with CommonJS modules, you might need to use a transpiler like Babel to convert ES6 modules to CommonJS, or configure your ESLint to allow such usage.

If you are looking for a specific configuration or workaround within eslint-plugin-import-x, please let me know, and I can help you further explore the documentation or configuration options.

@SukkaW
Copy link
Collaborator

SukkaW commented May 21, 2025

https://github.com/un-ts/eslint-plugin-import-x/blob/v4.12.2/docs/rules/default.md#rule-details

IMHO, even if we are using import directive with the CJS module, to maintain the semantics we will still need to use import * as.

@JounQin
Copy link
Member Author

JounQin commented May 21, 2025

@SukkaW eslint/eslint#19703

Sadly we can't.

import * as imported will add a new default property on imported, and the reference is different with import imported AFAIK.

In the rule description:

This rule currently does not interpret module.exports = ... as a default export, either, so such a situation will be reported in the importing module.

So I'd think it's a limitation of current implementation and we should resolve.

@JounQin JounQin added help wanted Extra attention is needed good first issue Good for newcomers PR welcome labels May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed PR welcome
Projects
None yet
Development

No branches or pull requests

2 participants