Skip to content

Commit

Permalink
Fix eslint config next/core-web-vitals (#27567)
Browse files Browse the repository at this point in the history
fixes what i messed up in #27363. cf. #27363 (comment)

also added an integration test for extending from `next/core-web-vitals` eslint config

## Bug

- [x] Related issues linked using `fixes #number`
- [x] 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.
- [ ] 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 28, 2021
1 parent c7e2a1d commit 0833f83
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eslint-config-next/core-web-vitals.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['.', 'plugin:@next/next/core-web-vitals'].map(require.resolve),
extends: [require.resolve('.'), 'plugin:@next/next/core-web-vitals'],
}
4 changes: 4 additions & 0 deletions test/integration/eslint/config-core-web-vitals/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "next/core-web-vitals",
"root": true
}
9 changes: 9 additions & 0 deletions test/integration/eslint/config-core-web-vitals/pages/index.js
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
16 changes: 16 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,7 @@ jest.setTimeout(1000 * 60 * 2)

const dirFirstTimeSetup = join(__dirname, '../first-time-setup')
const dirCustomConfig = join(__dirname, '../custom-config')
const dirWebVitalsConfig = join(__dirname, '../config-core-web-vitals')
const dirPluginRecommendedConfig = join(
__dirname,
'../plugin-recommended-config'
Expand Down Expand Up @@ -167,6 +168,21 @@ describe('ESLint', () => {
)
})

test('shows warnings and errors with next/core-web-vitals config', async () => {
const { stdout, stderr } = await nextLint(dirWebVitalsConfig, [], {
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('shows warnings and errors when extending plugin recommended config', async () => {
const { stdout, stderr } = await nextLint(
dirPluginRecommendedConfig,
Expand Down

0 comments on commit 0833f83

Please sign in to comment.