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

chore: add jsdoc type annotation to rules #15291

Merged
merged 5 commits into from Nov 24, 2021
Merged

Conversation

bmish
Copy link
Sponsor Member

@bmish bmish commented Nov 11, 2021

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[X] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Adds jsdoc type annotation to core rules.

Supported by VSCode/Webstorm/other code editors. Uses TypeScript declaration to give JavaScript hints so code editors can provide information/autocomplete about various rule fields.

https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#type

Idea from: eslint/generator-eslint#113

133895350-a19d0daf-593e-44b9-835f-bebf8b6a3d30

We also have this suggested in our "Working with Rules" guide: https://eslint.org/docs/developer-guide/working-with-rules

Uses single-line version of this comment since there's no need for it to take up additional space.

Is there anything you'd like reviewers to focus on?

No.

@eslint-github-bot eslint-github-bot bot added the triage An ESLint team member will look at this issue soon label Nov 11, 2021
@nzakas
Copy link
Member

nzakas commented Nov 12, 2021

It seems like we should be using our own type definition:
https://github.com/eslint/eslint/blob/main/lib/shared/types.js

@nzakas nzakas added chore This change is not user-facing and removed triage An ESLint team member will look at this issue soon labels Nov 12, 2021
@bmish
Copy link
Sponsor Member Author

bmish commented Nov 12, 2021

It seems like we should be using our own type definition: main/lib/shared/types.js

That should work too, updated. The internal Rule type is pretty similar to the externally-maintained one from @types/eslint.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM

@bmish bmish closed this Nov 19, 2021
@bmish bmish reopened this Nov 19, 2021
@bmish
Copy link
Sponsor Member Author

bmish commented Nov 19, 2021

FYI: I have added a test to ensure this jsdoc comment is present in each rule file. Otherwise, it would be easily forgotten when adding new rules.

@bmish bmish merged commit 1e32ee5 into eslint:main Nov 24, 2021
@bmish bmish deleted the rules-jsdoc-type branch November 24, 2021 05:04
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators May 24, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion chore This change is not user-facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants