mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(linter/next): false positives for non-custom font link (#3383)
fix: #3378
They only check google fonts.
7e34b4cf98/packages/eslint-plugin-next/src/rules/no-page-custom-font.ts (L152-L154)
This commit is contained in:
parent
78e6326e48
commit
bb2221e4f4
1 changed files with 25 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use oxc_ast::{
|
||||
ast::{Class, Function, JSXAttributeItem, JSXElementName},
|
||||
ast::{Class, Function, JSXAttributeItem, JSXAttributeValue, JSXElementName},
|
||||
AstKind,
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
|
|
@ -46,7 +46,13 @@ impl Rule for NoPageCustomFont {
|
|||
if matches!(&element.name, JSXElementName::Identifier(ident) if ident.name != "link") {
|
||||
return;
|
||||
}
|
||||
let is_custom_font = element.attributes.iter().any(|attr| matches!(&attr, JSXAttributeItem::Attribute(attr) if attr.is_identifier("href") && attr.value.is_some()));
|
||||
|
||||
let is_custom_font = element.attributes.iter().any(|attr| {
|
||||
matches!(&attr,
|
||||
JSXAttributeItem::Attribute(attr) if attr.is_identifier("href") && attr.value.as_ref().is_some_and(|value|
|
||||
matches!(value, JSXAttributeValue::StringLiteral(literal) if literal.value.starts_with("https://fonts.googleapis.com/css"))
|
||||
))
|
||||
});
|
||||
|
||||
if !is_custom_font {
|
||||
return;
|
||||
|
|
@ -246,6 +252,23 @@ fn test() {
|
|||
None,
|
||||
filename.clone(),
|
||||
),
|
||||
(
|
||||
r#"function a() {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<link
|
||||
rel="apple-touch-startup-image"
|
||||
href="/assets/public/pwa/splash/apple-splash-2048-2732.jpg"
|
||||
/>
|
||||
</Head>
|
||||
</Html>
|
||||
)
|
||||
}"#,
|
||||
None,
|
||||
None,
|
||||
filename.clone(),
|
||||
),
|
||||
];
|
||||
|
||||
let fail = vec![
|
||||
|
|
|
|||
Loading…
Reference in a new issue