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

Update: Add type jsdoc to rule template #113

Merged
merged 1 commit into from Sep 28, 2021
Merged

Conversation

eightHundreds
Copy link
Contributor

No description provided.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 18, 2021

CLA Signed

The committers are authorized under a signed CLA.

@bmish bmish changed the title Chore: add type jsdoc to rule.js Chore: add type jsdoc to rule template Sep 18, 2021
@bmish
Copy link
Sponsor Member

bmish commented Sep 18, 2021

Neat! Can you explain a bit more about how this works and the benefits it provides in the PR description?

It looks like this allows code editors to see the type/structure of ESLint rule objects and thus provide information/autocomplete about the various rule fields. I like it.

Screen Shot 2021-09-18 at 12 13 18 PM

If this turns out to be the recommended way to annotate non-TypeScript rules with type information, then we could also add it to the Working with Rules rule example: eslint/eslint#15085

@bmish bmish changed the title Chore: add type jsdoc to rule template Update: Add type jsdoc to rule template Sep 18, 2021
@eightHundreds
Copy link
Contributor Author

This is the feature of vscode, and it seems also to be supported by webstorm.
It can use the Typescript declaration to give JavaScript hints.

Copy link
Sponsor Member

@bmish bmish left a comment

Choose a reason for hiding this comment

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

I like it!

@@ -8,6 +8,9 @@
// Rule Definition
//------------------------------------------------------------------------------

/**
* @type {import('eslint').Rule.RuleModule}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to include @types/eslint to make this work?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

My understanding is no. VSCode has Automatic Type Acquistion where it automatically retrieves the corresponding @types/ package for your dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

Huh, that’s cool. I wonder if that has any negative effect when running tsc? I don’t want to please VS Code only to anger TypeScript. Can you double check that?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

These rules are JS files so I don't think anyone will be running tsc with them?

However, I checked what happens when using @type in a TS file, and TS shows a non-blocking hint:

JSDoc types may be moved to TypeScript types. ts(80004)

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. I run TSC on JavaScript files frequently to generate .d.ts files from JSDoc comments. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants