-
-
Notifications
You must be signed in to change notification settings - Fork 577
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
base: main
Are you sure you want to change the base?
Conversation
}; | ||
use biome_console::markup; | ||
use biome_js_syntax::{JsModule, JsSyntaxToken}; | ||
use biome_module_graph::JsdocComment; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 thebiome_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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new crate
517d1ba
to
98be97b
Compare
CodSpeed Performance ReportMerging #5844 will not alter performanceComparing Summary
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
crates/biome_js_analyze/src/lint/nursery/use_single_js_doc_asterisk.rs
Outdated
Show resolved
Hide resolved
/** | ||
Asterisk after text * * | ||
*/ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Remove inaccurate comment add invalid examples
98be97b
to
cda9b64
Compare
There was a problem hiding this 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." |
There was a problem hiding this comment.
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
crates/biome_js_analyze/src/lint/nursery/use_single_js_doc_asterisk.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/tests/specs/nursery/useSingleJsDocAsterisk/valid.js
Show resolved
Hide resolved
add comment
Summary
Closes #5784
Test Plan
Added snapshots