Unverified Commit f97b82a2 authored by Yamagishi Kazutoshi's avatar Yamagishi Kazutoshi Committed by GitHub

Skip processing when href is not a simple string (#24986)

parent 2f142b62
......@@ -23,7 +23,7 @@ module.exports = {
}
const hrefValue = attributes.value('href')
const isGoogleFont = hrefValue.includes(
const isGoogleFont = hrefValue?.startsWith(
'https://fonts.googleapis.com/css'
)
......
......@@ -26,7 +26,7 @@ module.exports = {
attributes.value('rel') !== 'preconnect'
if (
hrefValue.includes('https://fonts.gstatic.com') &&
hrefValue?.startsWith('https://fonts.gstatic.com') &&
preconnectMissing
) {
context.report({
......
......@@ -38,7 +38,7 @@ module.exports = {
}
const hrefValue = attributes.value('href')
const isGoogleFont = hrefValue.includes(
const isGoogleFont = hrefValue?.startsWith(
'https://fonts.googleapis.com/css'
)
......
......@@ -3,7 +3,7 @@ const RuleTester = require('eslint').RuleTester
RuleTester.setDefaultConfig({
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
modules: true,
......@@ -20,6 +20,15 @@ ruleTester.run('google-font-display', rule, {
export default Test = () => {
return (
<Head>
<link href={test} rel="test" />
<link
href={process.env.NEXT_PUBLIC_CANONICAL_URL}
rel="canonical"
/>
<link
href={new URL("../public/favicon.ico", import.meta.url).toString()}
rel="icon"
/>
<link
href="https://fonts.googleapis.com/css2?family=Krona+One&display=optional"
rel="stylesheet"
......
......@@ -3,7 +3,7 @@ const RuleTester = require('eslint').RuleTester
RuleTester.setDefaultConfig({
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
modules: true,
......@@ -18,6 +18,14 @@ ruleTester.run('google-font-preconnect', rule, {
`export const Test = () => (
<div>
<link rel="preconnect" href="https://fonts.gstatic.com"/>
<link
href={process.env.NEXT_PUBLIC_CANONICAL_URL}
rel="canonical"
/>
<link
href={new URL("../public/favicon.ico", import.meta.url).toString()}
rel="icon"
/>
</div>
)
`,
......
......@@ -3,7 +3,7 @@ const RuleTester = require('eslint').RuleTester
RuleTester.setDefaultConfig({
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
modules: true,
......@@ -26,6 +26,14 @@ ruleTester.run('no-page-custom-font', rule, {
href="https://fonts.googleapis.com/css2?family=Krona+One&display=swap"
rel="stylesheet"
/>
<link
href={process.env.NEXT_PUBLIC_CANONICAL_URL}
rel="canonical"
/>
<link
href={new URL("../public/favicon.ico", import.meta.url).toString()}
rel="icon"
/>
</Head>
</Html>
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment