-
-
Notifications
You must be signed in to change notification settings - Fork 530
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(lint): add useGoogleFontPreconnect
rule
#4185
Conversation
c06b936
to
fdaaf79
Compare
CodSpeed Performance ReportMerging #4185 will not alter performanceComparing Summary
|
@kaioduarte a suggestion for this and other PRs. When filling out the template, please tell how you named the rule inside Biome. Since Biome has a strict naming convention, it's often difficult to understand which rule you implemented. |
google-font-preconnect
from eslint-plugin-next
useGoogleFontPreconnect
useGoogleFontPreconnect
useGoogleFontPreconnect
rule
fdaaf79
to
852870e
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.
The diagnostic must match our rule pillars
crates/biome_js_analyze/src/lint/nursery/use_google_font_preconnect.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_google_font_preconnect.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_google_font_preconnect.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/tests/specs/nursery/useGoogleFontPreconnect/invalid.jsx
Show resolved
Hide resolved
852870e
to
2b9ca81
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.
Thank you! I suggested few changes. Once addressed, we can merge the PR
if node.find_attribute_by_name("rel").is_some() { | ||
return None; | ||
} |
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.
Is this check needed? The check was already done in run
. Did I miss something?
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.
Yes, I didn't want to change the value if a rel
already exists, maybe we could do so, I'm not sure :)
The action is a bonus since the original rule doesn't have one.
crates/biome_js_analyze/src/lint/nursery/use_google_font_preconnect.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_google_font_preconnect.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/use_google_font_preconnect.rs
Outdated
Show resolved
Hide resolved
let rel = node.get_attribute_inner_string_text("rel"); | ||
|
||
if href.starts_with("https://fonts.gstatic.com") && (rel.is_none() || rel? != "preconnect") |
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.
let rel = node.get_attribute_inner_string_text("rel"); | |
if href.starts_with("https://fonts.gstatic.com") && (rel.is_none() || rel? != "preconnect") | |
let rel = node.get_attribute_inner_string_text("rel")?; | |
if href.starts_with("https://fonts.gstatic.com") && rel != "preconnect" |
Since rel
is mandatory attribute, we can simplify the check
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.
It's not mandatory, we emit a diagnostic in the absence of the property or if its value is different of preconnect
.
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.
Then you shouldn't use rel?
, because the try operator ?
exit from the function in case is None
, which goes in conflict with the accepted value rel.is_none
. I suggest using matches!(rel, Some("preconnect"))
instead.
While it's true we're using an OR operation, it would fail if you flip the arguments
2b9ca81
to
b73296d
Compare
Summary
Implement google-font-preconnect from eslint-plugin-next.
Test Plan
Snapshots + CI