Unverified Commit 5211ac5c authored by Michael Novotny's avatar Michael Novotny Committed by GitHub

Adds consistency to ESLint rules. (#34335)

* Adds consistency to ESLint rules.

* Fixes lint errors.

* Fixes manifest.

* Adds missing title.

* Fixes copy / paste error.
Co-authored-by: 's avatarLee Robinson <me@leerob.io>

* Update errors/no-script-in-document.md
Co-authored-by: 's avatarLee Robinson <me@leerob.io>

* Update errors/no-sync-scripts.md
Co-authored-by: 's avatarLee Robinson <me@leerob.io>

* Updates a couple of rule descriptions.

* Adds redirects.

* Fixes unit tests.

* Removes duplicated section.

* Updates `no-before-interactive-script-outside-document` description.

* Fixes lint.

* Fixes integration tests.

* Adds description to `no-before-interactive-script-outside-document` documentation.

* Removes `link-passhref` from rules list.

* Updates remaining `pages/_middleware.js` references.

* Adds consistancy to messaging in new `no-styled-jsx-in-document` rule.

* Apply suggestions from code review

* Apply suggestions from code review
Co-authored-by: 's avatarLee Robinson <me@leerob.io>
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent ec4df713
...@@ -80,28 +80,31 @@ This will take precedence over the configuration from `next.config.js`. ...@@ -80,28 +80,31 @@ This will take precedence over the configuration from `next.config.js`.
Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/package/@next/eslint-plugin-next), already bundled within the base configuration that makes it possible to catch common issues and problems in a Next.js application. The full set of rules is as follows: Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/package/@next/eslint-plugin-next), already bundled within the base configuration that makes it possible to catch common issues and problems in a Next.js application. The full set of rules is as follows:
| | Rule | Description |
| :-: | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| ✔️ | [next/google-font-display](/docs/messages/google-font-display.md) | Enforce optional or swap font-display behavior with Google Fonts |
| ✔️ | [next/google-font-preconnect](/docs/messages/google-font-preconnect.md) | Enforce preconnect usage with Google Fonts |
| ✔️ | [next/link-passhref](/docs/messages/link-passhref.md) | Enforce passHref prop usage with custom Link components |
| ✔️ | [next/no-css-tags](/docs/messages/no-css-tags.md) | Prevent manual stylesheet tags |
| ✔️ | [next/no-document-import-in-page](/docs/messages/no-document-import-in-page.md) | Disallow importing next/document outside of pages/document.js |
| ✔️ | [next/no-head-import-in-document](/docs/messages/no-head-import-in-document.md) | Disallow importing next/head in pages/document.js |
| ✔️ | [next/no-html-link-for-pages](/docs/messages/no-html-link-for-pages.md) | Prohibit HTML anchor links to pages without a Link component |
| ✔️ | [next/no-img-element](/docs/messages/no-img-element.md) | Prohibit usage of HTML &lt;img&gt; element |
| ✔️ | [next/no-head-element](/docs/messages/no-head-element.md) | Prohibit usage of HTML &lt;head&gt; element |
| ✔️ | [next/no-page-custom-font](/docs/messages/no-page-custom-font.md) | Prevent page-only custom fonts |
| ✔️ | [next/no-sync-scripts](/docs/messages/no-sync-scripts.md) | Forbid synchronous scripts |
| ✔️ | [next/no-title-in-document-head](/docs/messages/no-title-in-document-head.md) | Disallow using &lt;title&gt; with Head from next/document |
| ✔️ | [next/no-unwanted-polyfillio](/docs/messages/no-unwanted-polyfillio.md) | Prevent duplicate polyfills from Polyfill.io |
| ✔️ | [next/inline-script-id](/docs/messages/inline-script-id.md) | Enforce id attribute on next/script components with inline content |
| ✔️ | next/no-typos | Ensure no typos were made declaring [Next.js's data fetching function](/docs/basic-features/data-fetching/overview.md) |
| ✔️ | [next/next-script-for-ga](/docs/messages/next-script-for-ga.md) | Use the Script component to defer loading of the script until necessary. |
| ✔️ | [next/no-styled-jsx-in-document](/docs/messages/no-styled-jsx-in-document.md) | styled-jsx should not be used in \_document |
- ✔: Enabled in the recommended configuration - ✔: Enabled in the recommended configuration
| | Rule | Description |
| :-: | --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| ✔️ | [@next/next/google-font-display](/docs/messages/google-font-display.md) | Enforce font-display behavior with Google Fonts. |
| ✔️ | [@next/next/google-font-preconnect](/docs/messages/google-font-preconnect.md) | Ensure `preconnect` is used with Google Fonts. |
| ✔️ | [@next/next/inline-script-id](/docs/messages/inline-script-id.md) | Enforce `id` attribute on `next/script` components with inline content. |
| ✔️ | [@next/next/next-script-for-ga](/docs/messages/next-script-for-ga.md) | Prefer `next/script` component when using the inline script for Google Analytics. |
| ✔️ | [@next/next/no-before-interactive-script-outside-document](/docs/messages/no-before-interactive-script-outside-document.md) | Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`. |
| ✔️ | [@next/next/no-css-tags](/docs/messages/no-css-tags.md) | Prevent manual stylesheet tags. |
| ✔️ | [@next/next/no-document-import-in-page](/docs/messages/no-document-import-in-page.md) | Prevent importing `next/document` outside of `pages/_document.js`. |
| ✔️ | [@next/next/no-duplicate-head](/docs/messages/no-duplicate-head.md) | Prevent duplicate usage of `<Head>` in `pages/_document.js`. |
| ✔️ | [@next/next/no-head-element](/docs/messages/no-head-element.md) | Prevent usage of `<head>` element. |
| ✔️ | [@next/next/no-head-import-in-document](/docs/messages/no-head-import-in-document.md) | Prevent usage of `next/head` in `pages/_document.js`. |
| ✔️ | [@next/next/no-html-link-for-pages](/docs/messages/no-html-link-for-pages.md) | Prevent usage of `<a>` elements to navigate to internal Next.js pages. |
| ✔️ | [@next/next/no-img-element](/docs/messages/no-img-element.md) | Prevent usage of `<img>` element to prevent layout shift. |
| ✔️ | [@next/next/no-page-custom-font](/docs/messages/no-page-custom-font.md) | Prevent page-only custom fonts. |
| ✔️ | [@next/next/no-script-component-in-head](/docs/messages/no-script-component-in-head.md) | Prevent usage of `next/script` in `next/head` component. |
| ✔️ | [@next/next/no-server-import-in-page](/docs/messages/no-server-import-in-page.md) | Prevent usage of `next/server` outside of `middleware.js`. |
| ✔️ | [@next/next/no-styled-jsx-in-document](/docs/messages/no-styled-jsx-in-document.md) | Prevent usage of `styled-jsx` in `pages/_document.js`. |
| ✔️ | [@next/next/no-sync-scripts](/docs/messages/no-sync-scripts.md) | Prevent synchronous scripts. |
| ✔️ | [@next/next/no-title-in-document-head](/docs/messages/no-title-in-document-head.md) | Prevent usage of `<title>` with `Head` component from `next/document`. |
| ✔️ | @next/next/no-typos | Prevent common typos in [Next.js's data fetching functions](/docs/basic-features/data-fetching.md) |
| ✔️ | [@next/next/no-unwanted-polyfillio](/docs/messages/no-unwanted-polyfillio.md) | Prevent duplicate polyfills from Polyfill.io. |
If you already have ESLint configured in your application, we recommend extending from this plugin directly instead of including `eslint-config-next` unless a few conditions are met. Refer to the [Recommended Plugin Ruleset](/docs/basic-features/eslint.md#recommended-plugin-ruleset) to learn more. If you already have ESLint configured in your application, we recommend extending from this plugin directly instead of including `eslint-config-next` unless a few conditions are met. Refer to the [Recommended Plugin Ruleset](/docs/basic-features/eslint.md#recommended-plugin-ruleset) to learn more.
### Custom Settings ### Custom Settings
......
# Google Font Display # Google Font Display
> Enforce font-display behavior with Google Fonts.
### Why This Error Occurred ### Why This Error Occurred
For a Google Font, the `display` descriptor was either not assigned or set to `auto`, `fallback`, or `block`. For a Google Font, the font-display descriptor was either missing or set to `auto`, `block`, or `fallback`, which are not recommended.
### Possible Ways to Fix It ### Possible Ways to Fix It
...@@ -29,9 +31,10 @@ Specifying `display=optional` minimizes the risk of invisible text or layout shi ...@@ -29,9 +31,10 @@ Specifying `display=optional` minimizes the risk of invisible text or layout shi
### When Not To Use It ### When Not To Use It
If you want to specifically display a font using a `block` or `fallback` strategy, then you can disable this rule. If you want to specifically display a font using an `auto`, `block`, or `fallback` strategy, then you can disable this rule.
### Useful Links ### Useful Links
- [Controlling Font Performance with font-display](https://developer.chrome.com/blog/font-display/)
- [Google Fonts API Docs](https://developers.google.com/fonts/docs/css2#use_font-display) - [Google Fonts API Docs](https://developers.google.com/fonts/docs/css2#use_font-display)
- [CSS `font-display` property](https://www.w3.org/TR/css-fonts-4/#font-display-desc) - [CSS `font-display` property](https://www.w3.org/TR/css-fonts-4/#font-display-desc)
# Google Font Preconnect # Google Font Preconnect
> Ensure `preconnect` is used with Google Fonts.
### Why This Error Occurred ### Why This Error Occurred
A preconnect resource hint was not used with a request to the Google Fonts domain. Adding `preconnect` is recommended to initiate an early connection to the origin. A preconnect resource hint was not used with a request to the Google Fonts domain. Adding `preconnect` is recommended to initiate an early connection to the origin.
......
# next/script components with inline content require an `id` attribute # Inline script id
> Enforce `id` attribute on `next/script` components with inline content.
## Why This Error Occurred ## Why This Error Occurred
......
# Link passHref # Link `passHref`
> Ensure `passHref` is used with custom `Link` components.
### Why This Error Occurred ### Why This Error Occurred
......
...@@ -563,16 +563,34 @@ ...@@ -563,16 +563,34 @@
"path": "/errors/sharp-version-avif.md" "path": "/errors/sharp-version-avif.md"
}, },
{ {
"title": "script-in-document-page", "path": "/errors/no-script-in-document-page.md",
"path": "/errors/no-script-in-document-page.md" "redirect": {
"destination": "/errors/no-script-in-document"
}
},
{
"title": "no-script-in-document",
"path": "/errors/no-script-in-document.md"
}, },
{ {
"title": "before-interactive-script-outside-document", "title": "before-interactive-script-outside-document",
"path": "/errors/no-before-interactive-script-outside-document.md" "path": "/errors/no-before-interactive-script-outside-document.md"
}, },
{ {
"title": "script-component-in-head-component", "path": "/errors/no-script-in-head-component.md",
"path": "/errors/no-script-component-in-head-component.md" "redirect": {
"destination": "/errors/no-script-component-in-head"
}
},
{
"path": "/errors/no-script-component-in-head-component.md",
"redirect": {
"destination": "/errors/no-script-component-in-head"
}
},
{
"title": "no-script-component-in-head",
"path": "/errors/no-script-component-in-head.md"
}, },
{ {
"title": "script-tags-in-head-component", "title": "script-tags-in-head-component",
......
# Next Script for Google Analytics # Next Script for Google Analytics
> Prefer `next/script` component when using the inline script for Google Analytics.
### Why This Error Occurred ### Why This Error Occurred
An inline script was used for Google analytics which might impact your webpage's performance. An inline script was used for Google analytics which might impact your webpage's performance.
......
# beforeInteractive Script component outside \_document.js # No Before Interactive Script Outside Document
> Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`.
#### Why This Error Occurred #### Why This Error Occurred
You can't use the `next/script` component with the `beforeInteractive` strategy outside the `_document.js` page. That's because `beforeInteractive` strategy only works inside **\_document.js** and is designed to load scripts that are needed by the entire site (i.e. the script will load when any page in the application has been loaded server-side). You cannot use the `next/script` component with the `beforeInteractive` strategy outside `pages/_document.js`. That's because `beforeInteractive` strategy only works inside **`pages/_document.js`** and is designed to load scripts that are needed by the entire site (i.e. the script will load when any page in the application has been loaded server-side).
#### Possible Ways to Fix It #### Possible Ways to Fix It
If you want a global script, move the script inside `_document.js` page. If you want a global script, move the script inside `pages/_document.js`.
```jsx ```jsx
// In _document.js // In `pages/_document.js`
import { Html, Head, Main, NextScript } from 'next/document' import { Html, Head, Main, NextScript } from 'next/document'
import Script from 'next/script' import Script from 'next/script'
......
# No CSS Tags # No CSS Tags
> Prevent manual stylesheet tags.
### Why This Error Occurred ### Why This Error Occurred
An HTML link element was used to link to an external stylesheet. This can negatively affect CSS resource loading on your web page. A `link` element was used to link to an external stylesheet. This can negatively affect CSS resource loading on your webpage.
### Possible Ways to Fix It ### Possible Ways to Fix It
......
# No Document Import in Page # No Document Import in Page
> Prevent importing `next/document` outside of `pages/_document.js`.
### Why This Error Occurred ### Why This Error Occurred
`next/document` was imported in a page outside of `pages/_document.js` (or `pages/_document.tsx` if you are using TypeScript). This can cause unexpected issues in your application. `next/document` was imported in a page outside of `pages/_document.js` (or `pages/_document.tsx` if you are using TypeScript). This can cause unexpected issues in your application.
......
# No Duplicate Head # No Duplicate Head
> Prevent duplicate usage of `<Head>` in `pages/_document.js`.
### Why This Error Occurred ### Why This Error Occurred
More than a single instance of the `<Head />` component was used in a single custom document. This can cause unexpected behavior in your application. More than a single instance of the `<Head />` component was used in a single custom document. This can cause unexpected behavior in your application.
......
# No Head Element # No Head Element
> Prevent usage of `<head>` element.
### Why This Error Occurred ### Why This Error Occurred
An HTML `<head>` element was used to include page-level metadata, but this can cause unexpected behavior in a Next.js application. Use Next.js' built-in `<Head />` component instead. A `<head>` element was used to include page-level metadata, but this can cause unexpected behavior in a Next.js application. Use Next.js' built-in `next/head` component instead.
### Possible Ways to Fix It ### Possible Ways to Fix It
......
# No Head Import in Document # No Head Import in Document
> Prevent usage of `next/head` in `pages/_document.js`.
### Why This Error Occurred ### Why This Error Occurred
`next/head` was imported in `pages/_document.js`. This can cause unexpected issues in your application. `next/head` was imported in `pages/_document.js`. This can cause unexpected issues in your application.
......
# No HTML link for pages # No HTML link for pages
> Prevent usage of `<a>` elements to navigate to internal Next.js pages.
### Why This Error Occurred ### Why This Error Occurred
An HTML anchor element, `<a>`, was used to navigate to a page route without using the `Link` component. An `<a>` element was used to navigate to a page route without using the `next/link` component, causing unnecessary full page refreshes.
The `Link` component is required in order to enable client-side route transitions between pages and provide a single-page app experience. The `Link` component is required in order to enable client-side route transitions between pages and provide a single-page app experience.
......
# No Img Element # No Img Element
> Prevent usage of `<img>` element to prevent layout shift.
### Why This Error Occurred ### Why This Error Occurred
An HTML `<img>` element was used to display an image. For better performance and automatic Image Optimization, use Next.js' built-in image component instead. An `<img>` element was used to display an image. For better performance and automatic Image Optimization, use `next/image` instead.
### Possible Ways to Fix It ### Possible Ways to Fix It
......
# No Page Custom Font # No Page Custom Font
> Prevent page-only custom fonts.
### Why This Error Occurred ### Why This Error Occurred
- The custom font you're adding was added to a page - this only adds the font to the specific page and not the entire application. - The custom font you're adding was added to a page - this only adds the font to the specific page and not the entire application.
- The custom font you're adding was added to a separate component within `Document` - this disables automatic font optimization. - The custom font you're adding was added to a separate component within `pages/_document.js` - this disables automatic font optimization.
### Possible Ways to Fix It ### Possible Ways to Fix It
......
# Script component inside Head component # No Script Component in Head
> Prevent usage of `next/script` in `next/head` component.
#### Why This Error Occurred #### Why This Error Occurred
The `next/script` component shouldn't be placed inside the `next/head` component The `next/script` component should not be used in a `next/head` component.
#### Possible Ways to Fix It #### Possible Ways to Fix It
Move the `<Script />` component outside of `<Head>...</Head>` Move the `<Script />` component outside of `<Head>` instead.
**Before** **Before**
......
# Script component inside \_document.js # No Script in Document
> ⚠️ This error is not relevant in versions 12.1.6 or later. Please refer to the updated [error message](https://nextjs.org/docs/messages/no-before-interactive-script-outside-document). > Prevent usage of `next/script` in `pages/_document.js`.
> ⚠️ This error is not relevant in Next.js versions 12.1.6 or later. Please refer to the updated [error message](https://nextjs.org/docs/messages/no-before-interactive-script-outside-document).
#### Why This Error Occurred #### Why This Error Occurred
You can't use the `next/script` component inside the `_document.js` page in versions prior to v12.1.6. That's because the `_document.js` page only runs on the server and `next/script` has client-side functionality to ensure loading order. You should not use the `next/script` component in `pages/_document.js` in Next.js versions prior to 12.1.6. That's because the `pages/_document.js` page only runs on the server and `next/script` has client-side functionality to ensure loading order.
#### Possible Ways to Fix It #### Possible Ways to Fix It
If you want a global script, instead use the `_app.js` page. If you want a global script, use `next/script` in `pages/_app.js` instead.
```jsx ```jsx
import Script from 'next/script' import Script from 'next/script'
......
# No Server Import In Page # No Server Import In Page
> Prevent usage of `next/server` outside of `middleware.js`.
### Why This Error Occurred ### Why This Error Occurred
`next/server` was imported outside of `middleware.{js,ts}`. `next/server` was imported outside of `middleware.{js,ts}`.
......
# No styled-jsx in Document # No styled-jsx in Document
> Prevent usage of `styled-jsx` in `pages/_document.js`.
### Why This Error Occurred ### Why This Error Occurred
Custom CSS like `styled-jsx` is not allowed in a [Custom Document](https://nextjs.org/docs/advanced-features/custom-document). Custom CSS like `styled-jsx` is not allowed in a [Custom Document](https://nextjs.org/docs/advanced-features/custom-document).
......
# No Sync Scripts # No Sync Scripts
> Prevent synchronous scripts.
### Why This Error Occurred ### Why This Error Occurred
A synchronous script was used which can impact your webpage's performance. A synchronous script was used which can impact your webpage performance.
### Possible Ways to Fix It ### Possible Ways to Fix It
#### Script component (experimental) #### Script component (recommended)
Use the Script component with the right loading strategy to defer loading of the script until necessary.
```jsx ```jsx
import Script from 'next/script' import Script from 'next/script'
...@@ -25,6 +25,13 @@ function Home() { ...@@ -25,6 +25,13 @@ function Home() {
export default Home export default Home
``` ```
#### Use `async` or `defer`
```html
<script src="https://third-party-script.js" async />
<script src="https://third-party-script.js" defer />
```
### Useful Links ### Useful Links
- [Efficiently load third-party JavaScript](https://web.dev/efficiently-load-third-party-javascript/) - [Efficiently load third-party JavaScript](https://web.dev/efficiently-load-third-party-javascript/)
# No Title in Document Head # No Title in Document Head
> Prevent usage of `<title>` with `Head` component from `next/document`.
### Why This Error Occurred ### Why This Error Occurred
A `<title>` element was defined within the `Head` component imported from `next/document`, which should only be used for any `<head>` code that is common for all pages. Title tags should be defined at the page-level using `next/head`. A `<title>` element was defined within the `Head` component imported from `next/document`, which should only be used for any `<head>` code that is common for all pages. Title tags should be defined at the page-level using `next/head` instead.
### Possible Ways to Fix It ### Possible Ways to Fix It
......
# Duplicate Polyfills from Polyfill.io # No Unwanted Polyfill.io
> Prevent duplicate polyfills from Polyfill.io.
#### Why This Error Occurred #### Why This Error Occurred
You are using Polyfill.io and including duplicate polyfills already shipped with Next.js. This increases page weight unnecessarily which can affect loading performance. You are using polyfills from Polyfill.io and including polyfills already shipped with Next.js. This unnecessarily increases page weight which can affect loading performance.
#### Possible Ways to Fix It #### Possible Ways to Fix It
Remove all duplicate polyfills that are included with Polyfill.io. If you need to add polyfills but are not sure if Next.js already includes it, take a look at the list of [supported browsers and features](https://nextjs.org/docs/basic-features/supported-browsers-features) first. Remove all duplicate polyfills. If you need to add polyfills but are not sure if Next.js already includes it, take a look at the list of [supported browsers and features](https://nextjs.org/docs/basic-features/supported-browsers-features).
### Useful Links ### Useful Links
......
module.exports = { module.exports = {
rules: { rules: {
'no-css-tags': require('./rules/no-css-tags'),
'no-sync-scripts': require('./rules/no-sync-scripts'),
'no-html-link-for-pages': require('./rules/no-html-link-for-pages'),
'no-img-element': require('./rules/no-img-element'),
'no-head-element': require('./rules/no-head-element'),
'no-unwanted-polyfillio': require('./rules/no-unwanted-polyfillio'),
'no-page-custom-font': require('./rules/no-page-custom-font'),
'no-title-in-document-head': require('./rules/no-title-in-document-head'),
'google-font-display': require('./rules/google-font-display'), 'google-font-display': require('./rules/google-font-display'),
'google-font-preconnect': require('./rules/google-font-preconnect'), 'google-font-preconnect': require('./rules/google-font-preconnect'),
'inline-script-id': require('./rules/inline-script-id'),
'next-script-for-ga': require('./rules/next-script-for-ga'),
'no-before-interactive-script-outside-document': require('./rules/no-before-interactive-script-outside-document'),
'no-css-tags': require('./rules/no-css-tags'),
'no-document-import-in-page': require('./rules/no-document-import-in-page'), 'no-document-import-in-page': require('./rules/no-document-import-in-page'),
'no-duplicate-head': require('./rules/no-duplicate-head'),
'no-head-element': require('./rules/no-head-element'),
'no-head-import-in-document': require('./rules/no-head-import-in-document'), 'no-head-import-in-document': require('./rules/no-head-import-in-document'),
'no-html-link-for-pages': require('./rules/no-html-link-for-pages'),
'no-img-element': require('./rules/no-img-element'),
'no-page-custom-font': require('./rules/no-page-custom-font'),
'no-script-component-in-head': require('./rules/no-script-component-in-head'), 'no-script-component-in-head': require('./rules/no-script-component-in-head'),
'no-server-import-in-page': require('./rules/no-server-import-in-page'), 'no-server-import-in-page': require('./rules/no-server-import-in-page'),
'no-styled-jsx-in-document': require('./rules/no-styled-jsx-in-document'), 'no-styled-jsx-in-document': require('./rules/no-styled-jsx-in-document'),
'no-sync-scripts': require('./rules/no-sync-scripts'),
'no-title-in-document-head': require('./rules/no-title-in-document-head'),
'no-typos': require('./rules/no-typos'), 'no-typos': require('./rules/no-typos'),
'no-duplicate-head': require('./rules/no-duplicate-head'), 'no-unwanted-polyfillio': require('./rules/no-unwanted-polyfillio'),
'inline-script-id': require('./rules/inline-script-id'),
'next-script-for-ga': require('./rules/next-script-for-ga'),
'no-before-interactive-script-outside-document': require('./rules/no-before-interactive-script-outside-document'),
'no-assign-module-variable': require('./rules/no-assign-module-variable'),
}, },
configs: { configs: {
recommended: { recommended: {
plugins: ['@next/next'], plugins: ['@next/next'],
rules: { rules: {
'@next/next/no-css-tags': 1, // Errors
'@next/next/no-sync-scripts': 1, '@next/next/google-font-display': 'error',
'@next/next/no-html-link-for-pages': 1, '@next/next/google-font-preconnect': 'error',
'@next/next/no-img-element': 1, '@next/next/next-script-for-ga': 'error',
'@next/next/no-head-element': 1, '@next/next/no-before-interactive-script-outside-document': 'error',
'@next/next/no-unwanted-polyfillio': 1, '@next/next/no-css-tags': 'error',
'@next/next/no-page-custom-font': 1, '@next/next/no-head-element': 'error',
'@next/next/no-title-in-document-head': 1, '@next/next/no-html-link-for-pages': 'error',
'@next/next/google-font-display': 1, '@next/next/no-img-element': 'error',
'@next/next/google-font-preconnect': 1, '@next/next/no-page-custom-font': 'error',
'@next/next/next-script-for-ga': 1, '@next/next/no-styled-jsx-in-document': 'error',
'@next/next/no-document-import-in-page': 2, '@next/next/no-sync-scripts': 'error',
'@next/next/no-head-import-in-document': 2, '@next/next/no-title-in-document-head': 'error',
'@next/next/no-script-component-in-head': 2, '@next/next/no-typos': 'error',
'@next/next/no-styled-jsx-in-document': 2, '@next/next/no-unwanted-polyfillio': 'error',
'@next/next/no-server-import-in-page': 2, // Warnings
'@next/next/no-typos': 1, '@next/next/inline-script-id': 'warn',
'@next/next/no-duplicate-head': 2, '@next/next/no-document-import-in-page': 'warn',
'@next/next/inline-script-id': 2, '@next/next/no-duplicate-head': 'warn',
'@next/next/no-before-interactive-script-outside-document': 1, '@next/next/no-head-import-in-document': 'warn',
'@next/next/no-assign-module-variable': 2, '@next/next/no-server-import-in-page': 'warn',
'@next/next/no-script-component-in-head': 'warn',
}, },
}, },
'core-web-vitals': { 'core-web-vitals': {
plugins: ['@next/next'], plugins: ['@next/next'],
extends: ['plugin:@next/next/recommended'], extends: ['plugin:@next/next/recommended'],
rules: { rules: {
'@next/next/no-sync-scripts': 2, '@next/next/no-html-link-for-pages': 'warn',
'@next/next/no-html-link-for-pages': 2, '@next/next/no-sync-scripts': 'warn',
}, },
}, },
}, },
......
const NodeAttributes = require('../utils/node-attributes.js') const NodeAttributes = require('../utils/node-attributes.js')
const url = 'https://nextjs.org/docs/messages/google-font-display'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: description: 'Enforce font-display behavior with Google Fonts.',
'Ensure correct font-display property is assigned for Google Fonts',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/google-font-display', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -33,22 +34,23 @@ module.exports = { ...@@ -33,22 +34,23 @@ module.exports = {
const displayValue = params.get('display') const displayValue = params.get('display')
if (!params.has('display')) { if (!params.has('display')) {
message = 'Display parameter is missing.' message =
'A font-display parameter is missing (adding `&display=optional` is recommended).'
} else if ( } else if (
displayValue === 'auto' ||
displayValue === 'block' || displayValue === 'block' ||
displayValue === 'fallback' || displayValue === 'fallback'
displayValue === 'auto'
) { ) {
message = `${ message = `${
displayValue[0].toUpperCase() + displayValue.slice(1) displayValue[0].toUpperCase() + displayValue.slice(1)
} behavior is not recommended.` } is not recommended.`
} }
} }
if (message) { if (message) {
context.report({ context.report({
node, node,
message: `${message} See: https://nextjs.org/docs/messages/google-font-display`, message: `${message} See: ${url}`,
}) })
} }
}, },
......
const NodeAttributes = require('../utils/node-attributes.js') const NodeAttributes = require('../utils/node-attributes.js')
const url = 'https://nextjs.org/docs/messages/google-font-preconnect'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Ensure preconnect is used with Google Fonts', description: 'Ensure `preconnect` is used with Google Fonts.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/google-font-preconnect', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -33,7 +35,7 @@ module.exports = { ...@@ -33,7 +35,7 @@ module.exports = {
) { ) {
context.report({ context.report({
node, node,
message: `Preconnect is missing. See: https://nextjs.org/docs/messages/google-font-preconnect`, message: `\`rel="preconnect"\` is missing from Google Font. See: ${url}`,
}) })
} }
}, },
......
const url = 'https://nextjs.org/docs/messages/inline-script-id'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: description:
'next/script components with inline content must specify an `id` attribute.', 'Enforce `id` attribute on `next/script` components with inline content.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/inline-script-id', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -59,8 +61,7 @@ module.exports = { ...@@ -59,8 +61,7 @@ module.exports = {
if (!attributeNames.has('id')) { if (!attributeNames.has('id')) {
context.report({ context.report({
node, node,
message: message: `\`next/script\` components with inline content must specify an \`id\` attribute. See: ${url}`,
'next/script components with inline content must specify an `id` attribute. See: https://nextjs.org/docs/messages/inline-script-id',
}) })
} }
} }
......
...@@ -8,8 +8,10 @@ const SUPPORTED_HTML_CONTENT_URLS = [ ...@@ -8,8 +8,10 @@ const SUPPORTED_HTML_CONTENT_URLS = [
'www.google-analytics.com/analytics.js', 'www.google-analytics.com/analytics.js',
'www.googletagmanager.com/gtm.js', 'www.googletagmanager.com/gtm.js',
] ]
const ERROR_MSG = const description =
'Use the `next/script` component for loading third party scripts. See: https://nextjs.org/docs/messages/next-script-for-ga' 'Prefer `next/script` component when using the inline script for Google Analytics.'
const url = 'https://nextjs.org/docs/messages/next-script-for-ga'
const ERROR_MSG = `${description} See: ${url}`
// Check if one of the items in the list is a substring of the passed string // Check if one of the items in the list is a substring of the passed string
const containsStr = (str, strList) => { const containsStr = (str, strList) => {
...@@ -19,12 +21,12 @@ const containsStr = (str, strList) => { ...@@ -19,12 +21,12 @@ const containsStr = (str, strList) => {
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: description,
'Prefer next script component when using the inline script for Google Analytics',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/next-script-for-ga', url,
}, },
}, },
schema: [],
create: function (context) { create: function (context) {
return { return {
JSXOpeningElement(node) { JSXOpeningElement(node) {
...@@ -74,5 +76,3 @@ module.exports = { ...@@ -74,5 +76,3 @@ module.exports = {
} }
}, },
} }
module.exports.schema = []
const path = require('path') const path = require('path')
const url =
'https://nextjs.org/docs/messages/no-before-interactive-script-outside-document'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: description:
'Disallow using next/script beforeInteractive strategy outside the next/_document component', "Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`.",
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-before-interactive-script-outside-document', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -46,8 +49,7 @@ module.exports = { ...@@ -46,8 +49,7 @@ module.exports = {
context.report({ context.report({
node, node,
message: message: `\`next/script\`'s \`beforeInteractive\` strategy should not be used outside of \`pages/_document.js\`. See: ${url}`,
'next/script beforeInteractive strategy should only be used inside next/_document. See: https://nextjs.org/docs/messages/no-before-interactive-script-outside-document',
}) })
}, },
} }
......
module.exports = function (context) { const url = 'https://nextjs.org/docs/messages/no-css-tags'
return {
JSXOpeningElement(node) {
if (node.name.name !== 'link') {
return
}
if (node.attributes.length === 0) {
return
}
const attributes = node.attributes.filter( module.exports = {
(attr) => attr.type === 'JSXAttribute' meta: {
) docs: {
if ( description: 'Prevent manual stylesheet tags.',
attributes.find( recommended: true,
(attr) => url,
attr.name.name === 'rel' && attr.value.value === 'stylesheet'
) &&
attributes.find(
(attr) =>
attr.name.name === 'href' &&
attr.value.type === 'Literal' &&
!/^https?/.test(attr.value.value)
)
) {
context.report({
node,
message:
'Do not include stylesheets manually. See: https://nextjs.org/docs/messages/no-css-tags',
})
}
}, },
} },
} schema: [],
create: function (context) {
return {
JSXOpeningElement(node) {
if (node.name.name !== 'link') {
return
}
if (node.attributes.length === 0) {
return
}
module.exports.schema = [] const attributes = node.attributes.filter(
(attr) => attr.type === 'JSXAttribute'
)
if (
attributes.find(
(attr) =>
attr.name.name === 'rel' && attr.value.value === 'stylesheet'
) &&
attributes.find(
(attr) =>
attr.name.name === 'href' &&
attr.value.type === 'Literal' &&
!/^https?/.test(attr.value.value)
)
) {
context.report({
node,
message: `Do not include stylesheets manually. See: ${url}`,
})
}
},
}
},
}
const path = require('path') const path = require('path')
const url = 'https://nextjs.org/docs/messages/no-document-import-in-page'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: description:
'Disallow importing next/document outside of pages/document.js', 'Prevent importing `next/document` outside of `pages/_document.js`.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-document-import-in-page', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -29,7 +31,7 @@ module.exports = { ...@@ -29,7 +31,7 @@ module.exports = {
context.report({ context.report({
node, node,
message: `next/document should not be imported outside of pages/_document.js. See: https://nextjs.org/docs/messages/no-document-import-in-page`, message: `\`<Document />\` from \`next/document\` should not be imported outside of \`pages/_document.js\`. See: ${url}`,
}) })
}, },
} }
......
const url = 'https://nextjs.org/docs/messages/no-duplicate-head'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Enforce no duplicate usage of <Head> in pages/document.js', description:
'Prevent duplicate usage of `<Head>` in `pages/_document.js`.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-duplicate-head', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -44,8 +47,7 @@ module.exports = { ...@@ -44,8 +47,7 @@ module.exports = {
for (let i = 1; i < headComponents.length; i++) { for (let i = 1; i < headComponents.length; i++) {
context.report({ context.report({
node: headComponents[i], node: headComponents[i],
message: message: `Do not include multiple instances of \`<Head/>\`. See: ${url}`,
'Do not include multiple instances of <Head/>. See: https://nextjs.org/docs/messages/no-duplicate-head',
}) })
} }
} }
......
const url = 'https://nextjs.org/docs/messages/no-head-element'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Prohibit usage of HTML <head> element', description: 'Prevent usage of `<head>` element.',
category: 'HTML', category: 'HTML',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-head-element', url,
}, },
fixable: 'code', fixable: 'code',
}, },
create: function (context) { create: function (context) {
return { return {
JSXOpeningElement(node) { JSXOpeningElement(node) {
...@@ -18,7 +19,7 @@ module.exports = { ...@@ -18,7 +19,7 @@ module.exports = {
context.report({ context.report({
node, node,
message: `Do not use <head>. Use Head from 'next/head' instead. See: https://nextjs.org/docs/messages/no-head-element`, message: `Do not use \`<head>\` element. Use \`<Head />\` from \`next/head\` instead. See: ${url}`,
}) })
}, },
} }
......
const path = require('path') const path = require('path')
const url = 'https://nextjs.org/docs/messages/no-head-import-in-document'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Disallow importing next/head in pages/document.js', description: 'Prevent usage of `next/head` in `pages/_document.js`.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-head-import-in-document', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -28,7 +30,7 @@ module.exports = { ...@@ -28,7 +30,7 @@ module.exports = {
) { ) {
context.report({ context.report({
node, node,
message: `next/head should not be imported in pages${document}. Import Head from next/document instead. See: https://nextjs.org/docs/messages/no-head-import-in-document`, message: `\`next/head\` should not be imported in \`pages${document}\`. Use \`<Head />\` from \`next/document\` instead. See: ${url}`,
}) })
} }
}, },
......
...@@ -11,7 +11,7 @@ const { ...@@ -11,7 +11,7 @@ const {
const pagesDirWarning = execOnce((pagesDirs) => { const pagesDirWarning = execOnce((pagesDirs) => {
console.warn( console.warn(
`Pages directory cannot be found at ${pagesDirs.join(' or ')}. ` + `Pages directory cannot be found at ${pagesDirs.join(' or ')}. ` +
`If using a custom path, please configure with the no-html-link-for-pages rule in your eslint config file` 'If using a custom path, please configure with the `no-html-link-for-pages` rule in your eslint config file.'
) )
}) })
...@@ -19,13 +19,16 @@ const pagesDirWarning = execOnce((pagesDirs) => { ...@@ -19,13 +19,16 @@ const pagesDirWarning = execOnce((pagesDirs) => {
// Prevent multiple blocking IO requests that have already been calculated. // Prevent multiple blocking IO requests that have already been calculated.
const fsExistsSyncCache = {} const fsExistsSyncCache = {}
const url = 'https://nextjs.org/docs/messages/no-html-link-for-pages'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Prohibit full page refresh for Next.js pages', description:
'Prevent usage of `<a>` elements to navigate to internal Next.js pages.',
category: 'HTML', category: 'HTML',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-html-link-for-pages', url,
}, },
fixable: null, // or "code" or "whitespace" fixable: null, // or "code" or "whitespace"
schema: [ schema: [
...@@ -79,7 +82,7 @@ module.exports = { ...@@ -79,7 +82,7 @@ module.exports = {
return {} return {}
} }
const urls = getUrlFromPagesDirectories('/', foundPagesDirs) const pageUrls = getUrlFromPagesDirectories('/', foundPagesDirs)
return { return {
JSXOpeningElement(node) { JSXOpeningElement(node) {
if (node.name.name !== 'a') { if (node.name.name !== 'a') {
...@@ -121,11 +124,11 @@ module.exports = { ...@@ -121,11 +124,11 @@ module.exports = {
return return
} }
urls.forEach((url) => { pageUrls.forEach((pageUrl) => {
if (url.test(normalizeURL(hrefPath))) { if (pageUrl.test(normalizeURL(hrefPath))) {
context.report({ context.report({
node, node,
message: `Do not use the HTML <a> tag to navigate to ${hrefPath}. Use Link from 'next/link' instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages`, message: `Do not use an \`<a>\` element to navigate to \`${hrefPath}\`. Use \`<Link />\` from \`next/link\` instead. See: ${url}`,
}) })
} }
}) })
......
const url = 'https://nextjs.org/docs/messages/no-img-element'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Prohibit usage of HTML <img> element', description: 'Prevent usage of `<img>` element to prevent layout shift.',
category: 'HTML', category: 'HTML',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-img-element', url,
}, },
fixable: 'code', fixable: 'code',
}, },
...@@ -22,7 +24,7 @@ module.exports = { ...@@ -22,7 +24,7 @@ module.exports = {
context.report({ context.report({
node, node,
message: `Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element`, message: `Do not use \`<img>\` element. Use \`<Image />\` from \`next/image\` instead. See: ${url}`,
}) })
}, },
} }
......
const NodeAttributes = require('../utils/node-attributes.js') const NodeAttributes = require('../utils/node-attributes.js')
const { sep, posix } = require('path') const { sep, posix } = require('path')
const url = 'https://nextjs.org/docs/messages/no-page-custom-font'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: description: 'Prevent page-only custom fonts.',
'Recommend adding custom font in a custom document and not in a specific page',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-page-custom-font', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -137,12 +138,11 @@ module.exports = { ...@@ -137,12 +138,11 @@ module.exports = {
hrefValue.startsWith('https://fonts.googleapis.com/css') hrefValue.startsWith('https://fonts.googleapis.com/css')
if (isGoogleFont) { if (isGoogleFont) {
const end = const end = `This is discouraged. See: ${url}`
'This is discouraged. See: https://nextjs.org/docs/messages/no-page-custom-font'
const message = is_Document const message = is_Document
? `Rendering this <link /> not inline within <Head> of Document disables font optimization. ${end}` ? `Using \`<link />\` outside of \`<Head>\` will disable automatic font optimization. ${end}`
: `Custom fonts not added at the document level will only load for a single page. ${end}` : `Custom fonts not added in \`pages/_document.js\` will only load for a single page. ${end}`
context.report({ context.report({
node, node,
......
const url =
'https://nextjs.org/docs/messages/no-script-component-in-head-component'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Disallow using next/script inside the next/head component', description: 'Prevent usage of `next/script` in `next/head` component.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-script-component-in-head-component', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -42,8 +45,7 @@ module.exports = { ...@@ -42,8 +45,7 @@ module.exports = {
if (scriptTag) { if (scriptTag) {
context.report({ context.report({
node, node,
message: message: `\`next/script\` should not be used in \`next/head\` component. Move \`<Script />\` outside of \`<Head>\` instead. See: ${url}`,
"next/script shouldn't be used inside next/head. See: https://nextjs.org/docs/messages/no-script-component-in-head-component",
}) })
} }
}, },
......
const path = require('path') const path = require('path')
const url = 'https://nextjs.org/docs/messages/no-server-import-in-page'
const middlewareRegExp = new RegExp(`^middleware\\.(?:t|j)s$`) const middlewareRegExp = new RegExp(`^middleware\\.(?:t|j)s$`)
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Disallow importing next/server outside of middleware', description: 'Prevent usage of `next/server` outside of `middleware.js`.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-server-import-in-page', url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -24,7 +25,7 @@ module.exports = { ...@@ -24,7 +25,7 @@ module.exports = {
context.report({ context.report({
node, node,
message: `next/server should not be imported outside of Middleware. Read more: https://nextjs.org/docs/messages/no-server-import-in-page`, message: `\`next/server\` should not be used outside of \`middleware.js\`. See: ${url}`,
}) })
}, },
} }
......
const path = require('path') const path = require('path')
const url = 'https://nextjs.org/docs/messages/no-styled-jsx-in-document'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Disallow using custom styled-jsx inside pages/_document.js', description: 'Prevent usage of `styled-jsx` in `pages/_document.js`.',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-styled-jsx-in-document', url,
}, },
fixable: 'code', fixable: 'code',
}, },
...@@ -35,7 +37,7 @@ module.exports = { ...@@ -35,7 +37,7 @@ module.exports = {
) { ) {
context.report({ context.report({
node, node,
message: `styled-jsx can not be used inside pages/_document.js. See https://nextjs.org/docs/messages/no-styled-jsx-in-document.`, message: `\`styled-jsx\` should not be used in \`pages/_document.js\`. See: ${url}`,
}) })
} }
}, },
......
module.exports = function (context) { const url = 'https://nextjs.org/docs/messages/no-sync-scripts'
return {
JSXOpeningElement(node) { module.exports = {
if (node.name.name !== 'script') { meta: {
return docs: {
} description: 'Prevent synchronous scripts.',
if (node.attributes.length === 0) { recommended: true,
return url,
}
const attributeNames = node.attributes
.filter((attr) => attr.type === 'JSXAttribute')
.map((attr) => attr.name.name)
if (
attributeNames.includes('src') &&
!attributeNames.includes('async') &&
!attributeNames.includes('defer')
) {
context.report({
node,
message:
'External synchronous scripts are forbidden. See: https://nextjs.org/docs/messages/no-sync-scripts',
})
}
}, },
} },
schema: [],
create: function (context) {
return {
JSXOpeningElement(node) {
if (node.name.name !== 'script') {
return
}
if (node.attributes.length === 0) {
return
}
const attributeNames = node.attributes
.filter((attr) => attr.type === 'JSXAttribute')
.map((attr) => attr.name.name)
if (
attributeNames.includes('src') &&
!attributeNames.includes('async') &&
!attributeNames.includes('defer')
) {
context.report({
node,
message: `Synchronous scripts should not be used. See: ${url}`,
})
}
},
}
},
} }
module.exports.schema = []
const url = 'https://nextjs.org/docs/messages/no-title-in-document-head'
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Disallow using <title> with Head from next/document', description:
url: 'https://nextjs.org/docs/messages/no-title-in-document-head', 'Prevent usage of `<title>` with `Head` component from `next/document`.',
url,
}, },
}, },
create: function (context) { create: function (context) {
...@@ -39,8 +42,7 @@ module.exports = { ...@@ -39,8 +42,7 @@ module.exports = {
if (titleTag) { if (titleTag) {
context.report({ context.report({
node: titleTag, node: titleTag,
message: message: `Do not use \`<title>\` element with \`<Head />\` component from \`next/document\`. Titles should defined at the page-level using \`<Head />\` from \`next/head\` instead. See: ${url}`,
'Titles should be defined at the page-level using next/head. See: https://nextjs.org/docs/messages/no-title-in-document-head',
}) })
} }
}, },
......
...@@ -42,7 +42,7 @@ function minDistance(a, b) { ...@@ -42,7 +42,7 @@ function minDistance(a, b) {
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: 'Prevent common typos', description: 'Prevent common typos in Next.js data fetching functions.',
category: 'Stylistic Issues', category: 'Stylistic Issues',
recommended: true, recommended: true,
}, },
......
...@@ -59,19 +59,20 @@ const NEXT_POLYFILLED_FEATURES = [ ...@@ -59,19 +59,20 @@ const NEXT_POLYFILLED_FEATURES = [
'es7', // Should be covered by babel-preset-env instead. 'es7', // Should be covered by babel-preset-env instead.
] ]
const url = 'https://nextjs.org/docs/messages/no-unwanted-polyfillio'
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Rule Definition // Rule Definition
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
module.exports = { module.exports = {
meta: { meta: {
docs: { docs: {
description: description: 'Prevent duplicate polyfills from Polyfill.io.',
'Prohibit unwanted features to be listed in Polyfill.io tag.',
category: 'HTML', category: 'HTML',
recommended: true, recommended: true,
url: 'https://nextjs.org/docs/messages/no-unwanted-polyfillio', url,
}, },
fixable: null, // or "code" or "whitespace" fixable: null,
}, },
create: function (context) { create: function (context) {
...@@ -118,7 +119,7 @@ module.exports = { ...@@ -118,7 +119,7 @@ module.exports = {
', ' ', '
)} ${ )} ${
unwantedFeatures.length > 1 ? 'are' : 'is' unwantedFeatures.length > 1 ? 'are' : 'is'
} already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio`, } already shipped with Next.js. See: ${url}`,
}) })
} }
} }
......
...@@ -59,7 +59,7 @@ describe('ESLint', () => { ...@@ -59,7 +59,7 @@ describe('ESLint', () => {
const output = stdout + stderr const output = stdout + stderr
expect(output).toContain( expect(output).toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
expect(output).toContain( expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces' 'Error: Comments inside children section of tag should be placed inside braces'
...@@ -90,9 +90,7 @@ describe('ESLint', () => { ...@@ -90,9 +90,7 @@ describe('ESLint', () => {
expect(output).toContain( expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces' 'Error: Comments inside children section of tag should be placed inside braces'
) )
expect(output).toContain( expect(output).toContain('Error: Synchronous scripts should not be used.')
'Warning: External synchronous scripts are forbidden'
)
}) })
test('invalid older eslint version', async () => { test('invalid older eslint version', async () => {
...@@ -121,7 +119,7 @@ describe('ESLint', () => { ...@@ -121,7 +119,7 @@ describe('ESLint', () => {
expect(output).not.toContain('Build error occurred') expect(output).not.toContain('Build error occurred')
expect(output).not.toContain('NoFilesFoundError') expect(output).not.toContain('NoFilesFoundError')
expect(output).toContain( expect(output).toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
expect(output).toContain('Compiled successfully') expect(output).toContain('Compiled successfully')
}) })
...@@ -136,7 +134,7 @@ describe('ESLint', () => { ...@@ -136,7 +134,7 @@ describe('ESLint', () => {
expect(output).not.toContain('Build error occurred') expect(output).not.toContain('Build error occurred')
expect(output).not.toContain('AllFilesIgnoredError') expect(output).not.toContain('AllFilesIgnoredError')
expect(output).toContain( expect(output).toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
expect(output).toContain('Compiled successfully') expect(output).toContain('Compiled successfully')
}) })
...@@ -270,7 +268,7 @@ describe('ESLint', () => { ...@@ -270,7 +268,7 @@ describe('ESLint', () => {
const output = stdout + stderr const output = stdout + stderr
expect(output).toContain( expect(output).toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
expect(output).toContain( expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces' 'Error: Comments inside children section of tag should be placed inside braces'
...@@ -285,10 +283,10 @@ describe('ESLint', () => { ...@@ -285,10 +283,10 @@ describe('ESLint', () => {
const output = stdout + stderr const output = stdout + stderr
expect(output).toContain( expect(output).toContain(
"Warning: Do not use <img>. Use Image from 'next/image' instead." 'Error: Do not use `<img>` element. Use `<Image />` from `next/image` instead.'
) )
expect(output).toContain( expect(output).toContain(
'Error: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
}) })
...@@ -303,11 +301,9 @@ describe('ESLint', () => { ...@@ -303,11 +301,9 @@ describe('ESLint', () => {
) )
const output = stdout + stderr const output = stdout + stderr
expect(output).toContain('Error: Synchronous scripts should not be used.')
expect(output).toContain( expect(output).toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: `<Document />` from `next/document` should not be imported outside of `pages/_document.js`.'
)
expect(output).toContain(
'Error: next/document should not be imported outside of pages/_document.js.'
) )
}) })
...@@ -323,10 +319,10 @@ describe('ESLint', () => { ...@@ -323,10 +319,10 @@ describe('ESLint', () => {
const output = stdout + stderr const output = stdout + stderr
expect(output).toContain( expect(output).toContain(
"Warning: Do not use <img>. Use Image from 'next/image' instead." 'Error: Do not use `<img>` element. Use `<Image />` from `next/image` instead.'
) )
expect(output).toContain( expect(output).toContain(
'Error: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
}) })
...@@ -393,7 +389,7 @@ describe('ESLint', () => { ...@@ -393,7 +389,7 @@ describe('ESLint', () => {
'Error: Comments inside children section of tag should be placed inside braces' 'Error: Comments inside children section of tag should be placed inside braces'
) )
expect(output).not.toContain( expect(output).not.toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
}) })
...@@ -407,9 +403,7 @@ describe('ESLint', () => { ...@@ -407,9 +403,7 @@ describe('ESLint', () => {
expect(output).toContain( expect(output).toContain(
'Error: Comments inside children section of tag should be placed inside braces' 'Error: Comments inside children section of tag should be placed inside braces'
) )
expect(output).toContain( expect(output).toContain('Error: Synchronous scripts should not be used.')
'Warning: External synchronous scripts are forbidden'
)
}) })
test('max warnings flag errors when warnings exceed threshold', async () => { test('max warnings flag errors when warnings exceed threshold', async () => {
...@@ -424,10 +418,10 @@ describe('ESLint', () => { ...@@ -424,10 +418,10 @@ describe('ESLint', () => {
expect(stderr).not.toEqual('') expect(stderr).not.toEqual('')
expect(stderr).toContain( expect(stderr).toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
expect(stdout).not.toContain( expect(stdout).not.toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
}) })
...@@ -443,10 +437,10 @@ describe('ESLint', () => { ...@@ -443,10 +437,10 @@ describe('ESLint', () => {
expect(stderr).toEqual('') expect(stderr).toEqual('')
expect(stderr).not.toContain( expect(stderr).not.toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
expect(stdout).toContain( expect(stdout).toContain(
'Warning: External synchronous scripts are forbidden' 'Warning: Synchronous scripts should not be used.'
) )
}) })
...@@ -462,7 +456,7 @@ describe('ESLint', () => { ...@@ -462,7 +456,7 @@ describe('ESLint', () => {
const output = stdout + stderr const output = stdout + stderr
expect(output).toContain( expect(output).toContain(
'warning: External synchronous scripts are forbidden' 'warning: Synchronous scripts should not be used.'
) )
expect(stdout).toContain('<script src="https://example.com" />') expect(stdout).toContain('<script src="https://example.com" />')
expect(stdout).toContain('2 warnings found') expect(stdout).toContain('2 warnings found')
...@@ -576,7 +570,7 @@ describe('ESLint', () => { ...@@ -576,7 +570,7 @@ describe('ESLint', () => {
) )
expect(output).not.toContain('pages/') expect(output).not.toContain('pages/')
expect(output).not.toContain('External synchronous scripts are forbidden') expect(output).not.toContain('Synchronous scripts should not be used.')
}) })
test('file flag can selectively lints multiple files', async () => { test('file flag can selectively lints multiple files', async () => {
...@@ -598,11 +592,11 @@ describe('ESLint', () => { ...@@ -598,11 +592,11 @@ describe('ESLint', () => {
expect(output).toContain('pages/bar.js') expect(output).toContain('pages/bar.js')
expect(output).toContain( expect(output).toContain(
"Do not use <img>. Use Image from 'next/image' instead" 'Do not use `<img>` element. Use `<Image />` from `next/image` instead.'
) )
expect(output).not.toContain('pages/index.js') expect(output).not.toContain('pages/index.js')
expect(output).not.toContain('External synchronous scripts are forbidden') expect(output).not.toContain('Synchronous scripts should not be used.')
}) })
}) })
}) })
...@@ -53,7 +53,7 @@ ruleTester.run('google-font-display', rule, { ...@@ -53,7 +53,7 @@ ruleTester.run('google-font-display', rule, {
); );
} }
} }
export default MyDocument; export default MyDocument;
`, `,
], ],
...@@ -76,7 +76,7 @@ ruleTester.run('google-font-display', rule, { ...@@ -76,7 +76,7 @@ ruleTester.run('google-font-display', rule, {
errors: [ errors: [
{ {
message: message:
'Display parameter is missing. See: https://nextjs.org/docs/messages/google-font-display', 'A font-display parameter is missing (adding `&display=optional` is recommended). See: https://nextjs.org/docs/messages/google-font-display',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
...@@ -98,7 +98,7 @@ ruleTester.run('google-font-display', rule, { ...@@ -98,7 +98,7 @@ ruleTester.run('google-font-display', rule, {
errors: [ errors: [
{ {
message: message:
'Block behavior is not recommended. See: https://nextjs.org/docs/messages/google-font-display', 'Block is not recommended. See: https://nextjs.org/docs/messages/google-font-display',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
...@@ -120,7 +120,7 @@ ruleTester.run('google-font-display', rule, { ...@@ -120,7 +120,7 @@ ruleTester.run('google-font-display', rule, {
errors: [ errors: [
{ {
message: message:
'Auto behavior is not recommended. See: https://nextjs.org/docs/messages/google-font-display', 'Auto is not recommended. See: https://nextjs.org/docs/messages/google-font-display',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
...@@ -142,7 +142,7 @@ ruleTester.run('google-font-display', rule, { ...@@ -142,7 +142,7 @@ ruleTester.run('google-font-display', rule, {
errors: [ errors: [
{ {
message: message:
'Fallback behavior is not recommended. See: https://nextjs.org/docs/messages/google-font-display', 'Fallback is not recommended. See: https://nextjs.org/docs/messages/google-font-display',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
......
...@@ -42,7 +42,7 @@ ruleTester.run('google-font-preconnect', rule, { ...@@ -42,7 +42,7 @@ ruleTester.run('google-font-preconnect', rule, {
errors: [ errors: [
{ {
message: message:
'Preconnect is missing. See: https://nextjs.org/docs/messages/google-font-preconnect', '`rel="preconnect"` is missing from Google Font. See: https://nextjs.org/docs/messages/google-font-preconnect',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
...@@ -58,7 +58,7 @@ ruleTester.run('google-font-preconnect', rule, { ...@@ -58,7 +58,7 @@ ruleTester.run('google-font-preconnect', rule, {
errors: [ errors: [
{ {
message: message:
'Preconnect is missing. See: https://nextjs.org/docs/messages/google-font-preconnect', '`rel="preconnect"` is missing from Google Font. See: https://nextjs.org/docs/messages/google-font-preconnect',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
......
...@@ -12,7 +12,7 @@ import { RuleTester } from 'eslint' ...@@ -12,7 +12,7 @@ import { RuleTester } from 'eslint'
}) })
const errorMessage = const errorMessage =
'next/script components with inline content must specify an `id` attribute. See: https://nextjs.org/docs/messages/inline-script-id' '`next/script` components with inline content must specify an `id` attribute. See: https://nextjs.org/docs/messages/inline-script-id'
const ruleTester = new RuleTester() const ruleTester = new RuleTester()
ruleTester.run('inline-script-id', rule, { ruleTester.run('inline-script-id', rule, {
......
...@@ -12,7 +12,7 @@ import { RuleTester } from 'eslint' ...@@ -12,7 +12,7 @@ import { RuleTester } from 'eslint'
}) })
const ERROR_MSG = const ERROR_MSG =
'Use the `next/script` component for loading third party scripts. See: https://nextjs.org/docs/messages/next-script-for-ga' 'Prefer `next/script` component when using the inline script for Google Analytics. See: https://nextjs.org/docs/messages/next-script-for-ga'
const ruleTester = new RuleTester() const ruleTester = new RuleTester()
......
...@@ -124,7 +124,7 @@ ruleTester.run('no-before-interactive-script-outside-document', rule, { ...@@ -124,7 +124,7 @@ ruleTester.run('no-before-interactive-script-outside-document', rule, {
errors: [ errors: [
{ {
message: message:
'next/script beforeInteractive strategy should only be used inside next/_document. See: https://nextjs.org/docs/messages/no-before-interactive-script-outside-document', "`next/script`'s `beforeInteractive` strategy should not be used outside of `pages/_document.js`. See: https://nextjs.org/docs/messages/no-before-interactive-script-outside-document",
}, },
], ],
}, },
......
...@@ -125,7 +125,7 @@ ruleTester.run('no-document-import-in-page', rule, { ...@@ -125,7 +125,7 @@ ruleTester.run('no-document-import-in-page', rule, {
errors: [ errors: [
{ {
message: message:
'next/document should not be imported outside of pages/_document.js. See: https://nextjs.org/docs/messages/no-document-import-in-page', '`<Document />` from `next/document` should not be imported outside of `pages/_document.js`. See: https://nextjs.org/docs/messages/no-document-import-in-page',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
], ],
...@@ -139,7 +139,7 @@ ruleTester.run('no-document-import-in-page', rule, { ...@@ -139,7 +139,7 @@ ruleTester.run('no-document-import-in-page', rule, {
errors: [ errors: [
{ {
message: message:
'next/document should not be imported outside of pages/_document.js. See: https://nextjs.org/docs/messages/no-document-import-in-page', '`<Document />` from `next/document` should not be imported outside of `pages/_document.js`. See: https://nextjs.org/docs/messages/no-document-import-in-page',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
], ],
...@@ -153,7 +153,7 @@ ruleTester.run('no-document-import-in-page', rule, { ...@@ -153,7 +153,7 @@ ruleTester.run('no-document-import-in-page', rule, {
errors: [ errors: [
{ {
message: message:
'next/document should not be imported outside of pages/_document.js. See: https://nextjs.org/docs/messages/no-document-import-in-page', '`<Document />` from `next/document` should not be imported outside of `pages/_document.js`. See: https://nextjs.org/docs/messages/no-document-import-in-page',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
], ],
......
...@@ -21,7 +21,7 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -21,7 +21,7 @@ ruleTester.run('no-duplicate-head', rule, {
static async getInitialProps(ctx) { static async getInitialProps(ctx) {
//... //...
} }
render() { render() {
return ( return (
<Html> <Html>
...@@ -30,7 +30,7 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -30,7 +30,7 @@ ruleTester.run('no-duplicate-head', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document.js', filename: 'pages/_document.js',
...@@ -38,7 +38,7 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -38,7 +38,7 @@ ruleTester.run('no-duplicate-head', rule, {
{ {
code: `import Document, { Html, Head, Main, NextScript } from 'next/document' code: `import Document, { Html, Head, Main, NextScript } from 'next/document'
class MyDocument extends Document { class MyDocument extends Document {
render() { render() {
return ( return (
<Html> <Html>
...@@ -53,7 +53,7 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -53,7 +53,7 @@ ruleTester.run('no-duplicate-head', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document.tsx', filename: 'pages/_document.tsx',
...@@ -64,7 +64,7 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -64,7 +64,7 @@ ruleTester.run('no-duplicate-head', rule, {
code: ` code: `
import Document, { Html, Main, NextScript } from 'next/document' import Document, { Html, Main, NextScript } from 'next/document'
import Head from 'next/head' import Head from 'next/head'
class MyDocument extends Document { class MyDocument extends Document {
render() { render() {
return ( return (
...@@ -76,19 +76,19 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -76,19 +76,19 @@ ruleTester.run('no-duplicate-head', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document.js', filename: 'pages/_document.js',
errors: [ errors: [
{ {
message: message:
'Do not include multiple instances of <Head/>. See: https://nextjs.org/docs/messages/no-duplicate-head', 'Do not include multiple instances of `<Head/>`. See: https://nextjs.org/docs/messages/no-duplicate-head',
type: 'JSXElement', type: 'JSXElement',
}, },
{ {
message: message:
'Do not include multiple instances of <Head/>. See: https://nextjs.org/docs/messages/no-duplicate-head', 'Do not include multiple instances of `<Head/>`. See: https://nextjs.org/docs/messages/no-duplicate-head',
type: 'JSXElement', type: 'JSXElement',
}, },
], ],
...@@ -97,7 +97,7 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -97,7 +97,7 @@ ruleTester.run('no-duplicate-head', rule, {
code: ` code: `
import Document, { Html, Main, NextScript } from 'next/document' import Document, { Html, Main, NextScript } from 'next/document'
import Head from 'next/head' import Head from 'next/head'
class MyDocument extends Document { class MyDocument extends Document {
render() { render() {
return ( return (
...@@ -124,14 +124,14 @@ ruleTester.run('no-duplicate-head', rule, { ...@@ -124,14 +124,14 @@ ruleTester.run('no-duplicate-head', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document.page.tsx', filename: 'pages/_document.page.tsx',
errors: [ errors: [
{ {
message: message:
'Do not include multiple instances of <Head/>. See: https://nextjs.org/docs/messages/no-duplicate-head', 'Do not include multiple instances of `<Head/>`. See: https://nextjs.org/docs/messages/no-duplicate-head',
type: 'JSXElement', type: 'JSXElement',
}, },
], ],
......
...@@ -67,7 +67,7 @@ ruleTester.run('no-head-element', rule, { ...@@ -67,7 +67,7 @@ ruleTester.run('no-head-element', rule, {
errors: [ errors: [
{ {
message: message:
"Do not use <head>. Use Head from 'next/head' instead. See: https://nextjs.org/docs/messages/no-head-element", 'Do not use `<head>` element. Use `<Head />` from `next/head` instead. See: https://nextjs.org/docs/messages/no-head-element',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
...@@ -93,7 +93,7 @@ ruleTester.run('no-head-element', rule, { ...@@ -93,7 +93,7 @@ ruleTester.run('no-head-element', rule, {
errors: [ errors: [
{ {
message: message:
"Do not use <head>. Use Head from 'next/head' instead. See: https://nextjs.org/docs/messages/no-head-element", 'Do not use `<head>` element. Use `<Head />` from `next/head` instead. See: https://nextjs.org/docs/messages/no-head-element',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
......
...@@ -21,7 +21,7 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -21,7 +21,7 @@ ruleTester.run('no-head-import-in-document', rule, {
static async getInitialProps(ctx) { static async getInitialProps(ctx) {
//... //...
} }
render() { render() {
return ( return (
<Html> <Html>
...@@ -31,7 +31,7 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -31,7 +31,7 @@ ruleTester.run('no-head-import-in-document', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document.tsx', filename: 'pages/_document.tsx',
...@@ -46,7 +46,7 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -46,7 +46,7 @@ ruleTester.run('no-head-import-in-document', rule, {
<meta name="viewport" content="initial-scale=1.0, width=device-width" /> <meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head> </Head>
); );
} }
`, `,
filename: 'pages/index.tsx', filename: 'pages/index.tsx',
}, },
...@@ -56,7 +56,7 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -56,7 +56,7 @@ ruleTester.run('no-head-import-in-document', rule, {
code: ` code: `
import Document, { Html, Main, NextScript } from 'next/document' import Document, { Html, Main, NextScript } from 'next/document'
import Head from 'next/head' import Head from 'next/head'
class MyDocument extends Document { class MyDocument extends Document {
render() { render() {
return ( return (
...@@ -70,14 +70,14 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -70,14 +70,14 @@ ruleTester.run('no-head-import-in-document', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document.js', filename: 'pages/_document.js',
errors: [ errors: [
{ {
message: message:
'next/head should not be imported in pages/_document.js. Import Head from next/document instead. See: https://nextjs.org/docs/messages/no-head-import-in-document', '`next/head` should not be imported in `pages/_document.js`. Use `<Head />` from `next/document` instead. See: https://nextjs.org/docs/messages/no-head-import-in-document',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
], ],
...@@ -86,7 +86,7 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -86,7 +86,7 @@ ruleTester.run('no-head-import-in-document', rule, {
code: ` code: `
import Document, { Html, Main, NextScript } from 'next/document' import Document, { Html, Main, NextScript } from 'next/document'
import Head from 'next/head' import Head from 'next/head'
class MyDocument extends Document { class MyDocument extends Document {
render() { render() {
return ( return (
...@@ -100,14 +100,14 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -100,14 +100,14 @@ ruleTester.run('no-head-import-in-document', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document.page.tsx', filename: 'pages/_document.page.tsx',
errors: [ errors: [
{ {
message: message:
'next/head should not be imported in pages/_document.page.tsx. Import Head from next/document instead. See: https://nextjs.org/docs/messages/no-head-import-in-document', '`next/head` should not be imported in `pages/_document.page.tsx`. Use `<Head />` from `next/document` instead. See: https://nextjs.org/docs/messages/no-head-import-in-document',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
], ],
...@@ -116,7 +116,7 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -116,7 +116,7 @@ ruleTester.run('no-head-import-in-document', rule, {
code: ` code: `
import Document, { Html, Main, NextScript } from 'next/document' import Document, { Html, Main, NextScript } from 'next/document'
import Head from 'next/head' import Head from 'next/head'
class MyDocument extends Document { class MyDocument extends Document {
render() { render() {
return ( return (
...@@ -130,14 +130,14 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -130,14 +130,14 @@ ruleTester.run('no-head-import-in-document', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document/index.js', filename: 'pages/_document/index.js',
errors: [ errors: [
{ {
message: message:
'next/head should not be imported in pages/_document/index.js. Import Head from next/document instead. See: https://nextjs.org/docs/messages/no-head-import-in-document', '`next/head` should not be imported in `pages/_document/index.js`. Use `<Head />` from `next/document` instead. See: https://nextjs.org/docs/messages/no-head-import-in-document',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
], ],
...@@ -146,7 +146,7 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -146,7 +146,7 @@ ruleTester.run('no-head-import-in-document', rule, {
code: ` code: `
import Document, { Html, Main, NextScript } from 'next/document' import Document, { Html, Main, NextScript } from 'next/document'
import Head from 'next/head' import Head from 'next/head'
class MyDocument extends Document { class MyDocument extends Document {
render() { render() {
return ( return (
...@@ -160,14 +160,14 @@ ruleTester.run('no-head-import-in-document', rule, { ...@@ -160,14 +160,14 @@ ruleTester.run('no-head-import-in-document', rule, {
) )
} }
} }
export default MyDocument export default MyDocument
`, `,
filename: 'pages/_document/index.tsx', filename: 'pages/_document/index.tsx',
errors: [ errors: [
{ {
message: message:
'next/head should not be imported in pages/_document/index.tsx. Import Head from next/document instead. See: https://nextjs.org/docs/messages/no-head-import-in-document', '`next/head` should not be imported in `pages/_document/index.tsx`. Use `<Head />` from `next/document` instead. See: https://nextjs.org/docs/messages/no-head-import-in-document',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
], ],
......
...@@ -246,7 +246,7 @@ describe('no-html-link-for-pages', function () { ...@@ -246,7 +246,7 @@ describe('no-html-link-for-pages', function () {
assert.notEqual(report, undefined, 'No lint errors found.') assert.notEqual(report, undefined, 'No lint errors found.')
assert.equal( assert.equal(
report.message, report.message,
"Do not use the HTML <a> tag to navigate to /. Use Link from 'next/link' instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages" 'Do not use an `<a>` element to navigate to `/`. Use `<Link />` from `next/link` instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages'
) )
}) })
...@@ -257,7 +257,7 @@ describe('no-html-link-for-pages', function () { ...@@ -257,7 +257,7 @@ describe('no-html-link-for-pages', function () {
assert.notEqual(report, undefined, 'No lint errors found.') assert.notEqual(report, undefined, 'No lint errors found.')
assert.equal( assert.equal(
report.message, report.message,
"Do not use the HTML <a> tag to navigate to /list/foo/bar/. Use Link from 'next/link' instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages" 'Do not use an `<a>` element to navigate to `/list/foo/bar/`. Use `<Link />` from `next/link` instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages'
) )
const [secondReport] = linter.verify( const [secondReport] = linter.verify(
secondInvalidDynamicCode, secondInvalidDynamicCode,
...@@ -269,7 +269,7 @@ describe('no-html-link-for-pages', function () { ...@@ -269,7 +269,7 @@ describe('no-html-link-for-pages', function () {
assert.notEqual(secondReport, undefined, 'No lint errors found.') assert.notEqual(secondReport, undefined, 'No lint errors found.')
assert.equal( assert.equal(
secondReport.message, secondReport.message,
"Do not use the HTML <a> tag to navigate to /list/foo/. Use Link from 'next/link' instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages" 'Do not use an `<a>` element to navigate to `/list/foo/`. Use `<Link />` from `next/link` instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages'
) )
const [thirdReport] = linter.verify(thirdInvalidDynamicCode, linterConfig, { const [thirdReport] = linter.verify(thirdInvalidDynamicCode, linterConfig, {
filename: 'foo.js', filename: 'foo.js',
...@@ -277,7 +277,7 @@ describe('no-html-link-for-pages', function () { ...@@ -277,7 +277,7 @@ describe('no-html-link-for-pages', function () {
assert.notEqual(thirdReport, undefined, 'No lint errors found.') assert.notEqual(thirdReport, undefined, 'No lint errors found.')
assert.equal( assert.equal(
thirdReport.message, thirdReport.message,
"Do not use the HTML <a> tag to navigate to /list/lorem-ipsum/. Use Link from 'next/link' instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages" 'Do not use an `<a>` element to navigate to `/list/lorem-ipsum/`. Use `<Link />` from `next/link` instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages'
) )
}) })
}) })
...@@ -38,7 +38,7 @@ ruleTester.run('no-img-element', rule, { ...@@ -38,7 +38,7 @@ ruleTester.run('no-img-element', rule, {
render() { render() {
return ( return (
<div> <div>
<img <img
src="/test.png" src="/test.png"
alt="Test picture" alt="Test picture"
width={500} width={500}
...@@ -51,7 +51,7 @@ ruleTester.run('no-img-element', rule, { ...@@ -51,7 +51,7 @@ ruleTester.run('no-img-element', rule, {
errors: [ errors: [
{ {
message: message:
"Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element", 'Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
......
...@@ -148,7 +148,7 @@ ruleTester.run('no-page-custom-font', rule, { ...@@ -148,7 +148,7 @@ ruleTester.run('no-page-custom-font', rule, {
errors: [ errors: [
{ {
message: message:
'Custom fonts not added at the document level will only load for a single page. This is discouraged. See: https://nextjs.org/docs/messages/no-page-custom-font', 'Custom fonts not added in `pages/_document.js` will only load for a single page. This is discouraged. See: https://nextjs.org/docs/messages/no-page-custom-font',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
...@@ -188,11 +188,11 @@ ruleTester.run('no-page-custom-font', rule, { ...@@ -188,11 +188,11 @@ ruleTester.run('no-page-custom-font', rule, {
errors: [ errors: [
{ {
message: message:
'Rendering this <link /> not inline within <Head> of Document disables font optimization. This is discouraged. See: https://nextjs.org/docs/messages/no-page-custom-font', 'Using `<link />` outside of `<Head>` will disable automatic font optimization. This is discouraged. See: https://nextjs.org/docs/messages/no-page-custom-font',
}, },
{ {
message: message:
'Rendering this <link /> not inline within <Head> of Document disables font optimization. This is discouraged. See: https://nextjs.org/docs/messages/no-page-custom-font', 'Using `<link />` outside of `<Head>` will disable automatic font optimization. This is discouraged. See: https://nextjs.org/docs/messages/no-page-custom-font',
}, },
], ],
}, },
......
...@@ -32,7 +32,7 @@ ruleTester.run('no-script-in-head', rule, { ...@@ -32,7 +32,7 @@ ruleTester.run('no-script-in-head', rule, {
code: ` code: `
import Head from "next/head"; import Head from "next/head";
import Script from "next/script"; import Script from "next/script";
export default function Index() { export default function Index() {
return ( return (
<Head> <Head>
...@@ -44,7 +44,7 @@ ruleTester.run('no-script-in-head', rule, { ...@@ -44,7 +44,7 @@ ruleTester.run('no-script-in-head', rule, {
errors: [ errors: [
{ {
message: message:
"next/script shouldn't be used inside next/head. See: https://nextjs.org/docs/messages/no-script-component-in-head-component", '`next/script` should not be used in `next/head` component. Move `<Script />` outside of `<Head>` instead. See: https://nextjs.org/docs/messages/no-script-component-in-head-component',
}, },
], ],
}, },
......
...@@ -16,7 +16,7 @@ const ruleTester = new RuleTester() ...@@ -16,7 +16,7 @@ const ruleTester = new RuleTester()
const errors = [ const errors = [
{ {
message: message:
'next/server should not be imported outside of Middleware. Read more: https://nextjs.org/docs/messages/no-server-import-in-page', '`next/server` should not be used outside of `middleware.js`. See: https://nextjs.org/docs/messages/no-server-import-in-page',
type: 'ImportDeclaration', type: 'ImportDeclaration',
}, },
] ]
......
...@@ -23,7 +23,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, { ...@@ -23,7 +23,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, {
const initialProps = await Document.getInitialProps(ctx) const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps } return { ...initialProps }
} }
render() { render() {
return ( return (
<Html> <Html>
...@@ -46,7 +46,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, { ...@@ -46,7 +46,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, {
const initialProps = await Document.getInitialProps(ctx) const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps } return { ...initialProps }
} }
render() { render() {
return ( return (
<Html> <Html>
...@@ -96,7 +96,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, { ...@@ -96,7 +96,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, {
const initialProps = await Document.getInitialProps(ctx) const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps } return { ...initialProps }
} }
render() { render() {
return ( return (
<Html> <Html>
...@@ -116,8 +116,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, { ...@@ -116,8 +116,7 @@ ruleTester.run('no-styled-jsx-in-document', rule, {
}`, }`,
errors: [ errors: [
{ {
message: message: `\`styled-jsx\` should not be used in \`pages/_document.js\`. See: https://nextjs.org/docs/messages/no-styled-jsx-in-document`,
'styled-jsx can not be used inside pages/_document.js. See https://nextjs.org/docs/messages/no-styled-jsx-in-document.',
}, },
], ],
}, },
......
...@@ -58,7 +58,7 @@ ruleTester.run('sync-scripts', rule, { ...@@ -58,7 +58,7 @@ ruleTester.run('sync-scripts', rule, {
errors: [ errors: [
{ {
message: message:
'External synchronous scripts are forbidden. See: https://nextjs.org/docs/messages/no-sync-scripts', 'Synchronous scripts should not be used. See: https://nextjs.org/docs/messages/no-sync-scripts',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
...@@ -80,7 +80,7 @@ ruleTester.run('sync-scripts', rule, { ...@@ -80,7 +80,7 @@ ruleTester.run('sync-scripts', rule, {
errors: [ errors: [
{ {
message: message:
'External synchronous scripts are forbidden. See: https://nextjs.org/docs/messages/no-sync-scripts', 'Synchronous scripts should not be used. See: https://nextjs.org/docs/messages/no-sync-scripts',
type: 'JSXOpeningElement', type: 'JSXOpeningElement',
}, },
], ],
......
...@@ -38,7 +38,7 @@ ruleTester.run('no-title-in-document-head', rule, { ...@@ -38,7 +38,7 @@ ruleTester.run('no-title-in-document-head', rule, {
); );
} }
} }
export default MyDocument; export default MyDocument;
`, `,
], ],
...@@ -60,7 +60,7 @@ ruleTester.run('no-title-in-document-head', rule, { ...@@ -60,7 +60,7 @@ ruleTester.run('no-title-in-document-head', rule, {
errors: [ errors: [
{ {
message: message:
'Titles should be defined at the page-level using next/head. See: https://nextjs.org/docs/messages/no-title-in-document-head', 'Do not use `<title>` element with `<Head />` component from `next/document`. Titles should defined at the page-level using `<Head />` from `next/head` instead. See: https://nextjs.org/docs/messages/no-title-in-document-head',
type: 'JSXElement', type: 'JSXElement',
}, },
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment