Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
[eslint] move core-web-vitals config to eslint-plugin-next (vercel#27363
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
stefanprobst authored Jul 23, 2021
1 parent 5561bc8 commit f02f35a
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/eslint-config-next/core-web-vitals.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = {
extends: ['.'].map(require.resolve),
rules: {
'@next/next/no-sync-scripts': 2,
'@next/next/no-html-link-for-pages': 2,
},
extends: ['.', 'plugin:@next/next/core-web-vitals'].map(require.resolve),
}
8 changes: 8 additions & 0 deletions packages/eslint-plugin-next/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ module.exports = {
'@next/next/no-duplicate-head': 2,
},
},
'core-web-vitals': {
plugins: ['@next/next'],
extends: ['plugin:@next/next/recommended'],
rules: {
'@next/next/no-sync-scripts': 2,
'@next/next/no-html-link-for-pages': 2,
},
},
},
}
11 changes: 11 additions & 0 deletions test/integration/eslint/plugin-core-web-vitals-config/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "plugin:@next/next/core-web-vitals",
"root": true,
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2015,
"ecmaFeatures": {
"jsx": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Home = () => (
<div>
<p>Home</p>
<script src="https://example.com" />
<img src="https://example.com/image.png" />
</div>
)

export default Home
11 changes: 11 additions & 0 deletions test/integration/eslint/plugin-recommended-config/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "plugin:@next/next/recommended",
"root": true,
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2015,
"ecmaFeatures": {
"jsx": true
}
}
}
10 changes: 10 additions & 0 deletions test/integration/eslint/plugin-recommended-config/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Document from 'next/document'

const Home = () => (
<div>
<p>Home</p>
<script src="https://example.com" />
</div>
)

export default Home
46 changes: 46 additions & 0 deletions test/integration/eslint/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ jest.setTimeout(1000 * 60 * 2)

const dirFirstTimeSetup = join(__dirname, '../first-time-setup')
const dirCustomConfig = join(__dirname, '../custom-config')
const dirPluginRecommendedConfig = join(
__dirname,
'../plugin-recommended-config'
)
const dirPluginCoreWebVitalsConfig = join(
__dirname,
'../plugin-core-web-vitals-config'
)
const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds')
const dirCustomDirectories = join(__dirname, '../custom-directories')
const dirConfigInPackageJson = join(__dirname, '../config-in-package-json')
Expand Down Expand Up @@ -159,6 +167,44 @@ describe('ESLint', () => {
)
})

test('shows warnings and errors when extending plugin recommended config', async () => {
const { stdout, stderr } = await nextLint(
dirPluginRecommendedConfig,
[],
{
stdout: true,
stderr: true,
}
)

const output = stdout + stderr
expect(output).toContain(
'Warning: External synchronous scripts are forbidden'
)
expect(output).toContain(
'Error: next/document should not be imported outside of pages/_document.js.'
)
})

test('shows warnings and errors when extending plugin core-web-vitals config', async () => {
const { stdout, stderr } = await nextLint(
dirPluginCoreWebVitalsConfig,
[],
{
stdout: true,
stderr: true,
}
)

const output = stdout + stderr
expect(output).toContain(
"Warning: Do not use <img>. Use Image from 'next/image' instead."
)
expect(output).toContain(
'Error: External synchronous scripts are forbidden'
)
})

test('success message when no warnings or errors', async () => {
const { stdout, stderr } = await nextLint(dirFirstTimeSetup, [], {
stdout: true,
Expand Down

0 comments on commit f02f35a

Please sign in to comment.