mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
ESLint plugin defaults to flat config, and we also dropped the built-in lint check at https://github.com/vercel/next.js/pull/83136, so we can sunset the deprecated ESLint v8 testing.
74 lines
1.6 KiB
TypeScript
74 lines
1.6 KiB
TypeScript
import { RuleTester } from 'eslint'
|
|
import { rules } from '@next/eslint-plugin-next'
|
|
|
|
const NextESLintRule = rules['google-font-preconnect']
|
|
|
|
const tests = {
|
|
valid: [
|
|
`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>
|
|
)
|
|
`,
|
|
],
|
|
|
|
invalid: [
|
|
{
|
|
code: `
|
|
export const Test = () => (
|
|
<div>
|
|
<link href="https://fonts.gstatic.com"/>
|
|
</div>
|
|
)
|
|
`,
|
|
errors: [
|
|
{
|
|
message:
|
|
'`rel="preconnect"` is missing from Google Font. See: https://nextjs.org/docs/messages/google-font-preconnect',
|
|
type: 'JSXOpeningElement',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
export const Test = () => (
|
|
<div>
|
|
<link rel="preload" href="https://fonts.gstatic.com"/>
|
|
</div>
|
|
)
|
|
`,
|
|
errors: [
|
|
{
|
|
message:
|
|
'`rel="preconnect"` is missing from Google Font. See: https://nextjs.org/docs/messages/google-font-preconnect',
|
|
type: 'JSXOpeningElement',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
|
|
describe('google-font-preconnect', () => {
|
|
new RuleTester({
|
|
languageOptions: {
|
|
ecmaVersion: 2020,
|
|
sourceType: 'module',
|
|
parserOptions: {
|
|
ecmaFeatures: {
|
|
modules: true,
|
|
jsx: true,
|
|
},
|
|
},
|
|
},
|
|
}).run('eslint', NextESLintRule, tests)
|
|
})
|