mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
e1b8c00d0f
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.
76 lines
1.5 KiB
TypeScript
76 lines
1.5 KiB
TypeScript
import { RuleTester } from 'eslint'
|
|
import { rules } from '@next/eslint-plugin-next'
|
|
|
|
const NextESLintRule = rules['no-title-in-document-head']
|
|
|
|
const tests = {
|
|
valid: [
|
|
`import Head from "next/head";
|
|
|
|
class Test {
|
|
render() {
|
|
return (
|
|
<Head>
|
|
<title>My page title</title>
|
|
</Head>
|
|
);
|
|
}
|
|
}`,
|
|
|
|
`import Document, { Html, Head } from "next/document";
|
|
|
|
class MyDocument extends Document {
|
|
render() {
|
|
return (
|
|
<Html>
|
|
<Head>
|
|
</Head>
|
|
</Html>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default MyDocument;
|
|
`,
|
|
],
|
|
|
|
invalid: [
|
|
{
|
|
code: `
|
|
import { Head } from "next/document";
|
|
|
|
class Test {
|
|
render() {
|
|
return (
|
|
<Head>
|
|
<title>My page title</title>
|
|
</Head>
|
|
);
|
|
}
|
|
}`,
|
|
errors: [
|
|
{
|
|
message:
|
|
'Do not use `<title>` element with `<Head />` component from `next/document`. Titles should defined at the page-level using `<Head />` from `next/head` instead. See: https://nextjs.org/docs/messages/no-title-in-document-head',
|
|
type: 'JSXElement',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
|
|
describe('no-title-in-document-head', () => {
|
|
new RuleTester({
|
|
languageOptions: {
|
|
ecmaVersion: 2018,
|
|
sourceType: 'module',
|
|
parserOptions: {
|
|
ecmaFeatures: {
|
|
modules: true,
|
|
jsx: true,
|
|
},
|
|
},
|
|
},
|
|
}).run('eslint', NextESLintRule, tests)
|
|
})
|