1
- import path from 'path'
1
+ import { RuleTester as ESLintTesterV8 } from 'eslint'
2
+ import { RuleTester as ESLintTesterV9 } from 'eslint-v9'
3
+ import { rules } from '@next/eslint-plugin-next'
2
4
3
- import rule from '@next/eslint-plugin-next/dist/rules/no-document-import-in-page'
4
- import { RuleTester } from 'eslint'
5
- ; ( RuleTester as any ) . setDefaultConfig ( {
6
- parserOptions : {
7
- ecmaVersion : 2018 ,
8
- sourceType : 'module' ,
9
- ecmaFeatures : {
10
- modules : true ,
11
- jsx : true ,
12
- } ,
13
- } ,
14
- } )
15
- const ruleTester = new RuleTester ( )
5
+ const NextESLintRule = rules [ 'no-document-import-in-page' ]
16
6
17
- ruleTester . run ( 'no-document-import-in-page' , rule , {
7
+ const tests = {
18
8
valid : [
19
9
{
20
10
code : `import Document from "next/document"
@@ -33,34 +23,6 @@ ruleTester.run('no-document-import-in-page', rule, {
33
23
{
34
24
code : `import Document from "next/document"
35
25
36
- export default class MyDocument extends Document {
37
- render() {
38
- return (
39
- <Html>
40
- </Html>
41
- );
42
- }
43
- }
44
- ` ,
45
- filename : `pages${ path . sep } _document.js` ,
46
- } ,
47
- {
48
- code : `import NextDocument from "next/document"
49
-
50
- export default class MyDocument extends NextDocument {
51
- render() {
52
- return (
53
- <Html>
54
- </Html>
55
- );
56
- }
57
- }
58
- ` ,
59
- filename : `pages${ path . posix . sep } _document.tsx` ,
60
- } ,
61
- {
62
- code : `import Document from "next/document"
63
-
64
26
export default class MyDocument extends Document {
65
27
render() {
66
28
return (
@@ -144,19 +106,31 @@ ruleTester.run('no-document-import-in-page', rule, {
144
106
} ,
145
107
] ,
146
108
} ,
147
- {
148
- code : `import Document from "next/document"
109
+ ] ,
110
+ }
149
111
150
- export const Test = () => <p>Test</p>
151
- ` ,
152
- filename : `pages${ path . sep } test.js` ,
153
- errors : [
154
- {
155
- message :
156
- '`<Document />` from `next/document` should not be imported outside of `pages/_document.js`. See: https://nextjs.org/docs/messages/no-document-import-in-page' ,
157
- type : 'ImportDeclaration' ,
112
+ describe ( 'no-document-import-in-page' , ( ) => {
113
+ new ESLintTesterV8 ( {
114
+ parserOptions : {
115
+ ecmaVersion : 2018 ,
116
+ sourceType : 'module' ,
117
+ ecmaFeatures : {
118
+ modules : true ,
119
+ jsx : true ,
120
+ } ,
121
+ } ,
122
+ } ) . run ( 'eslint-v8' , NextESLintRule , tests )
123
+
124
+ new ESLintTesterV9 ( {
125
+ languageOptions : {
126
+ ecmaVersion : 2018 ,
127
+ sourceType : 'module' ,
128
+ parserOptions : {
129
+ ecmaFeatures : {
130
+ modules : true ,
131
+ jsx : true ,
158
132
} ,
159
- ] ,
133
+ } ,
160
134
} ,
161
- ] ,
135
+ } ) . run ( 'eslint-v9' , NextESLintRule , tests )
162
136
} )
0 commit comments