Skip to content

Commit e6f9017

Browse files
committedJan 12, 2018
Just Use Prettier™
Wise words from the immortal @vjeux himself https://twitter.com/Vjeux/status/951538552675868673
1 parent 74a3d0e commit e6f9017

Some content is hidden

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

71 files changed

+3200
-3053
lines changed
 

‎.watchmanconfig

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,190 +1,190 @@
1-
import React from 'react'
2-
import ReactDOMServer from 'react-dom/server'
3-
import StaticRouter from 'react-router/StaticRouter'
4-
import matchRoutes from '../matchRoutes'
5-
import renderRoutes from '../renderRoutes'
1+
import React from "react";
Has comments. Original line has comments.
2+
import ReactDOMServer from "react-dom/server";
3+
import StaticRouter from "react-router/StaticRouter";
4+
import matchRoutes from "../matchRoutes";
5+
import renderRoutes from "../renderRoutes";
66

7-
describe('integration', () => {
8-
it('generates the same matches in renderRoutes and matchRoutes', () => {
9-
const rendered = []
7+
describe("integration", () => {
8+
it("generates the same matches in renderRoutes and matchRoutes", () => {
9+
const rendered = [];
1010

1111
const Comp = ({ match, route: { routes } }) => (
12-
rendered.push(match),
13-
renderRoutes(routes)
14-
)
12+
rendered.push(match), renderRoutes(routes)
13+
);
1514

1615
const routes = [
17-
{ path: '/pepper',
16+
{
17+
path: "/pepper",
1818
component: Comp,
1919
routes: [
20-
{ path: '/pepper/:type',
20+
{
21+
path: "/pepper/:type",
2122
component: Comp,
2223
routes: [
23-
{ path: '/pepper/:type/scoville',
24+
{
25+
path: "/pepper/:type/scoville",
2426
component: Comp
2527
}
2628
]
2729
}
2830
]
2931
},
3032

31-
{ path: undefined,
33+
{
34+
path: undefined,
3235
component: Comp,
3336
routes: [
34-
{ path: '/ghost',
37+
{
38+
path: "/ghost",
3539
component: Comp
3640
}
3741
]
3842
}
39-
]
43+
];
4044

41-
const pathname = '/pepper/jalepeno'
42-
const branch = matchRoutes(routes, pathname)
45+
const pathname = "/pepper/jalepeno";
46+
const branch = matchRoutes(routes, pathname);
4347
ReactDOMServer.renderToString(
4448
<StaticRouter location={pathname} context={{}}>
4549
{renderRoutes(routes)}
4650
</StaticRouter>
47-
)
48-
expect(branch.length).toEqual(2)
49-
expect(rendered.length).toEqual(2)
50-
expect(branch[0].match).toEqual(rendered[0])
51-
expect(branch[1].match).toEqual(rendered[1])
52-
})
51+
);
52+
expect(branch.length).toEqual(2);
53+
expect(rendered.length).toEqual(2);
54+
expect(branch[0].match).toEqual(rendered[0]);
55+
expect(branch[1].match).toEqual(rendered[1]);
56+
});
5357

54-
55-
56-
it('generates the same matches in renderRoutes and matchRoutes with pathless routes', () => {
57-
const rendered = []
58+
it("generates the same matches in renderRoutes and matchRoutes with pathless routes", () => {
59+
const rendered = [];
5860

5961
const Comp = ({ match, route: { routes } }) => (
60-
rendered.push(match),
61-
renderRoutes(routes)
62-
)
62+
rendered.push(match), renderRoutes(routes)
63+
);
6364

6465
const routes = [
65-
{ path: '/pepper',
66+
{
67+
path: "/pepper",
6668
component: Comp,
6769
routes: [
68-
{ path: '/pepper/:type',
70+
{
71+
path: "/pepper/:type",
6972
component: Comp,
7073
routes: [
71-
{ path: '/pepper/:type/scoville',
74+
{
75+
path: "/pepper/:type/scoville",
7276
component: Comp
7377
}
7478
]
7579
}
7680
]
7781
},
7882

79-
{ path: undefined,
83+
{
84+
path: undefined,
8085
component: Comp,
8186
routes: [
82-
{ path: '/ghost',
87+
{
88+
path: "/ghost",
8389
component: Comp
8490
}
8591
]
8692
}
87-
]
93+
];
8894

89-
const pathname = '/ghost'
90-
const branch = matchRoutes(routes, pathname)
95+
const pathname = "/ghost";
96+
const branch = matchRoutes(routes, pathname);
9197
ReactDOMServer.renderToString(
9298
<StaticRouter location={pathname} context={{}}>
9399
{renderRoutes(routes)}
94100
</StaticRouter>
95-
)
96-
expect(branch.length).toEqual(2)
97-
expect(rendered.length).toEqual(2)
98-
expect(branch[0].match).toEqual(rendered[0])
99-
expect(branch[1].match).toEqual(rendered[1])
100-
})
101-
101+
);
102+
expect(branch.length).toEqual(2);
103+
expect(rendered.length).toEqual(2);
104+
expect(branch[0].match).toEqual(rendered[0]);
105+
expect(branch[1].match).toEqual(rendered[1]);
106+
});
102107

103-
104-
it('generates the same matches in renderRoutes and matchRoutes with routes using exact', () => {
105-
const rendered = []
108+
it("generates the same matches in renderRoutes and matchRoutes with routes using exact", () => {
109+
const rendered = [];
106110

107111
const Comp = ({ match, route: { routes } }) => (
108-
rendered.push(match),
109-
renderRoutes(routes)
110-
)
112+
rendered.push(match), renderRoutes(routes)
113+
);
111114

112115
const routes = [
113116
// should skip
114117
{
115-
path: '/pepper/habanero',
118+
path: "/pepper/habanero",
116119
component: Comp,
117120
exact: true
118121
},
119122
// should match
120123
{
121-
path: '/pepper',
124+
path: "/pepper",
122125
component: Comp,
123126
exact: true
124127
}
125-
]
128+
];
126129

127-
const pathname = '/pepper'
128-
const branch = matchRoutes(routes, pathname)
130+
const pathname = "/pepper";
131+
const branch = matchRoutes(routes, pathname);
129132
ReactDOMServer.renderToString(
130133
<StaticRouter location={pathname} context={{}}>
131134
{renderRoutes(routes)}
132135
</StaticRouter>
133-
)
134-
expect(branch.length).toEqual(1)
135-
expect(rendered.length).toEqual(1)
136-
expect(branch[0].match).toEqual(rendered[0])
137-
})
138-
139-
136+
);
137+
expect(branch.length).toEqual(1);
138+
expect(rendered.length).toEqual(1);
139+
expect(branch[0].match).toEqual(rendered[0]);
140+
});
140141

141-
it('generates the same matches in renderRoutes and matchRoutes with routes using exact + strict', () => {
142-
const rendered = []
142+
it("generates the same matches in renderRoutes and matchRoutes with routes using exact + strict", () => {
143+
const rendered = [];
143144

144145
const Comp = ({ match, route: { routes } }) => (
145-
rendered.push(match),
146-
renderRoutes(routes)
147-
)
146+
rendered.push(match), renderRoutes(routes)
147+
);
148148

149149
const routes = [
150150
// should match
151151
{
152-
path: '/pepper/',
152+
path: "/pepper/",
153153
component: Comp,
154154
strict: true,
155155
exact: true,
156156
routes: [
157157
// should skip
158158
{
159-
path: '/pepper',
159+
path: "/pepper",
160160
component: Comp,
161161
strict: true,
162162
exact: true
163163
}
164164
]
165165
}
166-
]
166+
];
167167

168-
let pathname = '/pepper'
169-
let branch = matchRoutes(routes, pathname)
168+
let pathname = "/pepper";
169+
let branch = matchRoutes(routes, pathname);
170170
ReactDOMServer.renderToString(
171171
<StaticRouter location={pathname} context={{}}>
172172
{renderRoutes(routes)}
173173
</StaticRouter>
174-
)
175-
expect(branch.length).toEqual(0)
176-
expect(rendered.length).toEqual(0)
174+
);
175+
expect(branch.length).toEqual(0);
176+
expect(rendered.length).toEqual(0);
177177

178-
pathname = '/pepper/'
179-
branch = matchRoutes(routes, pathname)
178+
pathname = "/pepper/";
179+
branch = matchRoutes(routes, pathname);
180180
ReactDOMServer.renderToString(
181181
<StaticRouter location={pathname} context={{}}>
182182
{renderRoutes(routes)}
183183
</StaticRouter>
184-
)
184+
);
185185

186-
expect(branch.length).toEqual(1)
187-
expect(rendered.length).toEqual(1)
188-
expect(branch[0].match).toEqual(rendered[0])
189-
})
190-
})
186+
expect(branch.length).toEqual(1);
187+
expect(rendered.length).toEqual(1);
188+
expect(branch[0].match).toEqual(rendered[0]);
189+
});
190+
});

8 commit comments

Comments
 (8)

pshrmn commented on Jan 12, 2018

@pshrmn
Contributor

Those beautiful semicolons 😍

timdorr commented on Jan 12, 2018

@timdorr
Member

Well, this breaks pretty much every PR :P

mjackson commented on Jan 12, 2018

@mjackson
MemberAuthor

@timdorr Fixing them is as easy as running prettier --write. No customizations whatsoever

pshrmn commented on Jan 12, 2018

@pshrmn
Contributor

It would probably be best to make prettier a dev dep and add scripts to the packages so that it is easy for anyone making a PR to have their code correctly formatted. I've also seen some projects setup prettier to run pre-commit, although I'm not sure if you want that behavior here.

timdorr commented on Jan 12, 2018

@timdorr
Member

It's just that many are old and abandoned, so no one is at the wheel to run that command.

Note: I'm a Prettier user via text editor plugin, so I'm on board with this.

timdorr commented on Jan 12, 2018

@timdorr
Member

@pshrmn We landed that on Redux in reduxjs/redux#2676. Works well.

mjackson commented on Jan 12, 2018

@mjackson
MemberAuthor

@pshrmn @timdorr Feel free to make a PR that auto-formats stuff. I use vim-prettier to auto-format everything on save. Not sure the best strategy for doing this on a project level.

pshrmn commented on Jan 12, 2018

@pshrmn
Contributor
Please sign in to comment.