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

Cannot use "this" in a typescript function declaration #919

Closed
a88zach opened this issue Oct 19, 2022 · 4 comments
Closed

Cannot use "this" in a typescript function declaration #919

a88zach opened this issue Oct 19, 2022 · 4 comments

Comments

@a88zach
Copy link

a88zach commented Oct 19, 2022

Expected behavior

A user should be able to document a function in Typescript that uses the "this" keyword

Actual behavior

Conflicting rules prevent this from passing warnings.

  • When @param this is declared the warning is:
    Screen Shot 2022-10-19 at 10 08 32 AM

  • When @param this is removed the warning is:
    Screen Shot 2022-10-19 at 10 09 13 AM

ESLint Config

module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:jsdoc/recommended',
  ],
  overrides: [],
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint', 'jsdoc'],
  root: true,
  rules: {
    'jsdoc/require-param-type': 0,
    'jsdoc/require-returns-type': 0,
    'jsdoc/no-types': 2,
  },
};

ESLint sample

Screen Shot 2022-10-19 at 10 08 32 AM

type T = { name: string };

/**
 * @param this desc
 * @param bar number to return
 * @returns number returned back to caller
 */
function foo(this: T, bar: number): number {
  console.log(this.name);
  return bar;
}

const bound = foo.bind({ name: 'baz' });

bound(2);

Screen Shot 2022-10-19 at 10 09 13 AM

type T = { name: string };

/**
 * @param bar number to return
 * @returns number returned back to caller
 */
function foo(this: T, bar: number): number {
  console.log(this.name);
  return bar;
}

const bound = foo.bind({ name: 'baz' });

bound(2);

Environment

  • Node version: 16
  • ESLint version 8.25.0
  • eslint-plugin-jsdoc version: 39.3.14
@gajus
Copy link
Owner

gajus commented Oct 22, 2022

🎉 This issue has been resolved in version 39.3.16 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Oct 22, 2022
@brettz9
Copy link
Collaborator

brettz9 commented Oct 22, 2022

I've resumed tolerating @param this in check-param-names, but we really still need to support this: xyz being ignored as a param in require-param whether the user is documenting it with the (also TS-sanctioned) @this or with @param this.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Oct 22, 2022
@brettz9
Copy link
Collaborator

brettz9 commented Oct 22, 2022

I've gone ahead and also made require-param more tolerant in accepting @param this. However, since TS supports @this, it might be a better idea to ensure that the this object is documented with @this rather than as a param.

@gajus
Copy link
Owner

gajus commented Oct 22, 2022

🎉 This issue has been resolved in version 39.3.19 🎉

The release is available on:

Your semantic-release bot 📦🚀

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue Oct 24, 2022
This PR contains the following updates:

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

---

### Release Notes

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

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

[Compare Source](gajus/eslint-plugin-jsdoc@v39.3.20...v39.3.21)

##### Bug Fixes

-   **`require-param`:** do not cache by comment node; fixes [#&#8203;901](gajus/eslint-plugin-jsdoc#901) ([867edc3](gajus/eslint-plugin-jsdoc@867edc3))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v39.3.19...v39.3.20)

##### Bug Fixes

-   **`require-returns-check`:** allow for missing catch or finalizer and missing case contents; fixes [#&#8203;924](gajus/eslint-plugin-jsdoc#924) ([4fabdd6](gajus/eslint-plugin-jsdoc@4fabdd6))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v39.3.18...v39.3.19)

##### Bug Fixes

-   **`require-param`:** be tolerant if `this` is not included as `[@param](https://github.com/param)`; fixes [#&#8203;919](gajus/eslint-plugin-jsdoc#919) ([c1f21f8](gajus/eslint-plugin-jsdoc@c1f21f8))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v39.3.17...v39.3.18)

##### Bug Fixes

-   **`require-returns-check`:** check child nodes of consequents; fixes [#&#8203;923](gajus/eslint-plugin-jsdoc#923) ([dc1f875](gajus/eslint-plugin-jsdoc@dc1f875))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v39.3.16...v39.3.17)

##### Bug Fixes

-   **`require-returns-check`:** throw statements to be exempted from final check if elsewhere in function; fixes [#&#8203;892](gajus/eslint-plugin-jsdoc#892) ([87c1c2a](gajus/eslint-plugin-jsdoc@87c1c2a))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v39.3.15...v39.3.16)

##### Bug Fixes

-   **`check-param-names`:** tolerate documented "this" param; fixes [#&#8203;919](gajus/eslint-plugin-jsdoc#919) ([5d20bdf](gajus/eslint-plugin-jsdoc@5d20bdf))

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

[Compare Source](gajus/eslint-plugin-jsdoc@v39.3.14...v39.3.15)

##### Bug Fixes

-   **`require-returns-check`:** checks that all branches of final node return; fixes [#&#8203;892](gajus/eslint-plugin-jsdoc#892) ([bdd6af2](gajus/eslint-plugin-jsdoc@bdd6af2))

</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, click this checkbox.

---

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

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1600
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

3 participants