Skip to content

Allow to use tryExtensions in the rule no-unpublished-import #429

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

Conversation

wdzeng
Copy link

@wdzeng wdzeng commented Mar 27, 2025

I just found that the option tryExtensions is available in no-unpublished-require, but not in no-unpublished-import. So I add this option.

Both lib/util/visit-require.js and lib/util/visit-import.js support this option, so this PR should work.

Here is my manual test:

  1. Create an empty project.
  2. Create package.json at the project root with only one line {"files":["index.mts","foo.mts"]}.
  3. Create index.mts at the project root with only one line import foo from './foo'; import bar from './bar';.
  4. Install eslint and eslint-plugin-n by npm i -D eslint eslint-plugin-n.
  5. Create eslint.config.mjs at the project root.
    import eslintPluginN from 'eslint-plugin-n'
    export default [{
      files: ['*.mts'],
      plugins: { n: eslintPluginN },
      // rules: { 'n/no-unpublished-import': ['error'] }
      rules: { 'n/no-unpublished-import': ['error', { tryExtensions: ['.mts'] }] } 
    }]
  6. Run npx eslint index.mts.

Here is the test result:

Without this PR With this PR
Use commented rules in step 5. Got false error message: error "./foo" is not published. Same as left.
Use uncommented rules in step 5. Got error message in step 6: Unexpected property "tryExtensions". Work as expected.

I also tried with using tsconfig.json and path alias. It works smoothly.

Copy link

@scagood scagood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, thank you!

Do you think you can add a couple of tests for this option too?

@wdzeng wdzeng force-pushed the features/no-unpublished-import-try-extensions branch from 8edb27e to 6548b74 Compare March 27, 2025 20:06
@wdzeng
Copy link
Author

wdzeng commented Mar 27, 2025

Hi @scagood I've done the test. One valid case and one invalid case.

Copy link

@scagood scagood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💜 Thank you!

@scagood scagood requested a review from aladdin-add March 27, 2025 21:58
Copy link

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 💯

@aladdin-add aladdin-add merged commit 002ac9c into eslint-community:master Mar 28, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants