Skip to content
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

imports-as-dependencies: Node package not found #1112

Closed
regseb opened this issue Jun 5, 2023 · 5 comments
Closed

imports-as-dependencies: Node package not found #1112

regseb opened this issue Jun 5, 2023 · 5 comments

Comments

@regseb
Copy link
Contributor

regseb commented Jun 5, 2023

Expected behavior

imports-as-dependencies should support Node package (e.g. http, fs, path).

Actual behavior

imports-as-dependencies reports: import points to package which is not found in dependencies

Files

package.json

{
  "name": "testcase",
  "dependencies": {
    "eslint": "8.42.0",
    "eslint-plugin-jsdoc": "46.2.4",
    "typescript": "5.1.3"
  },
  "eslintConfig": {
    "plugins": ["jsdoc"],
    "rules": {
      "jsdoc/imports-as-dependencies": "error"
    }
  }
}

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "noEmit": true,
    "checkJs": true
  }
}

index.js

/**
 * @typedef {import("node:http").Server} Server
 */

/**
 * @param {Server} server
 */
module.exports = function foo(server) {
    console.log(server.maxHeadersCount);
};

To reproduce

npx eslint index.js

/home/regseb/testcase/index.js
  2:1  error  import points to package which is not found in dependencies  jsdoc/imports-as-dependencies

✖ 1 problem (1 error, 0 warnings)

Environment

  • Node version: 18.16.0
  • ESLint version: 8.42.0
  • eslint-plugin-jsdoc version: 46.2.4

Additional info

  • npx tsc support Node package (no error reported).
  • You can use @typedef {import("http").Server} Server (without node: prefix).
@regseb regseb changed the title [imports-as-dependencies] Node package not found imports-as-dependencies: Node package not found Jun 5, 2023
@brettz9
Copy link
Collaborator

brettz9 commented Jun 5, 2023

Makes sense, but shouldn't @types/node be detected as present?

@regseb
Copy link
Contributor Author

regseb commented Jun 6, 2023

I don't have @types/node in the dependencies.

If I add it, there's always the error. I think the rule can't make the connection between node:http and the dependency @types/node.


You may need to add a list of allowed imports with module.builtinModules:

import { builtinModules } from "node:module";

const allowed = builtinModules.flatMap((m) => [m, "node:" + m]);

Or use module.isBuiltin():

import { isBuiltin } from "node:module";
isBuiltin("node:http"); // true
isBuiltin("http"); // true
isBuiltin("wss"); // false 

@brettz9
Copy link
Collaborator

brettz9 commented Jun 6, 2023

Yes, I've already prepared a PR. I'm just wondering whether the desired behavior should require @types/node or nothing at all.

@brettz9
Copy link
Collaborator

brettz9 commented Jun 6, 2023

Since Intellisense works without @types/node installed, I guess @types/node is not strictly required.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jun 6, 2023
@brettz9 brettz9 closed this as completed in ab00592 Jun 6, 2023
@github-actions
Copy link

github-actions bot commented Jun 6, 2023

🎉 This issue has been resolved in version 46.2.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue Jun 16, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) | devDependencies | patch | [`46.2.4` -> `46.2.6`](https://renovatebot.com/diffs/npm/eslint-plugin-jsdoc/46.2.4/46.2.6) |

---

### Release Notes

<details>
<summary>gajus/eslint-plugin-jsdoc</summary>

### [`v46.2.6`](https://github.com/gajus/eslint-plugin-jsdoc/releases/tag/v46.2.6)

[Compare Source](gajus/eslint-plugin-jsdoc@v46.2.5...v46.2.6)

##### Bug Fixes

-   **`imports-as-dependencies`:** do not log missing package.json when rule is not active; fixes [#&#8203;1117](gajus/eslint-plugin-jsdoc#1117) ([3a5dd7d](gajus/eslint-plugin-jsdoc@3a5dd7d))

### [`v46.2.5`](https://github.com/gajus/eslint-plugin-jsdoc/releases/tag/v46.2.5)

[Compare Source](gajus/eslint-plugin-jsdoc@v46.2.4...v46.2.5)

##### Bug Fixes

-   **`imports-as-dependencies`:** support Node builtins; fixes [#&#8203;1112](gajus/eslint-plugin-jsdoc#1112) ([ab00592](gajus/eslint-plugin-jsdoc@ab00592))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTUuMiIsInVwZGF0ZWRJblZlciI6IjM1LjExOC4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1933
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants