From 756c821a4674190afe1710a75c53b01835bda770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olle=20Lauri=20Bostr=C3=B6m?= Date: Thu, 7 Mar 2019 21:11:08 +0100 Subject: [PATCH 1/3] chore: Run prettier/tslint in ci --- package.json | 9 ++++++--- tslint.json | 3 +++ yarn.lock | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 825356977e..dfc0d3dd70 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,11 @@ "build": "gatsby build", "build-ci": "gatsby build --prefix-paths", "start": "gatsby develop", - "format": "prettier --write '**/*.tsx'", - "test": "jest" + "format": "prettier --write **/*.{ts,tsx,js} !.cache !public", + "format-check": "prettier --check **/*.{ts,tsx,js} !.cache !public", + "jest": "jest", + "test": "yarn run jest && yarn run format-check && yarn run tslint", + "tslint": "tslint --project ./tsconfig.json" }, "devDependencies": { "@babel/core": "^7.3.3", @@ -57,7 +60,7 @@ "husky": "^1.3.1", "identity-obj-proxy": "^3.0.0", "jest": "^24.1.0", - "prettier": "^1.14.2", + "prettier": "^1.16.4", "react-test-renderer": "^16.8.2", "tslint-config-prettier": "^1.15.0", "tslint-react": "^3.6.0" diff --git a/tslint.json b/tslint.json index 5d4701fd5a..10e7dfce13 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,8 @@ { "extends": ["tslint-react", "tslint-config-prettier"], + "jsRules": { + "no-empty": true + }, "rules": { "array-type": [true, "array"], "arrow-return-shorthand": true, diff --git a/yarn.lock b/yarn.lock index b0dcb36559..17a884a8fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9564,9 +9564,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@^1.14.2: - version "1.15.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.3.tgz#1feaac5bdd181237b54dbe65d874e02a1472786a" +prettier@^1.16.4: + version "1.16.4" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717" + integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g== pretty-bytes@^4.0.2: version "4.0.2" From ef0b2780d9b3bbe17230d19d8645fdeca5aa358f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olle=20Lauri=20Bostr=C3=B6m?= Date: Thu, 7 Mar 2019 21:15:29 +0100 Subject: [PATCH 2/3] style: Format all files --- src/components/article.tsx | 10 ++++++---- src/components/hero.tsx | 14 +++++++------- src/components/navigation-item.tsx | 9 +++++++-- src/components/pagination.tsx | 6 +++--- src/components/seo.tsx | 18 +++++++++--------- src/config.js | 2 +- src/pages/404.tsx | 16 ++++++++-------- src/util/scrollTo.tsx | 21 ++++++++++++++++----- test/components/author-link.test.tsx | 4 +++- test/components/header.test.tsx | 14 +++++++------- test/components/hero.test.tsx | 2 +- test/components/seo.test.tsx | 8 +------- 12 files changed, 69 insertions(+), 55 deletions(-) diff --git a/src/components/article.tsx b/src/components/article.tsx index a6e07664c3..1feaaae451 100644 --- a/src/components/article.tsx +++ b/src/components/article.tsx @@ -30,11 +30,13 @@ const Article = ({ flexWrap: 'wrap', marginTop: '5rem', alignItems: 'center', - }}> + }} + > Contributors: - {authors && authors.map(author => ( - author && - ))} + {authors && + authors.map( + author => author && + )} diff --git a/src/components/hero.tsx b/src/components/hero.tsx index aecf93dbb0..580ef153ed 100644 --- a/src/components/hero.tsx +++ b/src/components/hero.tsx @@ -2,19 +2,19 @@ import React from 'react'; type Props = { title: string; -} +}; const Hero = ({ title }: Props) => (

{title}

-
-
-
-
+
+
+
+
-) +); -export default Hero +export default Hero; diff --git a/src/components/navigation-item.tsx b/src/components/navigation-item.tsx index 3318abab55..2d1ba27b61 100644 --- a/src/components/navigation-item.tsx +++ b/src/components/navigation-item.tsx @@ -17,7 +17,7 @@ const NavigationItem = ({ isDone, isActive, slug, title, onClick }: Props) => { if (ref && isActive) { element.current = ref; } - } + }; useEffect(() => { if (element.current) { @@ -34,7 +34,12 @@ const NavigationItem = ({ isDone, isActive, slug, title, onClick }: Props) => { } return ( - + {title} ); diff --git a/src/components/pagination.tsx b/src/components/pagination.tsx index 3d0f65213d..cf25cba310 100644 --- a/src/components/pagination.tsx +++ b/src/components/pagination.tsx @@ -6,7 +6,7 @@ import { PaginationInfo } from '../types'; type Props = { previous?: PaginationInfo; next?: PaginationInfo; -} +}; const ulStyles: SerializedStyles = css` display: flex; @@ -33,6 +33,6 @@ const Pagination = ({ previous, next }: Props) => ( )} -) +); -export default Pagination +export default Pagination; diff --git a/src/components/seo.tsx b/src/components/seo.tsx index 53e39e550d..8482023493 100644 --- a/src/components/seo.tsx +++ b/src/components/seo.tsx @@ -1,12 +1,12 @@ -import React from 'react' -import { Helmet } from 'react-helmet' -import config from '../config' +import React from 'react'; +import { Helmet } from 'react-helmet'; +import config from '../config'; type Props = { - title?: string - description?: string - img?: string -} + title?: string; + description?: string; + img?: string; +}; const SEO = ({ title, description, img }: Props) => ( ( > -) +); -export default SEO +export default SEO; diff --git a/src/config.js b/src/config.js index 44fb85a163..902541968b 100644 --- a/src/config.js +++ b/src/config.js @@ -20,4 +20,4 @@ module.exports = { twitterCard: `summary`, twitterImgAlt: `The Node.js Hexagon Logo`, facebook: `https://www.facebook.com/nodejsfoundation/`, -} +}; diff --git a/src/pages/404.tsx b/src/pages/404.tsx index e92213a8f3..86e530c7b2 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -14,14 +14,14 @@ export default (props: Props) => { return ( -
-

- The page you're trying to access does not exist. Go back to the - Homepage or find what you're looking for in the menu. -

-

- Take me back to the Homepage → -

+
+

+ The page you're trying to access does not exist. Go back to the + Homepage or find what you're looking for in the menu. +

+

+ Take me back to the Homepage → +

); diff --git a/src/util/scrollTo.tsx b/src/util/scrollTo.tsx index 00ad921f39..fb49a149ff 100644 --- a/src/util/scrollTo.tsx +++ b/src/util/scrollTo.tsx @@ -1,7 +1,15 @@ -const easeInOutCubic = (t: number, b: number, c: number, d: number) => (t /= d / 2) < 1 ? c / 2 * t * t * t + b : c / 2 * ((t -= 2) * t * t + 2) + b; +const easeInOutCubic = (t: number, b: number, c: number, d: number) => + (t /= d / 2) < 1 + ? (c / 2) * t * t * t + b + : (c / 2) * ((t -= 2) * t * t + 2) + b; -export function scrollTo(scrollTo: number, duration: number = 333): Promise { - const start = (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0); +export function scrollTo( + scrollTo: number, + duration: number = 333 +): Promise { + const start = + (window.pageYOffset || document.documentElement.scrollTop) - + (document.documentElement.clientTop || 0); const change = scrollTo - start; let previousTime = window.performance.now(); let currentTime = 0; @@ -12,7 +20,10 @@ export function scrollTo(scrollTo: number, duration: number = 333): Promise { it('renders correctly', () => { const username = 'test-author'; - const tree = renderer.create().toJSON(); + const tree = renderer + .create() + .toJSON(); expect(tree).toMatchSnapshot(); }); it('does not render without a username', () => { diff --git a/test/components/header.test.tsx b/test/components/header.test.tsx index 8cc8fc1384..35d1118c39 100644 --- a/test/components/header.test.tsx +++ b/test/components/header.test.tsx @@ -1,10 +1,10 @@ -import React from 'react' -import renderer from 'react-test-renderer' -import Header from '../../src/components/header' +import React from 'react'; +import renderer from 'react-test-renderer'; +import Header from '../../src/components/header'; describe('Tests for Header component', () => { it('renders correctly', () => { - const tree = renderer.create(
).toJSON() - expect(tree).toMatchSnapshot() - }) -}) + const tree = renderer.create(
).toJSON(); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/test/components/hero.test.tsx b/test/components/hero.test.tsx index b49132f294..cc2d1d1783 100644 --- a/test/components/hero.test.tsx +++ b/test/components/hero.test.tsx @@ -5,7 +5,7 @@ import Hero from '../../src/components/hero'; describe('Hero component', () => { it('renders correctly', () => { const title = 'Introduction to Node.js'; - const tree = renderer.create().toJSON(); + const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); }); diff --git a/test/components/seo.test.tsx b/test/components/seo.test.tsx index e209fad334..dc2f03292c 100644 --- a/test/components/seo.test.tsx +++ b/test/components/seo.test.tsx @@ -8,13 +8,7 @@ describe('SEO component', () => { const title = 'title-mock'; const description = 'description-mock'; const img = 'image-mock'; - renderer.render( - - ); + renderer.render(); expect(renderer.getRenderOutput()).toMatchSnapshot(); }); it('uses config properties as fallback for missing props', () => { From 60a147b9559211a0dd13f6cdde13e27ed530709a Mon Sep 17 00:00:00 2001 From: ZYSzys Date: Fri, 8 Mar 2019 13:26:27 +0800 Subject: [PATCH 3/3] chore: Fix prettier --- .prettierignore | 3 +++ package.json | 4 ++-- src/util/createSlug.js | 12 ++++++------ test-setup.js | 2 +- test/util/createSlug.test.js | 4 ++-- test/util/onCreateNode.test.js | 6 +++--- 6 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000..110ae2a22f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +.cache/ +.github/ +public/ diff --git a/package.json b/package.json index dfc0d3dd70..a48091a253 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "build": "gatsby build", "build-ci": "gatsby build --prefix-paths", "start": "gatsby develop", - "format": "prettier --write **/*.{ts,tsx,js} !.cache !public", - "format-check": "prettier --check **/*.{ts,tsx,js} !.cache !public", + "format": "prettier --write '**/*.{ts,tsx,js}'", + "format-check": "prettier --check '**/*.{ts,tsx,js}'", "jest": "jest", "test": "yarn run jest && yarn run format-check && yarn run tslint", "tslint": "tslint --project ./tsconfig.json" diff --git a/src/util/createSlug.js b/src/util/createSlug.js index a7cb797fe6..ab3f525f04 100644 --- a/src/util/createSlug.js +++ b/src/util/createSlug.js @@ -2,9 +2,9 @@ function createSlug(title) { let slug = title.toLowerCase().trim(); const sets = [ - {to: 'nodejs', from: /node.js/ }, // Replace node.js - {to: '-and-', from: /&/ }, // Replace & - {to: '-', from: /[/_,:;\\ .]/g } // Replace /_,:;\. and whitespace + { to: 'nodejs', from: /node.js/ }, // Replace node.js + { to: '-and-', from: /&/ }, // Replace & + { to: '-', from: /[/_,:;\\ .]/g }, // Replace /_,:;\. and whitespace ]; sets.forEach(set => { @@ -13,9 +13,9 @@ function createSlug(title) { return slug .replace(/[^\w\-]+/g, '') // Remove any non word characters - .replace(/--+/g, '-') // Replace multiple hyphens with single - .replace(/^-/, '') // Remove any leading hyphen - .replace(/-$/, ''); // Remove any trailing hyphen + .replace(/--+/g, '-') // Replace multiple hyphens with single + .replace(/^-/, '') // Remove any leading hyphen + .replace(/-$/, ''); // Remove any trailing hyphen } module.exports = createSlug; diff --git a/test-setup.js b/test-setup.js index 37084c74aa..530bd30b3c 100644 --- a/test-setup.js +++ b/test-setup.js @@ -1,3 +1,3 @@ global.___loader = { enqueue: jest.fn(), -} +}; diff --git a/test/util/createSlug.test.js b/test/util/createSlug.test.js index 48e840c521..db0a0975a8 100644 --- a/test/util/createSlug.test.js +++ b/test/util/createSlug.test.js @@ -13,7 +13,7 @@ describe('Tests for createSlug', () => { 'title: subtitle', 'a; b', 'C:\\Program Files\\nodejs', - 'a---b' + 'a---b', ].map(createSlug); expect(slugs).toEqual([ 'how-to-install-nodejs', @@ -26,7 +26,7 @@ describe('Tests for createSlug', () => { 'title-subtitle', 'a-b', 'c-program-files-nodejs', - 'a-b' + 'a-b', ]); }); }); diff --git a/test/util/onCreateNode.test.js b/test/util/onCreateNode.test.js index ba7ddce423..674fde76e5 100644 --- a/test/util/onCreateNode.test.js +++ b/test/util/onCreateNode.test.js @@ -9,9 +9,9 @@ function createMockNodeOfType(type) { getNode: jest.fn(), node: { internal: { type }, - frontmatter: { title: 'Test title' } - } - } + frontmatter: { title: 'Test title' }, + }, + }; } describe('Tests for onCreateNode', () => {