Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit 79f91ac

Browse files
core: adding standard and lint-staged for code organization
1 parent 7e7af3a commit 79f91ac

File tree

16 files changed

+967
-85
lines changed

16 files changed

+967
-85
lines changed

api/posts/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import fetch from 'isomorphic-fetch'
22

3-
export function getPosts() {
3+
export function getPosts () {
44
return fetch('https://jsonplaceholder.typicode.com/posts')
55
}
66

7-
export function getPost(slug) {
7+
export function getPost (slug) {
88
return fetch(`https://jsonplaceholder.typicode.com/posts?title=${slug}`)
99
}

components/Footer/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import styled from 'styled-components';
1+
import styled from 'styled-components'
22

33
const Footer = styled.footer`
44
padding: 15px;
55
background: #F5F5F5;
6-
`;
6+
`
77

8-
export default Footer;
8+
export default Footer

components/Nav/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Link from 'next/link'
2-
import styled from 'styled-components';
2+
import styled from 'styled-components'
33

44
const Wrapper = styled.nav`
55
padding: 15px;
@@ -11,7 +11,7 @@ const Wrapper = styled.nav`
1111
padding: 0 15px;
1212
color: #FFF;
1313
}
14-
`;
14+
`
1515

1616
const Nav = () => (
1717
<Wrapper>
@@ -21,4 +21,4 @@ const Nav = () => (
2121
</Wrapper>
2222
)
2323

24-
export default Nav;
24+
export default Nav

components/Post/Wrapper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from 'styled-components';
1+
import styled from 'styled-components'
22

33
const Wrapper = styled.div`
44
border-bottom: 1px solid #ddd;
@@ -32,6 +32,6 @@ const Wrapper = styled.div`
3232
font-family: "PT Serif", sans-serif;
3333
margin: 0;
3434
}
35-
`;
35+
`
3636

37-
export default Wrapper;
37+
export default Wrapper

layouts/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export default ({ children, title = 'This is the default title' }) => (
2020
Footer
2121
</Footer>
2222
</Wrapper>
23-
)
23+
)

layouts/Wrapper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from 'styled-components';
1+
import styled from 'styled-components'
22

33
const Wrapper = styled.footer`
44
display: flex;
@@ -8,6 +8,6 @@ const Wrapper = styled.footer`
88
main {
99
flex: 1;
1010
}
11-
`;
11+
`
1212

13-
export default Wrapper;
13+
export default Wrapper

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ module.exports = {
1414
// Important: return the modified config
1515
return config
1616
}
17-
}
17+
}

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55
"scripts": {
66
"dev": "node server.js",
77
"build": "next build",
8-
"start": "NODE_PATH=. NODE_ENV=production node server.js"
8+
"start": "NODE_PATH=. NODE_ENV=production node server.js",
9+
"lint": "standard 'api/*' 'components/*' 'layouts/*' 'pages/*' 'styles/*' 'routes.js' 'server.js'",
10+
"precommit": "lint-staged"
911
},
1012
"dependencies": {
13+
"babel-eslint": "^7.2.3",
1114
"babel-plugin-module-resolver": "^2.7.1",
1215
"babel-plugin-styled-components": "^1.1.7",
1316
"express": "^4.15.4",
17+
"lint-staged": "^4.0.3",
1418
"next": "^3.0.6",
1519
"next-routes": "^1.0.40",
1620
"react": "^15.6.1",
1721
"react-dom": "^15.6.1",
22+
"standard": "^10.0.3",
1823
"styled-components": "^2.1.2"
1924
},
2025
"now": {
2126
"alias": "next-go"
27+
},
28+
"standard": {
29+
"parser": "babel-eslint",
30+
"ignore": ["**/node_modules/**"]
31+
},
32+
"lint-staged": {
33+
"*.js": "standard"
2234
}
2335
}

pages/_document.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Document, { Head, Main, NextScript } from 'next/document'
2-
import { ServerStyleSheet } from 'styled-components'
1+
import Document, { Head, Main, NextScript } from 'next/document';
2+
import { ServerStyleSheet } from 'styled-components';
33
import 'styles/global-styles';
44

55
export default class SiteDocument extends Document {
@@ -10,14 +10,14 @@ export default class SiteDocument extends Document {
1010
return (
1111
<html>
1212
<Head>
13-
<meta charSet="utf-8" />
14-
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
15-
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sanitize.css/2.0.0/sanitize.min.css" />
16-
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.7.4/tachyons.min.css" />
13+
<meta charSet='utf-8' />
14+
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
15+
<link rel='stylesheet' type='text/css' href='https://cdnjs.cloudflare.com/ajax/libs/sanitize.css/2.0.0/sanitize.min.css' />
16+
<link rel='stylesheet' type='text/css' href='https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.7.4/tachyons.min.css' />
1717
{styleTags}
1818
</Head>
1919
<body>
20-
<div className="root">
20+
<div className='root'>
2121
{main}
2222
</div>
2323
<NextScript />

pages/about.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import Layout from 'layouts/Main';
1+
import Layout from 'layouts/Main'
22

33
export default () => <Layout>About Page</Layout>

pages/contact.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import Layout from 'layouts/Main';
1+
import Layout from 'layouts/Main'
22

33
export default () => <Layout>Contact Page</Layout>

pages/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import React from 'react'
2-
import Layout from 'layouts/Main';
2+
import Layout from 'layouts/Main'
33
import { getPosts } from 'api/posts'
4-
import { Link } from 'routes'
54

65
import Post from 'components/Post'
76

8-
const IndexPage = ({ posts }) => (
7+
const IndexPage = ({ posts }) =>
98
<Layout>
109
<ul>
11-
{posts.map(p => (
12-
<Post key={p.title} post={p} />
13-
))}
10+
{posts.map(p => <Post key={p.title} post={p} />)}
1411
</ul>
1512
</Layout>
16-
)
1713

1814
IndexPage.getInitialProps = async ({ req }) => {
1915
const res = await getPosts()

pages/post.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
2-
import Link from 'next/link'
32
import styled from 'styled-components'
4-
import Layout from 'layouts/Main';
3+
import Layout from 'layouts/Main'
54
import { getPost } from 'api/posts'
65

76
const Wrapper = styled.div`
@@ -31,14 +30,17 @@ const Wrapper = styled.div`
3130
}
3231
`
3332

34-
const PostPage = ({ post }) => (
33+
const PostPage = ({ post }) =>
3534
<Layout>
3635
<Wrapper>
37-
<h1>{post.title}</h1>
38-
<p>{post.body}</p>
36+
<h1>
37+
{post.title}
38+
</h1>
39+
<p>
40+
{post.body}
41+
</p>
3942
</Wrapper>
4043
</Layout>
41-
)
4244

4345
PostPage.getInitialProps = async ({ query }) => {
4446
const res = await getPost(query.slug)

routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ const routes = module.exports = nextRoutes()
33

44
routes.add('index', '/')
55
routes.add('about', '/about')
6-
routes.add('post', '/blog/:slug')
6+
routes.add('post', '/blog/:slug')

styles/global-styles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { injectGlobal } from 'styled-components';
1+
import { injectGlobal } from 'styled-components'
22

33
injectGlobal`
44
ul {
55
margin: 0;
66
padding: 0;
77
}
8-
`;
8+
`

0 commit comments

Comments
 (0)