Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit daf54bb

Browse files
authored
[eslint] move core-web-vitals config to eslint-plugin-next (vercel#27363)
this pr moves the "core-web-vitals" config from `eslint-config-next` to `eslint-plugin-next`. Fixes: vercel#27292 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes
1 parent a8b9c3a commit daf54bb

File tree

7 files changed

+96
-5
lines changed

7 files changed

+96
-5
lines changed
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module.exports = {
2-
extends: ['.'].map(require.resolve),
3-
rules: {
4-
'@next/next/no-sync-scripts': 2,
5-
'@next/next/no-html-link-for-pages': 2,
6-
},
2+
extends: ['.', 'plugin:@next/next/core-web-vitals'].map(require.resolve),
73
}

packages/eslint-plugin-next/lib/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,13 @@ module.exports = {
3333
'@next/next/no-duplicate-head': 2,
3434
},
3535
},
36+
'core-web-vitals': {
37+
plugins: ['@next/next'],
38+
extends: ['plugin:@next/next/recommended'],
39+
rules: {
40+
'@next/next/no-sync-scripts': 2,
41+
'@next/next/no-html-link-for-pages': 2,
42+
},
43+
},
3644
},
3745
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "plugin:@next/next/core-web-vitals",
3+
"root": true,
4+
"parserOptions": {
5+
"sourceType": "module",
6+
"ecmaVersion": 2015,
7+
"ecmaFeatures": {
8+
"jsx": true
9+
}
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Home = () => (
2+
<div>
3+
<p>Home</p>
4+
<script src="https://example.com" />
5+
<img src="https://example.com/image.png" />
6+
</div>
7+
)
8+
9+
export default Home
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "plugin:@next/next/recommended",
3+
"root": true,
4+
"parserOptions": {
5+
"sourceType": "module",
6+
"ecmaVersion": 2015,
7+
"ecmaFeatures": {
8+
"jsx": true
9+
}
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Document from 'next/document'
2+
3+
const Home = () => (
4+
<div>
5+
<p>Home</p>
6+
<script src="https://example.com" />
7+
</div>
8+
)
9+
10+
export default Home

test/integration/eslint/test/index.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ jest.setTimeout(1000 * 60 * 2)
88

99
const dirFirstTimeSetup = join(__dirname, '../first-time-setup')
1010
const dirCustomConfig = join(__dirname, '../custom-config')
11+
const dirPluginRecommendedConfig = join(
12+
__dirname,
13+
'../plugin-recommended-config'
14+
)
15+
const dirPluginCoreWebVitalsConfig = join(
16+
__dirname,
17+
'../plugin-core-web-vitals-config'
18+
)
1119
const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds')
1220
const dirCustomDirectories = join(__dirname, '../custom-directories')
1321
const dirConfigInPackageJson = join(__dirname, '../config-in-package-json')
@@ -159,6 +167,44 @@ describe('ESLint', () => {
159167
)
160168
})
161169

170+
test('shows warnings and errors when extending plugin recommended config', async () => {
171+
const { stdout, stderr } = await nextLint(
172+
dirPluginRecommendedConfig,
173+
[],
174+
{
175+
stdout: true,
176+
stderr: true,
177+
}
178+
)
179+
180+
const output = stdout + stderr
181+
expect(output).toContain(
182+
'Warning: External synchronous scripts are forbidden'
183+
)
184+
expect(output).toContain(
185+
'Error: next/document should not be imported outside of pages/_document.js.'
186+
)
187+
})
188+
189+
test('shows warnings and errors when extending plugin core-web-vitals config', async () => {
190+
const { stdout, stderr } = await nextLint(
191+
dirPluginCoreWebVitalsConfig,
192+
[],
193+
{
194+
stdout: true,
195+
stderr: true,
196+
}
197+
)
198+
199+
const output = stdout + stderr
200+
expect(output).toContain(
201+
"Warning: Do not use <img>. Use Image from 'next/image' instead."
202+
)
203+
expect(output).toContain(
204+
'Error: External synchronous scripts are forbidden'
205+
)
206+
})
207+
162208
test('success message when no warnings or errors', async () => {
163209
const { stdout, stderr } = await nextLint(dirFirstTimeSetup, [], {
164210
stdout: true,

0 commit comments

Comments
 (0)