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 doesn't detect missing @types packages #1107

Closed
DetachHead opened this issue Jun 3, 2023 · 10 comments · Fixed by #1108 or #1110
Closed

imports-as-dependencies doesn't detect missing @types packages #1107

DetachHead opened this issue Jun 3, 2023 · 10 comments · Fixed by #1108 or #1110

Comments

@DetachHead
Copy link

thanks for adding the rule i suggested in #896! i noticed that it doesn't seem to detect @types/ packages though

Expected behavior

error because @types/eslint is not in dependencies or devDependencies

Actual behavior

no error

ESLint Config

module.exports = {
    // ...
    rules: {
        'jsdoc/imports-as-dependencies': 'error'
    }
}

ESLint sample

source code

/** @type {import('eslint').Linter.ParserOptions} */
const foo = {}

package.json

{
  "dependencies": {
    "eslint": "^8.13.0"
  },
  "devDependencies": {}
}

Environment

  • Node version: 19.7.0
  • ESLint version
  • eslint-plugin-jsdoc version: 46.2.0
@brettz9
Copy link
Collaborator

brettz9 commented Jun 3, 2023

Ugh, yeah, I really hadn't thought this through. I'm not sure how much detection we want to be doing, e.g., to know whether to check for types in package.json, not to mention typeRoots or whatever.

@brettz9
Copy link
Collaborator

brettz9 commented Jun 3, 2023

I'm thinking I may need to remove the rule unless TypeScript provides an API for detection, since there is quite a bit involved here--e.g., types within exports, typeRoots, etc.

@DetachHead
Copy link
Author

import/no-extraneous-dependencies is able to detect this, maybe its worth looking at the source code for that rule to see how it works

@brettz9
Copy link
Collaborator

brettz9 commented Jun 3, 2023

That appears to be able to look for type imports, but not checking whether declaration files are present.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jun 3, 2023
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jun 3, 2023
@brettz9
Copy link
Collaborator

brettz9 commented Jun 3, 2023

Ok, I've submitted #1108 which should handle this. It doesn't do caching as it probably should, nor does it take into account typeRoots or use of types within exports, but it should provide an easy fix for the current problem at least.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jun 3, 2023
brettz9 added a commit that referenced this issue Jun 3, 2023
@github-actions
Copy link

github-actions bot commented Jun 3, 2023

🎉 This issue has been resolved in version 46.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@DetachHead
Copy link
Author

@brettz9 looks like it now errors on imports from packages that come with type definitions (ie. does not need a @types package)

/** @type {import('typescript').Program} */ // error  import points to package which is not found in dependencies  jsdoc/imports-as-dependencies
const foo = {}

in this case, i have typescript in devDependencies but there's no need for @types/typescript to be installed

@brettz9
Copy link
Collaborator

brettz9 commented Jun 4, 2023

With the exception of TypeScript itself (for which I can supply a fix), it should still be working for packages with their own types. TypeScript just doesn't have types in package.json as other packages should.

@DetachHead
Copy link
Author

looks like typescript uses typings instead of types, which is apparently an alias for the same thing, see https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package

Note that the "typings" field is synonymous with types, and could be used as well.

@github-actions
Copy link

github-actions bot commented Jun 4, 2023

🎉 This issue has been resolved in version 46.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

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

---

### Release Notes

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

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

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

##### Bug Fixes

-   **`imports-as-dependencies`:** allow relative paths ([7469e59](gajus/eslint-plugin-jsdoc@7469e59))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v46.2.2...v46.2.3)

##### Bug Fixes

-   **`imports-as-dependencies`:** catch `typings` as possible publishing source ([e3b0d0c](gajus/eslint-plugin-jsdoc@e3b0d0c))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v46.2.1...v46.2.2)

##### Bug Fixes

-   **`imports-as-dependencies`:** don't report TypeScript proper ([75b6b8c](gajus/eslint-plugin-jsdoc@75b6b8c))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v46.2.0...v46.2.1)

##### Bug Fixes

-   **`imports-as-dependencies`:** check for `types` in `package.json` and if not present, check `[@types](https://github.com/types)`; fixes [#&#8203;1107](gajus/eslint-plugin-jsdoc#1107) ([785fb26](gajus/eslint-plugin-jsdoc@785fb26))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v46.1.0...v46.2.0)

##### Features

-   **`imports-as-dependencies`:** add new rule to detect missing dependencies for import statements; fixes [#&#8203;896](gajus/eslint-plugin-jsdoc#896) ([d7ec6e0](gajus/eslint-plugin-jsdoc@d7ec6e0))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v46.0.0...v46.1.0)

##### Features

-   **`require-returns`:** per-context `forceRequireReturn`; fixes [#&#8203;757](gajus/eslint-plugin-jsdoc#757) ([31b3a24](gajus/eslint-plugin-jsdoc@31b3a24))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v45.0.0...v46.0.0)

##### Features

-   **`no-defaults`:** make no-defaults on by default ([034ade1](gajus/eslint-plugin-jsdoc@034ade1))

##### BREAKING CHANGES

-   **`no-defaults`:** Removes default values. Disable the rule if removal not desired.

Also:

-   docs: adds info on TS recommended rules

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

[Compare Source](gajus/eslint-plugin-jsdoc@v44.2.7...v45.0.0)

##### Features

-   add recommended-typescript-flavor configs ([6042b77](gajus/eslint-plugin-jsdoc@6042b77))
-   for typescript configs, disable `no-undefined-types`; fixes [#&#8203;888](gajus/eslint-plugin-jsdoc#888) ([ec41b90](gajus/eslint-plugin-jsdoc@ec41b90))

##### BREAKING CHANGES

-   This should only impact users of typescript configs. TS should itself handle
    checking for undefined types, so the (imperfect) rule has been disabled for
    such users.

### [`v44.2.7`](gajus/eslint-plugin-jsdoc@v44.2.6...v44.2.7)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.2.6...v44.2.7)

### [`v44.2.6`](gajus/eslint-plugin-jsdoc@v44.2.5...v44.2.6)

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

### [`v44.2.5`](gajus/eslint-plugin-jsdoc@v44.2.4...v44.2.5)

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

### [`v44.2.4`](gajus/eslint-plugin-jsdoc@v44.2.3...v44.2.4)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.2.3...v44.2.4)

### [`v44.2.3`](gajus/eslint-plugin-jsdoc@v44.2.2...v44.2.3)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.2.2...v44.2.3)

### [`v44.2.2`](gajus/eslint-plugin-jsdoc@v44.2.1...v44.2.2)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.2.1...v44.2.2)

### [`v44.2.1`](gajus/eslint-plugin-jsdoc@v44.2.0...v44.2.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.2.0...v44.2.1)

### [`v44.2.0`](gajus/eslint-plugin-jsdoc@v44.1.0...v44.2.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.1.0...v44.2.0)

### [`v44.1.0`](gajus/eslint-plugin-jsdoc@v44.0.2...v44.1.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.0.2...v44.1.0)

### [`v44.0.2`](gajus/eslint-plugin-jsdoc@v44.0.1...v44.0.2)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.0.1...v44.0.2)

### [`v44.0.1`](gajus/eslint-plugin-jsdoc@v44.0.0...v44.0.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v44.0.0...v44.0.1)

### [`v44.0.0`](gajus/eslint-plugin-jsdoc@v43.2.0...v44.0.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.2.0...v44.0.0)

### [`v43.2.0`](gajus/eslint-plugin-jsdoc@v43.1.1...v43.2.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.1.1...v43.2.0)

### [`v43.1.1`](gajus/eslint-plugin-jsdoc@v43.1.0...v43.1.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.1.0...v43.1.1)

### [`v43.1.0`](gajus/eslint-plugin-jsdoc@v43.0.9...v43.1.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.9...v43.1.0)

### [`v43.0.9`](gajus/eslint-plugin-jsdoc@v43.0.8...v43.0.9)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.8...v43.0.9)

### [`v43.0.8`](gajus/eslint-plugin-jsdoc@v43.0.7...v43.0.8)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.7...v43.0.8)

### [`v43.0.7`](gajus/eslint-plugin-jsdoc@v43.0.6...v43.0.7)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.6...v43.0.7)

### [`v43.0.6`](gajus/eslint-plugin-jsdoc@v43.0.5...v43.0.6)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.5...v43.0.6)

### [`v43.0.5`](gajus/eslint-plugin-jsdoc@v43.0.4...v43.0.5)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.4...v43.0.5)

### [`v43.0.4`](gajus/eslint-plugin-jsdoc@v43.0.3...v43.0.4)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.3...v43.0.4)

### [`v43.0.3`](gajus/eslint-plugin-jsdoc@v43.0.2...v43.0.3)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.2...v43.0.3)

### [`v43.0.2`](gajus/eslint-plugin-jsdoc@v43.0.1...v43.0.2)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.1...v43.0.2)

### [`v43.0.1`](gajus/eslint-plugin-jsdoc@v43.0.0...v43.0.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v43.0.0...v43.0.1)

### [`v43.0.0`](gajus/eslint-plugin-jsdoc@v42.0.0...v43.0.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v42.0.0...v43.0.0)

### [`v42.0.0`](gajus/eslint-plugin-jsdoc@v41.1.2...v42.0.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v41.1.2...v42.0.0)

### [`v41.1.2`](gajus/eslint-plugin-jsdoc@v41.1.1...v41.1.2)

[Compare Source](gajus/eslint-plugin-jsdoc@v41.1.1...v41.1.2)

### [`v41.1.1`](gajus/eslint-plugin-jsdoc@v41.1.0...v41.1.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v41.1.0...v41.1.1)

### [`v41.1.0`](gajus/eslint-plugin-jsdoc@v41.0.0...v41.1.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v41.0.0...v41.1.0)

### [`v41.0.0`](gajus/eslint-plugin-jsdoc@v40.3.0...v41.0.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v40.3.0...v41.0.0)

</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:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTEuMCIsInVwZGF0ZWRJblZlciI6IjM1LjExMS4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCJ9-->

Co-authored-by: cabr2-bot <[email protected]>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1913
Reviewed-by: Epsilon_02 <[email protected]>
Co-authored-by: Calciumdibromid Bot <[email protected]>
Co-committed-by: Calciumdibromid Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment