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

new rule prefer-jsdoc #1002

Closed
tjx666 opened this issue Mar 21, 2023 · 12 comments · Fixed by #1256
Closed

new rule prefer-jsdoc #1002

tjx666 opened this issue Mar 21, 2023 · 12 comments · Fixed by #1256

Comments

@tjx666
Copy link

tjx666 commented Mar 21, 2023

Motivation

jsdoc can provide useful documentation with IDE integration.

Current behavior

case one: object property

const person = {
    name: 'ly',
    // some description op top of property
    age: 18, // some description after property
};

case 2: typescript interface, should also work for type, enum

interface Options {
    // default value is ['.js', '.ts']
    extensions: String[]; // default value is ['.js', '.ts']
}

case 3: function

// compute sum of two numbers
function add(a, b) {
    
}

Desired behavior

all single comments above should be replaced with jsdoc

Alternatives considered


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@thernstig
Copy link

@tjx666 @brettz9 isn't this what https://eslint.org/docs/latest/rules/multiline-comment-style does already? That could be enforced there.

@brettz9
Copy link
Collaborator

brettz9 commented Apr 13, 2023

@thernstig : While that might make sense as a host for the behavior, that rule looks like it converts line comments (and only multiple consecutive ones) to block comments (including the conventionally asterisked lines) but doesn't convert any comments to JSDoc-style comments (which must have the 2 asterisks at the beginning).

@tjx666
Copy link
Author

tjx666 commented Apr 15, 2023

block comment:

/* this is a
block 
comment */

jsdoc: start withs /**, and will be parsed by typescript:

/**this is
jsdoc
comment */

@brettz9
Copy link
Collaborator

brettz9 commented Apr 15, 2023

@tjx666 : I'd suggest asking for this feature within multiline-comment-style even though that rule doesn't offer the option currently

@tjx666
Copy link
Author

tjx666 commented May 10, 2023

@brettz9 I think this rule is complex enough and I can't find rule multiline-comment-style

@brettz9
Copy link
Collaborator

brettz9 commented May 10, 2023

I'm speaking about ESLint's own rule. See https://eslint.org/docs/latest/rules/multiline-comment-style

@brettz9
Copy link
Collaborator

brettz9 commented May 10, 2023

I'm suggesting requesting this feature from ESLint itself.

@tjx666
Copy link
Author

tjx666 commented May 11, 2023

Seems eslint self doesn't accept feature other than ECMAScript new syntax

@brettz9
Copy link
Collaborator

brettz9 commented May 11, 2023

Ok, yeah, thanks for checking.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 5, 2024
@brettz9
Copy link
Collaborator

brettz9 commented Jul 5, 2024

Filed #1256 . Care to take a look, @tjx666 ?

Note that it doesn't currently work for comments after the structure--only before, and you have to specify contexts if you want it to apply in more than regular functions/methods.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 9, 2024
@brettz9 brettz9 closed this as completed in d5fa8da Jul 9, 2024
Copy link

github-actions bot commented Jul 9, 2024

🎉 This issue has been resolved in version 48.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@brettz9
Copy link
Collaborator

brettz9 commented Jul 9, 2024

I've noted that the new rule is experimental (and it's not under recommended), but it now includes options to check before, after, or before and after. I expect the rule (or the @es-joy/jsdoccomment code it depends upon) will need some further tweaking, but it, as per the tests, should handle the use cases mentioned.

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

Successfully merging a pull request may close this issue.

3 participants