ESLint in Next.js and Create Next App #24900
Replies: 5 comments 20 replies
-
I don't believe the |
Beta Was this translation helpful? Give feedback.
-
what about a rule to check the functions exported from within a page? I.e. only allow |
Beta Was this translation helpful? Give feedback.
-
why are we considering an abandoned config :( |
Beta Was this translation helpful? Give feedback.
-
It would be great if |
Beta Was this translation helpful? Give feedback.
-
can we inform an unaware user if they install plugins seperately which were already installed using config-next? afaik underlying plugins from config-next are not shown in project package.json or eslint file so it's unclear for a user to know which plugins does it extend. |
Beta Was this translation helpful? Give feedback.
-
Over 50% of Next.js apps use ESLint in some part of their build workflow. This discussion covers steps taken to include a Next.js' specific plugin and shareable config and proposes a default setup for all new applications built with Create Next App.
tl.dr:
eslint-plugin-next
is an ESLint plugin that aims to catch common issues and problems in a Next.js application. There are a list of initial rules that this plugin will provide, but we would love to hear more suggestions.eslint-config-next
is a shareable config that bundles multiple useful plugins (next
,react
, andreact-hooks
) and can easily be included in any Next.js application’s.eslintrc
file with({ "extends": "next"})
next/core-web-vitals
) to error on a few, important rules that will affect Core Web Vitalsnext
andnext/core-web-vitals
will be included into the initial configPlugin
The following is an initial set of rules that
eslint-plugin-next
will check for:Imports
next/document
should not be imported outside ofpages/_document.js
(ESLint Plugin: Prevent bad imports of next/document and next/head #24832)next/head
should not be imported inpages/_document.js
(ESLint Plugin: Prevent bad imports of next/document and next/head #24832)Images
<img>
. Use<Image>
instead. (ESLint Plugin: Image rules #23402)Google Fonts
font-display
value is missing (orfallback
/block
is used) for Google Fonts (ESLint Plugin: Google Font rules #24766)rel="preconnect"
is missing for Google Fonts domain (ESLint Plugin: Google Font rules #24766)Polyfills
Links
<a>
tag to navigate to a page. UseLink
fromnext/link
instead (adding no html-link lint rule to eslint-plugin #12969)passHref=true
must be assigned when usingLink
without an HTML<a>
element for a custom component (ESLint Plugin: passHref is not assigned #24670)Scripts
Styles
Head
<title>
should not be used in<Head>
in _document.js (ESLint Plugin: Disallow <title> in Head from next/document #24868)Shareable Config
New, experimental ESLint changes have been introduced to Next.js (still experimental/in canary). When
{ experimental: { eslint: true } }
is now enabled innext.config.js
:next build
)..eslintrc
file for the first time and running a build will automatically populate the file to extend fromeslint-config-next
(the new shareable config):This config extends recommended rule sets from
eslint-plugin-react
,eslint-plugin-react-hooks
, andeslint-plugin-next
.Proposals
Although this discussion aims to start a conversation on how ESLint is currently configured within Next.js, it also proposes the following:
Create an additional ESLint config entry point (
next/core-web-vitals
) that can be used by adding the following to.eslintrc
:This would be stricter than the recommended rule-set (which is almost all warnings) and error on a few important rules:
<img>
. Use<Image>
instead.<a>
tag to navigate to a page. UseLink
fromnext/link
instead.If any of these rules error with ESLint enabled, the build will fail. As more rules get added to the plugin, only those that are guaranteed to negatively affect Core Web Vital metrics will be included into this entry point.
By default, ESLint will enabled in Create Next App with the following default
.eslintrc
configuration:This will be set up to be easily opted-out of if need be and the default config can always be modified by the developer.
Thoughts? Suggestions? Please share!
Beta Was this translation helpful? Give feedback.
All reactions