Skip to content

Commit

Permalink
Ensure eslint-config warning/errors are correct (vercel#37760)
Browse files Browse the repository at this point in the history
* Ensure eslint-config warning/errors are correct

* fix tests
  • Loading branch information
ijjk authored and aboqasem committed Jun 18, 2022
1 parent 3bb8c5a commit db10279
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
48 changes: 24 additions & 24 deletions packages/eslint-plugin-next/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ module.exports = {
recommended: {
plugins: ['@next/next'],
rules: {
// Errors
'@next/next/google-font-display': 'error',
'@next/next/google-font-preconnect': 'error',
'@next/next/next-script-for-ga': 'error',
'@next/next/no-before-interactive-script-outside-document': 'error',
'@next/next/no-css-tags': 'error',
'@next/next/no-head-element': 'error',
'@next/next/no-html-link-for-pages': 'error',
'@next/next/no-img-element': 'error',
'@next/next/no-page-custom-font': 'error',
'@next/next/no-styled-jsx-in-document': 'error',
'@next/next/no-sync-scripts': 'error',
'@next/next/no-title-in-document-head': 'error',
'@next/next/no-typos': 'error',
'@next/next/no-unwanted-polyfillio': 'error',
// Warnings
'@next/next/inline-script-id': 'warn',
'@next/next/no-document-import-in-page': 'warn',
'@next/next/no-duplicate-head': 'warn',
'@next/next/no-head-import-in-document': 'warn',
'@next/next/no-server-import-in-page': 'warn',
'@next/next/no-script-component-in-head': 'warn',
// warnings
'@next/next/google-font-display': 'warn',
'@next/next/google-font-preconnect': 'warn',
'@next/next/next-script-for-ga': 'warn',
'@next/next/no-before-interactive-script-outside-document': 'warn',
'@next/next/no-css-tags': 'warn',
'@next/next/no-head-element': 'warn',
'@next/next/no-html-link-for-pages': 'warn',
'@next/next/no-img-element': 'warn',
'@next/next/no-page-custom-font': 'warn',
'@next/next/no-styled-jsx-in-document': 'warn',
'@next/next/no-sync-scripts': 'warn',
'@next/next/no-title-in-document-head': 'warn',
'@next/next/no-typos': 'warn',
'@next/next/no-unwanted-polyfillio': 'warn',
// errors
'@next/next/inline-script-id': 'error',
'@next/next/no-document-import-in-page': 'error',
'@next/next/no-duplicate-head': 'error',
'@next/next/no-head-import-in-document': 'error',
'@next/next/no-server-import-in-page': 'error',
'@next/next/no-script-component-in-head': 'error',
},
},
'core-web-vitals': {
plugins: ['@next/next'],
extends: ['plugin:@next/next/recommended'],
rules: {
'@next/next/no-html-link-for-pages': 'warn',
'@next/next/no-sync-scripts': 'warn',
'@next/next/no-html-link-for-pages': 'error',
'@next/next/no-sync-scripts': 'error',
},
},
},
Expand Down
26 changes: 14 additions & 12 deletions test/integration/eslint/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ describe('ESLint', () => {
expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces'
)
expect(output).toContain('Error: Synchronous scripts should not be used.')
expect(output).toContain(
'Warning: Synchronous scripts should not be used.'
)
})

test('invalid older eslint version', async () => {
Expand Down Expand Up @@ -283,11 +285,9 @@ describe('ESLint', () => {

const output = stdout + stderr
expect(output).toContain(
'Error: Do not use `<img>` element. Use `<Image />` from `next/image` instead.'
)
expect(output).toContain(
'Warning: Synchronous scripts should not be used.'
'Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead.'
)
expect(output).toContain('Error: Synchronous scripts should not be used.')
})

test('shows warnings and errors when extending plugin recommended config', async () => {
Expand All @@ -301,9 +301,11 @@ describe('ESLint', () => {
)

const output = stdout + stderr
expect(output).toContain('Error: Synchronous scripts should not be used.')
expect(output).toContain(
'Warning: `<Document />` from `next/document` should not be imported outside of `pages/_document.js`.'
'Warning: Synchronous scripts should not be used.'
)
expect(output).toContain(
'Error: `<Document />` from `next/document` should not be imported outside of `pages/_document.js`.'
)
})

Expand All @@ -319,11 +321,9 @@ describe('ESLint', () => {

const output = stdout + stderr
expect(output).toContain(
'Error: Do not use `<img>` element. Use `<Image />` from `next/image` instead.'
)
expect(output).toContain(
'Warning: Synchronous scripts should not be used.'
'Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead.'
)
expect(output).toContain('Error: Synchronous scripts should not be used.')
})

test('success message when no warnings or errors', async () => {
Expand Down Expand Up @@ -403,7 +403,9 @@ describe('ESLint', () => {
expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces'
)
expect(output).toContain('Error: Synchronous scripts should not be used.')
expect(output).toContain(
'Warning: Synchronous scripts should not be used.'
)
})

test('max warnings flag errors when warnings exceed threshold', async () => {
Expand Down

0 comments on commit db10279

Please sign in to comment.