Skip to content

Commit 86160a5

Browse files
authored
Upgrade to Prettier 2 (#13061)
1 parent 7c68d0c commit 86160a5

File tree

595 files changed

+1525
-1657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

595 files changed

+1525
-1657
lines changed

.prettierignore

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ packages/react-refresh-utils/**/*.js
77
packages/react-refresh-utils/**/*.d.ts
88
packages/react-dev-overlay/lib/**
99
**/__tmp__/**
10-
# prettier can't handle the `import type {} from ''` syntax yet
11-
test/integration/typescript-only-remove-type-imports/**/*.ts
12-
test/integration/typescript-only-remove-type-imports/**/*.tsx
1310
lerna.json

.prettierignore_staged

-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
**/_next/**
33
**/dist/**
44
packages/next/compiled/**/*
5-
# prettier can't handle the `import type {} from ''` syntax yet
6-
test/integration/typescript-only-remove-type-imports/**/*.ts
7-
test/integration/typescript-only-remove-type-imports/**/*.tsx
85
lerna.json

bench/recursive-copy/run.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const createSrcFolder = async () => {
2020
join(srcDir, `folder${i % 5}`, `folder${i + (1 % 5)}`, `file${i}`)
2121
)
2222

23-
await Promise.all(files.map(file => fs.outputFile(file, 'hello')))
23+
await Promise.all(files.map((file) => fs.outputFile(file, 'hello')))
2424
}
2525

2626
async function run(fn) {

docs/advanced-features/custom-document.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class MyDocument extends Document {
7171
ctx.renderPage = () =>
7272
originalRenderPage({
7373
// useful for wrapping the whole react tree
74-
enhanceApp: App => App,
74+
enhanceApp: (App) => App,
7575
// useful for wrapping in a per-page basis
76-
enhanceComponent: Component => Component,
76+
enhanceComponent: (Component) => Component,
7777
})
7878

7979
// Run the parent `getInitialProps`, it now includes the custom `renderPage`

docs/advanced-features/custom-server.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ app.prepare().then(() => {
4545
} else {
4646
handle(req, res, parsedUrl)
4747
}
48-
}).listen(3000, err => {
48+
}).listen(3000, (err) => {
4949
if (err) throw err
5050
console.log('> Ready on http://localhost:3000')
5151
})

docs/advanced-features/dynamic-import.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ To dynamically import the `Hello` component, you can return it from the [Promise
5555
import dynamic from 'next/dynamic'
5656

5757
const DynamicComponent = dynamic(() =>
58-
import('../components/hello').then(mod => mod.Hello)
58+
import('../components/hello').then((mod) => mod.Hello)
5959
)
6060

6161
function Home() {

docs/api-reference/data-fetching/getInitialProps.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Page({ stars }) {
2929
return <div>Next stars: {stars}</div>
3030
}
3131

32-
Page.getInitialProps = async ctx => {
32+
Page.getInitialProps = async (ctx) => {
3333
const res = await fetch('https://api.github.com/repos/zeit/next.js')
3434
const json = await res.json()
3535
return { stars: json.stargazers_count }

docs/api-reference/next.config.js/custom-webpack-config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//))
2525
return config
2626
},
27-
webpackDevMiddleware: config => {
27+
webpackDevMiddleware: (config) => {
2828
// Perform customizations to webpack dev middleware config
2929
// Important: return the modified config
3030
return config

docs/api-reference/next.config.js/exportPathMap.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Open `next.config.js` and add the following `exportPathMap` config:
2323

2424
```js
2525
module.exports = {
26-
exportPathMap: async function(
26+
exportPathMap: async function (
2727
defaultPathMap,
2828
{ dev, dir, outDir, distDir, buildId }
2929
) {

docs/api-reference/next/link.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ A `Link` to a dynamic route is a combination of the `href` and `as` props. A lin
6767
```jsx
6868
const pids = ['id1', 'id2', 'id3']
6969
{
70-
pids.map(pid => (
70+
pids.map((pid) => (
7171
<Link href="/post/[pid]" as={`/post/${pid}`}>
7272
<a>Post {pid}</a>
7373
</Link>

docs/api-reference/next/router.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function ActiveLink({ children, href }) {
2020
color: router.pathname === href ? 'red' : 'black',
2121
}
2222

23-
const handleClick = e => {
23+
const handleClick = (e) => {
2424
e.preventDefault()
2525
router.push(href)
2626
}
@@ -178,7 +178,7 @@ import { useCallback, useEffect } from 'react'
178178
import Router from 'next/router'
179179

180180
export default function Login() {
181-
const handleSubmit = useCallback(e => {
181+
const handleSubmit = useCallback((e) => {
182182
e.preventDefault()
183183

184184
fetch('/api/login', {
@@ -187,7 +187,7 @@ export default function Login() {
187187
body: JSON.stringify({
188188
/* Form data */
189189
}),
190-
}).then(res => {
190+
}).then((res) => {
191191
// Do a fast client-side transition to the already prefetched dashboard page
192192
if (res.ok) Router.push('/dashboard')
193193
})
@@ -283,7 +283,7 @@ For example, to listen to the router event `routeChangeStart`, do the following:
283283
```jsx
284284
import Router from 'next/router'
285285

286-
const handleRouteChange = url => {
286+
const handleRouteChange = (url) => {
287287
console.log('App is changing to: ', url)
288288
}
289289

@@ -316,7 +316,7 @@ Router events should be registered when a component mounts ([useEffect](https://
316316
import Router from 'next/router'
317317

318318
useEffect(() => {
319-
const handleRouteChange = url => {
319+
const handleRouteChange = (url) => {
320320
console.log('App is changing to: ', url)
321321
}
322322

docs/api-routes/api-middlewares.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const cors = Cors({
9494
// And to throw an error when an error happens in a middleware
9595
function runMiddleware(req, res, fn) {
9696
return new Promise((resolve, reject) => {
97-
fn(req, res, result => {
97+
fn(req, res, (result) => {
9898
if (result instanceof Error) {
9999
return reject(result)
100100
}

docs/basic-features/data-fetching.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Here’s an example which uses `getStaticProps` to fetch a list of blog posts fr
5656
function Blog({ posts }) {
5757
return (
5858
<ul>
59-
{posts.map(post => (
59+
{posts.map((post) => (
6060
<li>{post.title}</li>
6161
))}
6262
</ul>
@@ -100,7 +100,7 @@ For TypeScript, you can use the `GetStaticProps` type from `next`:
100100
```ts
101101
import { GetStaticProps } from 'next'
102102

103-
export const getStaticProps: GetStaticProps = async context => {
103+
export const getStaticProps: GetStaticProps = async (context) => {
104104
// ...
105105
}
106106
```
@@ -123,7 +123,7 @@ import path from 'path'
123123
function Blog({ posts }) {
124124
return (
125125
<ul>
126-
{posts.map(post => (
126+
{posts.map((post) => (
127127
<li>
128128
<h3>{post.filename}</h3>
129129
<p>{post.content}</p>
@@ -140,7 +140,7 @@ export async function getStaticProps() {
140140
const postsDirectory = path.join(process.cwd(), 'posts')
141141
const filenames = fs.readdirSync(postsDirectory)
142142

143-
const posts = filenames.map(filename => {
143+
const posts = filenames.map((filename) => {
144144
const filePath = path.join(postsDirectory, filename)
145145
const fileContents = fs.readFileSync(filePath, 'utf8')
146146

@@ -260,7 +260,7 @@ export async function getStaticPaths() {
260260
const posts = await res.json()
261261

262262
// Get the paths we want to pre-render based on posts
263-
const paths = posts.map(post => ({
263+
const paths = posts.map((post) => ({
264264
params: { id: post.id },
265265
}))
266266

@@ -445,7 +445,7 @@ For TypeScript, you can use the `GetServerSideProps` type from `next`:
445445
```ts
446446
import { GetServerSideProps } from 'next'
447447

448-
export const getServerSideProps: GetServerSideProps = async context => {
448+
export const getServerSideProps: GetServerSideProps = async (context) => {
449449
// ...
450450
}
451451
```

docs/basic-features/pages.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Some pages require fetching external data for pre-rendering. There are two scena
9393
function Blog({ posts }) {
9494
return (
9595
<ul>
96-
{posts.map(post => (
96+
{posts.map((post) => (
9797
<li>{post.title}</li>
9898
))}
9999
</ul>
@@ -152,7 +152,7 @@ export async function getStaticPaths() {
152152
const posts = await res.json()
153153

154154
// Get the paths we want to pre-render based on posts
155-
const paths = posts.map(post => `/posts/${post.id}`)
155+
const paths = posts.map((post) => `/posts/${post.id}`)
156156

157157
// We'll pre-render only these paths at build time.
158158
// { fallback: false } means other routes should 404.

docs/basic-features/typescript.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ For `getStaticProps`, `getStaticPaths`, and `getServerSideProps`, you can use th
5454
```ts
5555
import { GetStaticProps, GetStaticPaths, GetServerSideProps } from 'next'
5656

57-
export const getStaticProps: GetStaticProps = async context => {
57+
export const getStaticProps: GetStaticProps = async (context) => {
5858
// ...
5959
}
6060

6161
export const getStaticPaths: GetStaticPaths = async () => {
6262
// ...
6363
}
6464

65-
export const getServerSideProps: GetServerSideProps = async context => {
65+
export const getServerSideProps: GetServerSideProps = async (context) => {
6666
// ...
6767
}
6868
```

docs/routing/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ The `as` prop can also be generated dynamically. For example, to show a list of
9090
function Home({ posts }) {
9191
return (
9292
<ul>
93-
{posts.map(post => (
93+
{posts.map((post) => (
9494
<li key={post.id}>
9595
<Link href="/blog/[slug]" as={`/blog/${post.slug}`}>
9696
<a>{post.title}</a>

docs/upgrading.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ import dynamic from 'next/dynamic'
171171
const HelloBundle = dynamic({
172172
modules: () => {
173173
const components = {
174-
Hello1: () => import('../components/hello1').then(m => m.default),
175-
Hello2: () => import('../components/hello2').then(m => m.default),
174+
Hello1: () => import('../components/hello1').then((m) => m.default),
175+
Hello2: () => import('../components/hello2').then((m) => m.default),
176176
}
177177

178178
return components

errors/export-path-mismatch.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Change your `exportPathMap` function in `next.config.js` to have a path that mat
1111

1212
```js
1313
module.exports = {
14-
exportPathMap: function() {
14+
exportPathMap: function () {
1515
return {
1616
'/': { page: '/' },
1717
// '/blog/nextjs': { page: '/blog/[post]/comment/[id]' }, // wrong

errors/get-initial-props-as-an-instance-method.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class YourEntryComponent extends React.Component {
2323
or
2424

2525
```js
26-
const YourEntryComponent = function() {
26+
const YourEntryComponent = function () {
2727
return 'foo'
2828
}
2929

errors/next-dynamic-modules.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import dynamic from 'next/dynamic'
1818
const HelloBundle = dynamic({
1919
modules: () => {
2020
const components = {
21-
Hello1: () => import('../components/hello1').then(m => m.default),
22-
Hello2: () => import('../components/hello2').then(m => m.default),
21+
Hello1: () => import('../components/hello1').then((m) => m.default),
22+
Hello2: () => import('../components/hello2').then((m) => m.default),
2323
}
2424

2525
return components

errors/no-on-app-updated-hook.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Due to [this bug fix](https://github.com/zeit/next.js/pull/3849), we had to remo
55
We use this hook to detect a new app deployment when switching pages and act accordingly. Although there are many things you can do in this hook, it's often used to navigate the page via the server as shown below:
66

77
```js
8-
Router.onAppUpdated = function(nextRoute) {
8+
Router.onAppUpdated = function (nextRoute) {
99
location.href = nextRoute
1010
}
1111
```
@@ -17,7 +17,7 @@ One real use of this hook is to persist your application state to local-storage
1717
This is code for that:
1818

1919
```js
20-
window.onbeforeunload = function(e) {
20+
window.onbeforeunload = function (e) {
2121
// Get the application state (usually from a store like Redux)
2222
const appState = {}
2323
localStorage.setItem('app-state', JSON.stringify(appState))

errors/promise-in-next-config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The webpack function in `next.config.js` returned a promise which is not support
66

77
```js
88
module.exports = {
9-
webpack: async function(config) {
9+
webpack: async function (config) {
1010
return config
1111
},
1212
}

examples/amp-first/components/Layout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const THEME_COLOR = '#005af0'
1010
*
1111
* @param {Props} props
1212
*/
13-
const Layout = props => (
13+
const Layout = (props) => (
1414
<>
1515
<NextHead>
1616
<title>{props.title || ''}</title>

examples/amp-first/pages/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99

1010
export const config = { amp: true }
1111

12-
const Home = props => (
12+
const Home = (props) => (
1313
<>
1414
<Layout
1515
title="Welcome to AMP"

examples/api-routes-apollo-server-and-client-auth/apollo/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
3737
}
3838

3939
if (ssr || PageComponent.getInitialProps) {
40-
WithApollo.getInitialProps = async ctx => {
40+
WithApollo.getInitialProps = async (ctx) => {
4141
const { AppTree } = ctx
4242

4343
// Initialize ApolloClient, add it to the ctx object so

examples/api-routes-apollo-server-and-client-auth/apollo/resolvers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const resolvers = {
3131
try {
3232
const { id, email } = jwt.verify(token, JWT_SECRET)
3333

34-
return users.find(user => user.id === id && user.email === email)
34+
return users.find((user) => user.id === id && user.email === email)
3535
} catch {
3636
throw new AuthenticationError(
3737
'Authentication token is invalid, please log in'
@@ -50,7 +50,7 @@ export const resolvers = {
5050
},
5151

5252
async signIn(_parent, args, context, _info) {
53-
const user = users.find(user => user.email === args.input.email)
53+
const user = users.find((user) => user.email === args.input.email)
5454

5555
if (user && validPassword(user, args.input.password)) {
5656
const token = jwt.sign(

examples/api-routes-apollo-server-and-client/apollo/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function withApollo(PageComponent, { ssr = true } = {}) {
3737
}
3838

3939
if (ssr || PageComponent.getInitialProps) {
40-
WithApollo.getInitialProps = async ctx => {
40+
WithApollo.getInitialProps = async (ctx) => {
4141
const { AppTree } = ctx
4242

4343
// Initialize ApolloClient, add it to the ctx object so

examples/api-routes-cors/lib/init-middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export default function initMiddleware(middleware) {
44
return (req, res) =>
55
new Promise((resolve, reject) => {
6-
middleware(req, res, result => {
6+
middleware(req, res, (result) => {
77
if (result instanceof Error) {
88
return reject(result)
99
}

examples/api-routes-graphql/pages/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import useSWR from 'swr'
22

3-
const fetcher = query =>
3+
const fetcher = (query) =>
44
fetch('/api/graphql', {
55
method: 'POST',
66
headers: {
77
'Content-type': 'application/json',
88
},
99
body: JSON.stringify({ query }),
1010
})
11-
.then(res => res.json())
12-
.then(json => json.data)
11+
.then((res) => res.json())
12+
.then((json) => json.data)
1313

1414
export default function Index() {
1515
const { data, error } = useSWR('{ users { name } }', fetcher)

0 commit comments

Comments
 (0)