Skip to content

Commit 61e7fdb

Browse files
SukkaWgaojude
andauthored
feat(eslint-plugin): add minimal built-in flat presets (#73873)
Add minimal flat config presets for those who are building their own eslint flat presets and want to use their own parsers and settings. The usage would be like: ```js // eslint.config.js import eslintPluginNext from 'eslint-plugin-next'; export default [ { files: [], plugins: {}, settings: {}, languageOptions: {}, rules: {} }, eslintPluginNext.flatConfigs.recommended, // or eslintPluginNext.flatConfigs.coreWebVitals, ] ``` --------- Co-authored-by: Jude Gao <[email protected]>
1 parent 3a8f245 commit 61e7fdb

File tree

1 file changed

+55
-30
lines changed

1 file changed

+55
-30
lines changed
+55-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
module.exports = {
1+
const recommendedRules = {
2+
// warnings
3+
'@next/next/google-font-display': 'warn',
4+
'@next/next/google-font-preconnect': 'warn',
5+
'@next/next/next-script-for-ga': 'warn',
6+
'@next/next/no-async-client-component': 'warn',
7+
'@next/next/no-before-interactive-script-outside-document': 'warn',
8+
'@next/next/no-css-tags': 'warn',
9+
'@next/next/no-head-element': 'warn',
10+
'@next/next/no-html-link-for-pages': 'warn',
11+
'@next/next/no-img-element': 'warn',
12+
'@next/next/no-page-custom-font': 'warn',
13+
'@next/next/no-styled-jsx-in-document': 'warn',
14+
'@next/next/no-sync-scripts': 'warn',
15+
'@next/next/no-title-in-document-head': 'warn',
16+
'@next/next/no-typos': 'warn',
17+
'@next/next/no-unwanted-polyfillio': 'warn',
18+
// errors
19+
'@next/next/inline-script-id': 'error',
20+
'@next/next/no-assign-module-variable': 'error',
21+
'@next/next/no-document-import-in-page': 'error',
22+
'@next/next/no-duplicate-head': 'error',
23+
'@next/next/no-head-import-in-document': 'error',
24+
'@next/next/no-script-component-in-head': 'error',
25+
}
26+
27+
const coreWebVitalsRules = {
28+
'@next/next/no-html-link-for-pages': 'error',
29+
'@next/next/no-sync-scripts': 'error',
30+
}
31+
32+
const plugin = {
233
rules: {
334
'google-font-display': require('./rules/google-font-display'),
435
'google-font-preconnect': require('./rules/google-font-preconnect'),
@@ -25,39 +56,33 @@ module.exports = {
2556
configs: {
2657
recommended: {
2758
plugins: ['@next/next'],
28-
rules: {
29-
// warnings
30-
'@next/next/google-font-display': 'warn',
31-
'@next/next/google-font-preconnect': 'warn',
32-
'@next/next/next-script-for-ga': 'warn',
33-
'@next/next/no-async-client-component': 'warn',
34-
'@next/next/no-before-interactive-script-outside-document': 'warn',
35-
'@next/next/no-css-tags': 'warn',
36-
'@next/next/no-head-element': 'warn',
37-
'@next/next/no-html-link-for-pages': 'warn',
38-
'@next/next/no-img-element': 'warn',
39-
'@next/next/no-page-custom-font': 'warn',
40-
'@next/next/no-styled-jsx-in-document': 'warn',
41-
'@next/next/no-sync-scripts': 'warn',
42-
'@next/next/no-title-in-document-head': 'warn',
43-
'@next/next/no-typos': 'warn',
44-
'@next/next/no-unwanted-polyfillio': 'warn',
45-
// errors
46-
'@next/next/inline-script-id': 'error',
47-
'@next/next/no-assign-module-variable': 'error',
48-
'@next/next/no-document-import-in-page': 'error',
49-
'@next/next/no-duplicate-head': 'error',
50-
'@next/next/no-head-import-in-document': 'error',
51-
'@next/next/no-script-component-in-head': 'error',
52-
},
59+
rules: recommendedRules,
5360
},
5461
'core-web-vitals': {
5562
plugins: ['@next/next'],
5663
extends: ['plugin:@next/next/recommended'],
57-
rules: {
58-
'@next/next/no-html-link-for-pages': 'error',
59-
'@next/next/no-sync-scripts': 'error',
60-
},
64+
rules: coreWebVitalsRules,
65+
},
66+
},
67+
}
68+
69+
module.exports = plugin
70+
module.exports.flatConfig = {
71+
recommended: {
72+
name: 'next/recommended',
73+
plugins: {
74+
'@next/next': plugin,
75+
},
76+
rules: recommendedRules,
77+
},
78+
coreWebVitals: {
79+
name: 'next/core-web-vitals',
80+
plugins: {
81+
'@next/next': plugin,
82+
},
83+
rules: {
84+
...recommendedRules,
85+
...coreWebVitalsRules,
6186
},
6287
},
6388
}

0 commit comments

Comments
 (0)