Skip to content

Commit

Permalink
Add @next/next/no-unwanted-polyfillio rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tusbar committed Mar 31, 2021
1 parent ffbf0ca commit cb07706
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function Page() {
return (
<div>
<script
async
defer
src='https://polyfill.io/v3/polyfill.min.js?features=something-that-will-never-exist'
/>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Page() {
return (
<div>
<script async defer src='https://polyfill.io/v3/polyfill.min.js?features=es2019' />
</div>
)
}
16 changes: 16 additions & 0 deletions __tests__/next.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ describe('@next/next/no-sync-scripts', () => {
expect(result.messages[0].message).toBe('A synchronous script tag can impact your webpage\'s performance')
})
})

describe('@next/next/no-unwanted-polyfillio', () => {
it('correct', async () => {
const result = await lintFixture('@next/next/no-unwanted-polyfillio.correct.js')

expect(result.errorCount).toBe(0)
})

it('incorrect', async () => {
const result = await lintFixture('@next/next/no-unwanted-polyfillio.incorrect.js')

expect(result.messages).toHaveLength(1)
expect(result.messages[0].ruleId).toBe('@next/next/no-unwanted-polyfillio')
expect(result.messages[0].message).toBe('You\'re requesting polyfills from polyfill.io which are already shipped with NextJS. Please remove es2019 from the features list.')
})
})
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = {

// Next.js
'@next/next/no-css-tags': 'error',
'@next/next/no-sync-scripts': 'error'
'@next/next/no-sync-scripts': 'error',
'@next/next/no-unwanted-polyfillio': 'error'
}
}

0 comments on commit cb07706

Please sign in to comment.