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

feat(linter): add curly rule #8123

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

Conversation

baseballyama
Copy link
Contributor

@baseballyama baseballyama commented Dec 26, 2024

Copy link

graphite-app bot commented Dec 26, 2024

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 26, 2024
Copy link

codspeed-hq bot commented Dec 26, 2024

CodSpeed Performance Report

Merging #8123 will not alter performance

Comparing baseballyama:feat/eslint/curly (914ce40) with main (372eb09)

Summary

✅ 29 untouched benchmarks

@baseballyama baseballyama force-pushed the feat/eslint/curly branch 8 times, most recently from 7d8a824 to 6769983 Compare December 26, 2024 14:26
@camchenry
Copy link
Contributor

Thank you for the contribution! I will review this when I have some time.

@camchenry camchenry requested review from camchenry and camc314 January 3, 2025 15:15
Comment on lines 246 to 238
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
}
Copy link
Contributor

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.

Copy link
Contributor Author

@baseballyama baseballyama Jan 5, 2025

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;
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 think the root node is necessary here? You can get the last byte offset with ctx.source_text().len()

Copy link
Contributor Author

@baseballyama baseballyama Jan 5, 2025

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),
Copy link
Contributor

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)]

Copy link
Contributor Author

@baseballyama baseballyama Jan 5, 2025

Choose a reason for hiding this comment

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

OK! updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants