-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
next lint
+ ESLint in Create Next App
#25064
next lint
+ ESLint in Create Next App
#25064
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@timneutkens We can merge this PR last once we're okay with everything, happy with the proposed idea of adding ESLint to Create Next App and made sure all the appropriate rules have landed to the plugin 🙏 |
The PnP e2e test is failing due to missing dependencies |
This comment has been minimized.
This comment has been minimized.
next lint
+ ESLint in Create Next App templates
next lint
+ ESLint in Create Next App templatesnext lint
+ ESLint in Create Next App
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Failing test suitesCommit: ee29a91 test/integration/create-next-app/index.test.js
Expand output● create next app › should support typescript flag
|
This comment has been minimized.
This comment has been minimized.
@merceyz Modified the |
… next app templates, and documentation
This comment has been minimized.
This comment has been minimized.
Seems that when the checks pass there's no output except 2 empty lines
|
If you do not want ESLint to run as a build step, it can be disabled using the `--no-lint` flag: | ||
|
||
```bash | ||
next build --no-lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a next.config.js
flag in my opinion, similar to TypeScript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍
|
||
## Linting Custom Directories | ||
|
||
By default, Next.js will only run ESLint for all files in the `pages/` directory. However, you can specify other custom directories to run by using the `--dir` flag in `next lint`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default should definitely be pages
, components
, and lib
as those are the most common setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍 and in next.config.js
globally.
|
||
## ESLint Plugin | ||
|
||
Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/package/@next/eslint-plugin-next), that makes it easier to catch common issues and problems in a Next.js application. The full set of rules can be found in the [package repository](https://github.com/vercel/next.js/tree/master/packages/eslint-plugin-next/lib/rules). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of linking to them we should maintain a list in this document to allow for a description, but for now it's fine to have it linked 👍
This comment has been minimized.
This comment has been minimized.
Stats from current PRDefault Server Mode (Increase detected
|
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
buildDuration | 14.7s | 15.1s | |
buildDurationCached | 3.9s | 4s | |
nodeModulesSize | 46.7 MB | 46.7 MB |
Page Load Tests Overall increase ✓
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.686 | 2.688 | 0 |
/ avg req/sec | 930.67 | 930.18 | |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.613 | 1.587 | -0.03 |
/error-in-render avg req/sec | 1550.03 | 1575.73 | +25.7 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
framework-HASH.js gzip | 39.3 kB | 39.3 kB | ✓ |
main-HASH.js gzip | 19.5 kB | 19.5 kB | ✓ |
webpack-HASH.js gzip | 804 B | 804 B | ✓ |
Overall change | 59.5 kB | 59.5 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31.1 kB | 31.1 kB | ✓ |
Overall change | 31.1 kB | 31.1 kB | ✓ |
Client Pages
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
_app-HASH.js gzip | 801 B | 801 B | ✓ |
_error-HASH.js gzip | 3.07 kB | 3.07 kB | ✓ |
amp-HASH.js gzip | 527 B | 527 B | ✓ |
css-HASH.js gzip | 334 B | 334 B | ✓ |
hooks-HASH.js gzip | 890 B | 890 B | ✓ |
index-HASH.js gzip | 263 B | 263 B | ✓ |
link-HASH.js gzip | 1.64 kB | 1.64 kB | ✓ |
routerDirect..HASH.js gzip | 333 B | 333 B | ✓ |
withRouter-HASH.js gzip | 330 B | 330 B | ✓ |
bb14e60e810b..30f.css gzip | 125 B | 125 B | ✓ |
Overall change | 8.31 kB | 8.31 kB | ✓ |
Client Build Manifests
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
_buildManifest.js gzip | 392 B | 392 B | ✓ |
Overall change | 392 B | 392 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
index.html gzip | 559 B | 559 B | ✓ |
link.html gzip | 568 B | 568 B | ✓ |
withRouter.html gzip | 556 B | 556 B | ✓ |
Overall change | 1.68 kB | 1.68 kB | ✓ |
Serverless Mode
General Overall increase ⚠️
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
buildDuration | 16.7s | 16.8s | |
buildDurationCached | 5.2s | 5.2s | -48ms |
nodeModulesSize | 46.7 MB | 46.7 MB |
Client Bundles (main, webpack, commons)
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
framework-HASH.js gzip | 39.3 kB | 39.3 kB | ✓ |
main-HASH.js gzip | 19.5 kB | 19.5 kB | ✓ |
webpack-HASH.js gzip | 804 B | 804 B | ✓ |
Overall change | 59.5 kB | 59.5 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31.1 kB | 31.1 kB | ✓ |
Overall change | 31.1 kB | 31.1 kB | ✓ |
Client Pages
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
_app-HASH.js gzip | 801 B | 801 B | ✓ |
_error-HASH.js gzip | 3.07 kB | 3.07 kB | ✓ |
amp-HASH.js gzip | 527 B | 527 B | ✓ |
css-HASH.js gzip | 334 B | 334 B | ✓ |
hooks-HASH.js gzip | 890 B | 890 B | ✓ |
index-HASH.js gzip | 263 B | 263 B | ✓ |
link-HASH.js gzip | 1.64 kB | 1.64 kB | ✓ |
routerDirect..HASH.js gzip | 333 B | 333 B | ✓ |
withRouter-HASH.js gzip | 330 B | 330 B | ✓ |
bb14e60e810b..30f.css gzip | 125 B | 125 B | ✓ |
Overall change | 8.31 kB | 8.31 kB | ✓ |
Client Build Manifests
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
_buildManifest.js gzip | 392 B | 392 B | ✓ |
Overall change | 392 B | 392 B | ✓ |
Serverless bundles
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
_error.js | 16.9 kB | 16.9 kB | ✓ |
404.html | 2.42 kB | 2.42 kB | ✓ |
500.html | 2.41 kB | 2.41 kB | ✓ |
amp.amp.html | 10.8 kB | 10.8 kB | ✓ |
amp.html | 1.61 kB | 1.61 kB | ✓ |
css.html | 1.79 kB | 1.79 kB | ✓ |
hooks.html | 1.67 kB | 1.67 kB | ✓ |
index.js | 17.2 kB | 17.2 kB | ✓ |
link.js | 17.4 kB | 17.4 kB | ✓ |
routerDirect.js | 17.4 kB | 17.4 kB | ✓ |
withRouter.js | 17.4 kB | 17.4 kB | ✓ |
Overall change | 107 kB | 107 kB | ✓ |
Webpack 4 Mode (Increase detected ⚠️ )
General Overall increase ⚠️
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
buildDuration | 13.7s | 13.3s | -395ms |
buildDurationCached | 5.8s | 6s | |
nodeModulesSize | 46.7 MB | 46.7 MB |
Page Load Tests Overall increase ✓
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.853 | 2.793 | -0.06 |
/ avg req/sec | 876.16 | 895.19 | +19.03 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.695 | 1.633 | -0.06 |
/error-in-render avg req/sec | 1475.32 | 1530.58 | +55.26 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
677f882d2ed8..HASH.js gzip | 13.3 kB | 13.3 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-HASH.js gzip | 7.26 kB | 7.26 kB | ✓ |
webpack-HASH.js gzip | 751 B | 751 B | ✓ |
Overall change | 60.3 kB | 60.3 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31.3 kB | 31.3 kB | ✓ |
Overall change | 31.3 kB | 31.3 kB | ✓ |
Client Pages
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.07 kB | 1.07 kB | ✓ |
_error-HASH.js gzip | 3.74 kB | 3.74 kB | ✓ |
amp-HASH.js gzip | 536 B | 536 B | ✓ |
css-HASH.js gzip | 339 B | 339 B | ✓ |
hooks-HASH.js gzip | 887 B | 887 B | ✓ |
index-HASH.js gzip | 227 B | 227 B | ✓ |
link-HASH.js gzip | 1.63 kB | 1.63 kB | ✓ |
routerDirect..HASH.js gzip | 303 B | 303 B | ✓ |
withRouter-HASH.js gzip | 302 B | 302 B | ✓ |
e025d2764813..52f.css gzip | 125 B | 125 B | ✓ |
Overall change | 9.16 kB | 9.16 kB | ✓ |
Client Build Manifests
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
_buildManifest.js gzip | 420 B | 420 B | ✓ |
Overall change | 420 B | 420 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | housseindjirdeh/next.js eslint-create-next-app | Change | |
---|---|---|---|
index.html gzip | 614 B | 614 B | ✓ |
link.html gzip | 620 B | 620 B | ✓ |
withRouter.html gzip | 607 B | 607 B | ✓ |
Overall change | 1.84 kB | 1.84 kB | ✓ |
If you do not want ESLint to run as a build step, it can be disabled using the `--no-lint` flag: | ||
|
||
```bash | ||
next build --no-lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍
|
||
## Linting Custom Directories | ||
|
||
By default, Next.js will only run ESLint for all files in the `pages/` directory. However, you can specify other custom directories to run by using the `--dir` flag in `next lint`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍 and in next.config.js
globally.
} | ||
``` | ||
|
||
This configuration extends recommended rule sets from various Eslint plugins: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint capitalization here is different than the rest of the doc.
|
||
### Core Web Vitals | ||
|
||
A stricter `next/core-web-vitals` entrypoint can also be specified in `.eslintrc`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"entry point" instead of "entrypoint" IMO.
@@ -84,6 +84,16 @@ The application will start at `http://localhost:3000` by default. The default po | |||
npx next start -p 4000 | |||
``` | |||
|
|||
## Lint | |||
|
|||
`next lint` runs ESLint for all files in the `pages` directory and provides a guided setup to install any required dependencies if ESLint is not already configured in your application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change from just pages, let's update here too 👍
Some slight tweaks based on my review of the docs. A few outstanding questions left 😄 #25064 (review)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl> Co-authored-by: Tim Neutkens <timneutkens@me.com>
Some slight tweaks based on my review of the docs. A few outstanding questions left 😄 vercel#25064 (review)
For #24900
This PR does the following:
eslint
flagnext lint
which when run for the first time:eslint
,eslint-config-next
) if they are not installed.eslintrc
file with the default config (extends: "next"
)lint
on thepages/
dir on or other specified directories--no-lint
flag fornext build
to disable ESLint running as a build stepnext/core-web-vitals
entry point toeslint-config-next
to error on a few core rules that affect Core Web Vitals--example
or--example-path
)eslint
andeslint-config-next
are included as dev dependenciesextends: ["next" , "next/core-web-vitals"]
is included by default in.eslintrc