Skip to content

feat(linter): useSingleJsDocAsterisk #5844

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

minht11
Copy link
Contributor

@minht11 minht11 commented May 1, 2025

Summary

Closes #5784

  • Implement useSingleJsDocAsterisk rule which ensures single asterisk used at the comment start.
  • Add new rule source EslintJsDoc.

Test Plan

Added snapshots

@minht11 minht11 self-assigned this May 1, 2025
@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels May 1, 2025
};
use biome_console::markup;
use biome_js_syntax::{JsModule, JsSyntaxToken};
use biome_module_graph::JsdocComment;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel bit weird using function from module graph, despite not using module graph itself. Should it be moved somewhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, sorry about that! I knew this moment would come 😅

I just didn’t know a better place to move it to and creating a whole crate for just the one struct felt like overkill. But yeah, it’s starting to make more sense now. @ematipico Would you know a better place for it, or shall we create a biome_jsdoc crate?

Copy link
Member

@ematipico ematipico May 2, 2025

Choose a reason for hiding this comment

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

A new crate is an option. I can propose two other options without creating a new crate:

  • having a comments_ext.rs inside the biome_js_syntax crate
  • make jsdocs part of the semantic model crate (OXC does this)

Unfortunately I don't know how the JsDoc structs work under the hood, so take my suggestions with a grain of salt

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd lean towards a new crate still... @minht11 you can do it in this PR, but feel free to leave it, and I'll do it as a follow-up later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new crate

@minht11 minht11 force-pushed the feat/useSingleJsdocAsterix branch from 517d1ba to 98be97b Compare May 2, 2025 00:08
@minht11 minht11 requested review from a team May 2, 2025 00:10
Copy link

codspeed-hq bot commented May 2, 2025

CodSpeed Performance Report

Merging #5844 will not alter performance

Comparing feat/useSingleJsdocAsterix (217ac02) with main (14551ba)

Summary

✅ 95 untouched benchmarks

Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Nice! Just a few comments.

text.lines()
.take(invalid_line.line_index)
.fold(0, |acc, line| {
acc + line.len() + 1 // +1 for the line break
Copy link
Contributor

Choose a reason for hiding this comment

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

This may break on Windows, since you may have a \r\n sequence instead of only a single \n.

In this case, it may be better to split at \n than to use .lines(), so you'll count the \r as a regular character. It's probably best to add some test cases around this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You were right in CRLF mode offset was wrong and fix would replace all comments whit wrong line ending..
Fixed that and added snapshot file, is that what you had in mind with testing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, sounds good!

};
use biome_console::markup;
use biome_js_syntax::{JsModule, JsSyntaxToken};
use biome_module_graph::JsdocComment;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd lean towards a new crate still... @minht11 you can do it in this PR, but feel free to leave it, and I'll do it as a follow-up later.

Comment on lines +15 to +17
/**
Asterisk after text * *
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel this one should be invalid, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-multi-asterisks.md Allows it.

I am reaching a bit but could imagine comments like:

/**
* https//google.com/* 
* Password ****
*/

Unintentional asterisks at the end of line (except last one) should be rare enough, so for now I would it leave as is, but no strong preference tho.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t necessarily mind the asterisk at the end, but shouldn’t it fail because there isn’t an asterisk at the start of the line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied the same behavior from no-multi-asterisks and did not think much of it, but seems like oversight.

We should catch it, though I would like to implement this in a separate PR not to stall this one.

@minht11 minht11 force-pushed the feat/useSingleJsdocAsterix branch from 98be97b to cda9b64 Compare May 3, 2025 21:36
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Please make sure that the diagnostics follow the rule pillars

rule_category!(),
state.range,
markup! {
"JSDoc comment line should " {position} " with a single asterisk."
Copy link
Member

Choose a reason for hiding this comment

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

We're missing the second pillar , where we explain the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 Implement jsdoc/no-multi-asterisks
4 participants