-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
feat(linter): add curly
rule
#8123
base: main
Are you sure you want to change the base?
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
CodSpeed Performance ReportMerging #8123 will not alter performanceComparing Summary
|
7d8a824
to
6769983
Compare
Thank you for the contribution! I will review this when I have some time. |
fn get_root_node<'a, 'b>(mut node: &'a AstNode<'b>, ctx: &'a LintContext<'b>) -> &'a AstNode<'b> { | ||
while let Some(parent) = ctx.nodes().parent_node(node.id()) { | ||
node = parent; | ||
} | ||
node | ||
} |
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.
No need to iterate up the tree, you can simply get the root node by accessing root
like ctx.nodes().root_node()
, which will return the Program
node.
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.
Finally I don't need to use root_node.
|
||
fn is_followed_by_else_keyword(root_node: &AstNode, node: &Statement, ctx: &LintContext) -> bool { | ||
let start = node.span().end + 1; | ||
let end = root_node.span().end; |
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 think the root node is necessary here? You can get the last byte offset with ctx.source_text().len()
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.
fixed!
let text = ctx.source_range(Span::new( | ||
before_node_span.end + 1, | ||
span.end | ||
- (u32::try_from(node_string.len()).expect("Failed to convert to u32") - trimmed_len), |
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.
No need to use try_from
and expect here, it's OK to assume files are not larger than 4GB, it's a general assumption we make. You can use as u32
and add the annotation #[allow(clippy::cast_possible_truncation)]
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.
OK! updated!
6769983
to
ea76f7d
Compare
842ce81
to
d928b55
Compare
implement https://eslint.org/docs/latest/rules/curly