Skip to content

Commit

Permalink
Just Use Prettier™
Browse files Browse the repository at this point in the history
Wise words from the immortal @vjeux himself
https://twitter.com/Vjeux/status/951538552675868673
  • Loading branch information
mjackson committed Jan 12, 2018
1 parent 74a3d0e commit e6f9017
Show file tree
Hide file tree
Showing 71 changed files with 3,200 additions and 3,053 deletions.
Empty file removed .watchmanconfig
Empty file.
172 changes: 86 additions & 86 deletions packages/react-router-config/modules/__tests__/integration-test.js
Original file line number Diff line number Diff line change
@@ -1,190 +1,190 @@
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import StaticRouter from 'react-router/StaticRouter'
import matchRoutes from '../matchRoutes'
import renderRoutes from '../renderRoutes'
import React from "react";

This comment has been minimized.

Copy link
@vjeux

vjeux Jan 12, 2018

Feel free to use single quote and no semi option. They are meant to be used.

This comment has been minimized.

Copy link
@mjackson

mjackson Jan 12, 2018

Author Member

I use --no-semi on most of my projects, but I'm over it at this point. I'll just go with whatever defaults you guys decide on.

import ReactDOMServer from "react-dom/server";
import StaticRouter from "react-router/StaticRouter";
import matchRoutes from "../matchRoutes";
import renderRoutes from "../renderRoutes";

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

const Comp = ({ match, route: { routes } }) => (
rendered.push(match),
renderRoutes(routes)
)
rendered.push(match), renderRoutes(routes)
);

const routes = [
{ path: '/pepper',
{
path: "/pepper",
component: Comp,
routes: [
{ path: '/pepper/:type',
{
path: "/pepper/:type",
component: Comp,
routes: [
{ path: '/pepper/:type/scoville',
{
path: "/pepper/:type/scoville",
component: Comp
}
]
}
]
},

{ path: undefined,
{
path: undefined,
component: Comp,
routes: [
{ path: '/ghost',
{
path: "/ghost",
component: Comp
}
]
}
]
];

const pathname = '/pepper/jalepeno'
const branch = matchRoutes(routes, pathname)
const pathname = "/pepper/jalepeno";
const branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
<StaticRouter location={pathname} context={{}}>
{renderRoutes(routes)}
</StaticRouter>
)
expect(branch.length).toEqual(2)
expect(rendered.length).toEqual(2)
expect(branch[0].match).toEqual(rendered[0])
expect(branch[1].match).toEqual(rendered[1])
})
);
expect(branch.length).toEqual(2);
expect(rendered.length).toEqual(2);
expect(branch[0].match).toEqual(rendered[0]);
expect(branch[1].match).toEqual(rendered[1]);
});



it('generates the same matches in renderRoutes and matchRoutes with pathless routes', () => {
const rendered = []
it("generates the same matches in renderRoutes and matchRoutes with pathless routes", () => {
const rendered = [];

const Comp = ({ match, route: { routes } }) => (
rendered.push(match),
renderRoutes(routes)
)
rendered.push(match), renderRoutes(routes)
);

const routes = [
{ path: '/pepper',
{
path: "/pepper",
component: Comp,
routes: [
{ path: '/pepper/:type',
{
path: "/pepper/:type",
component: Comp,
routes: [
{ path: '/pepper/:type/scoville',
{
path: "/pepper/:type/scoville",
component: Comp
}
]
}
]
},

{ path: undefined,
{
path: undefined,
component: Comp,
routes: [
{ path: '/ghost',
{
path: "/ghost",
component: Comp
}
]
}
]
];

const pathname = '/ghost'
const branch = matchRoutes(routes, pathname)
const pathname = "/ghost";
const branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
<StaticRouter location={pathname} context={{}}>
{renderRoutes(routes)}
</StaticRouter>
)
expect(branch.length).toEqual(2)
expect(rendered.length).toEqual(2)
expect(branch[0].match).toEqual(rendered[0])
expect(branch[1].match).toEqual(rendered[1])
})

);
expect(branch.length).toEqual(2);
expect(rendered.length).toEqual(2);
expect(branch[0].match).toEqual(rendered[0]);
expect(branch[1].match).toEqual(rendered[1]);
});


it('generates the same matches in renderRoutes and matchRoutes with routes using exact', () => {
const rendered = []
it("generates the same matches in renderRoutes and matchRoutes with routes using exact", () => {
const rendered = [];

const Comp = ({ match, route: { routes } }) => (
rendered.push(match),
renderRoutes(routes)
)
rendered.push(match), renderRoutes(routes)
);

const routes = [
// should skip
{
path: '/pepper/habanero',
path: "/pepper/habanero",
component: Comp,
exact: true
},
// should match
{
path: '/pepper',
path: "/pepper",
component: Comp,
exact: true
}
]
];

const pathname = '/pepper'
const branch = matchRoutes(routes, pathname)
const pathname = "/pepper";
const branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
<StaticRouter location={pathname} context={{}}>
{renderRoutes(routes)}
</StaticRouter>
)
expect(branch.length).toEqual(1)
expect(rendered.length).toEqual(1)
expect(branch[0].match).toEqual(rendered[0])
})


);
expect(branch.length).toEqual(1);
expect(rendered.length).toEqual(1);
expect(branch[0].match).toEqual(rendered[0]);
});

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

const Comp = ({ match, route: { routes } }) => (
rendered.push(match),
renderRoutes(routes)
)
rendered.push(match), renderRoutes(routes)
);

const routes = [
// should match
{
path: '/pepper/',
path: "/pepper/",
component: Comp,
strict: true,
exact: true,
routes: [
// should skip
{
path: '/pepper',
path: "/pepper",
component: Comp,
strict: true,
exact: true
}
]
}
]
];

let pathname = '/pepper'
let branch = matchRoutes(routes, pathname)
let pathname = "/pepper";
let branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
<StaticRouter location={pathname} context={{}}>
{renderRoutes(routes)}
</StaticRouter>
)
expect(branch.length).toEqual(0)
expect(rendered.length).toEqual(0)
);
expect(branch.length).toEqual(0);
expect(rendered.length).toEqual(0);

pathname = '/pepper/'
branch = matchRoutes(routes, pathname)
pathname = "/pepper/";
branch = matchRoutes(routes, pathname);
ReactDOMServer.renderToString(
<StaticRouter location={pathname} context={{}}>
{renderRoutes(routes)}
</StaticRouter>
)
);

expect(branch.length).toEqual(1)
expect(rendered.length).toEqual(1)
expect(branch[0].match).toEqual(rendered[0])
})
})
expect(branch.length).toEqual(1);
expect(rendered.length).toEqual(1);
expect(branch[0].match).toEqual(rendered[0]);
});
});
Loading

8 comments on commit e6f9017

@pshrmn
Copy link
Contributor

@pshrmn pshrmn commented on e6f9017 Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those beautiful semicolons 😍

@timdorr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this breaks pretty much every PR :P

@mjackson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@pshrmn
Copy link
Contributor

@pshrmn pshrmn commented on e6f9017 Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mjackson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Contributor

@pshrmn pshrmn commented on e6f9017 Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.