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

refactor(noFloatingPromises): update functions to return Option #4970

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

kaykdm
Copy link
Contributor

@kaykdm kaykdm commented Jan 25, 2025

Summary

related: #4956

This PR refactors functions to return Option, aligning with the accepted coding practices in Biome as suggested here

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Jan 25, 2025
Copy link

codspeed-hq bot commented Jan 25, 2025

CodSpeed Performance Report

Merging #4970 will improve performances by 6.95%

Comparing kaykdm:refactor-noFloatingPromises (5dd7d53) with next (e750523)

Summary

⚡ 1 improvements
✅ 94 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
react.production.min_3378072959512366797.js[cached] 2 ms 1.9 ms +6.95%

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.

Thank you! Much better!

Just to give more information about this "style" of programming: our parsers are recoverable and error resilient, this means that even incorrect syntax will emit an analyzable CST.

Because of that we need to assume that each node/token are incorrect. Bogus nodes for nodes, missing mandatory tokens for tokens.

Inside lint rules, when we use .ok()?, it means that we "query a valid node", and we skip (via the try operator) possible bogus nodes/missing mandatory tokens.

I hope it makes sense! 😊

@ematipico ematipico merged commit bdc34a1 into biomejs:next Jan 25, 2025
12 checks passed
Comment on lines +204 to +207
AnyJsBindingDeclaration::JsVariableDeclarator(js_var_decl) => Some(
is_variable_initializer_a_promise(&js_var_decl).unwrap_or(false)
|| is_variable_annotation_a_promise(&js_var_decl).unwrap_or(false),
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think this could have been written more concisely as:

                AnyJsBindingDeclaration::JsVariableDeclarator(js_var_decl) =>
                    is_variable_initializer_a_promise(&js_var_decl).or_else(
                        || is_variable_annotation_a_promise(&js_var_decl)
                    ),

Note this would propagate the None state up to the caller, but that's also the point of having these functions return Option. Don't worry about it though, you'll get the hang of this style of Rust utilities soon enough 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I'll incorporate that change in the next PR.

@kaykdm kaykdm deleted the refactor-noFloatingPromises branch January 25, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants