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 1 commit 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.

Remove inaccurate comment

add invalid examples
@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 (98be97b) with main (66f7731)

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.

"@biomejs/biome": minor
---

Add [useSingleJsDocAsterisk](https://biomejs.dev/linter/rules/use-single-js-doc-asterisk/)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a short description here about what the rule does?

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.

};
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 +289 to +294
if char_is_whitespace(b) {
continue;
}

// Found non-whitespace character
break;
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 you can make your intention clearer like this:

Suggested change
if char_is_whitespace(b) {
continue;
}
// Found non-whitespace character
break;
if !char_is_whitespace(b) {
break;
}

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?

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
3 participants