From dd18987f22a7c02ea84a9571a80b2b313c987dce Mon Sep 17 00:00:00 2001 From: Onur Laru Date: Sat, 2 Mar 2019 18:54:19 +0100 Subject: [PATCH 01/25] chore: Eslint / Prettier integration. --- .eslintrc | 35 ++++++++++++++++++++++ .prettierrc | 12 -------- package.json | 16 +++++++--- tslint.json | 83 ---------------------------------------------------- 4 files changed, 47 insertions(+), 99 deletions(-) create mode 100644 .eslintrc delete mode 100644 .prettierrc delete mode 100644 tslint.json diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000000..815408b6aa --- /dev/null +++ b/.eslintrc @@ -0,0 +1,35 @@ +{ + "root": true, + "plugins": ["@typescript-eslint", "react-hooks"], + "extends": [ + "airbnb", + "prettier/@typescript-eslint", + "plugin:@typescript-eslint/recommended" + ], + "env": { + "browser": true + }, + "settings": { + "import/resolver": { + "typescript": {} + } + }, + "rules": { + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn" + }, + "overrides": [ + { + "files": ["**/*.ts", "**/*.tsx"], + "parser": "@typescript-eslint/parser", + "rules": { + "react/jsx-filename-extension": "off", + "camelcase": "off", + "@typescript-eslint/camelcase": ["error", { "properties": "never" }], + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/indent": ["error", 2] + } + } + ] +} diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 5159a26f3b..0000000000 --- a/.prettierrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "printWidth": 80, - "tabWidth": 2, - "useTabs": false, - "semi": true, - "singleQuote": true, - "jsxSingleQuote": false, - "trailingComma": "es5", - "bracketSpacing": true, - "jsxBracketSameLine": false, - "arrowParens": "avoid" -} diff --git a/package.json b/package.json index ab6a3b5718..8293d20855 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "react-dom": "^16.8.0", "react-emotion": "^10.0.0", "react-helmet": "^5.2.0", - "tslint": "^5.11.0", "typescript": "^3.1.1" }, "keywords": [ @@ -66,10 +65,19 @@ "husky": "^1.3.1", "identity-obj-proxy": "^3.0.0", "jest": "^24.1.0", - "prettier": "^1.16.4", "react-test-renderer": "^16.8.2", - "tslint-config-prettier": "^1.15.0", - "tslint-react": "^3.6.0" + "@typescript-eslint/eslint-plugin": "^1.4.2", + "eslint": "^5.14.1", + "eslint-config-airbnb": "^17.1.0", + "eslint-config-prettier": "^4.1.0", + "eslint-import-resolver-typescript": "^1.1.1", + "eslint-plugin-import": "^2.16.0", + "eslint-plugin-jsx-a11y": "^6.2.1", + "eslint-plugin-prettier": "^3.0.1", + "eslint-plugin-react": "^7.12.4", + "eslint-plugin-react-hooks": "^1.4.0", + "prettier": "^1.16.4", + "typescript": "~3.2.1" }, "repository": { "type": "git", diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 10e7dfce13..0000000000 --- a/tslint.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "extends": ["tslint-react", "tslint-config-prettier"], - "jsRules": { - "no-empty": true - }, - "rules": { - "array-type": [true, "array"], - "arrow-return-shorthand": true, - "ban": false, - "class-name": true, - "comment-format": [true, "check-space"], - "curly": true, - "eofline": false, - "forin": true, - "import-blacklist": [true, "lodash-es"], - "indent": [true, "spaces"], - "interface-name": [true, "never-prefix"], - "jsdoc-format": true, - "jsx-boolean-value": [true, "never"], - "jsx-no-lambda": false, - "jsx-no-multiline-js": false, - "label-position": true, - "newline-before-return": true, - "no-any": true, - "no-arg": true, - "no-bitwise": true, - "no-console": [ - true, - "log", - "error", - "debug", - "info", - "time", - "timeEnd", - "trace" - ], - "no-consecutive-blank-lines": true, - "no-construct": true, - "no-debugger": true, - "no-duplicate-variable": true, - "no-empty": true, - "no-eval": true, - "no-implicit-dependencies": [true, "dev"], - "no-string-literal": true, - "no-switch-case-fall-through": true, - "no-trailing-whitespace": false, - "no-unnecessary-callback-wrapper": true, - "no-unused-expression": true, - "one-line": [ - true, - "check-catch", - "check-else", - "check-open-brace", - "check-whitespace" - ], - "prefer-const": true, - "quotemark": [true, "single", "jsx-double"], - "radix": true, - "switch-default": true, - "triple-equals": [true, "allow-null-check"], - "typedef": [true, "parameter", "property-declaration"], - "typedef-whitespace": [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - } - ], - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-module", - "check-operator", - "check-separator", - "check-type", - "check-typecast" - ] - } -} From 793f15eedd7d844a6b2984dbdda2e5c2b969ce36 Mon Sep 17 00:00:00 2001 From: Onur Laru Date: Fri, 23 Aug 2019 14:50:21 +0200 Subject: [PATCH 02/25] chore: Change ext order to overwrite eslint rules --- .eslintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 815408b6aa..5cf7837a14 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,8 +3,8 @@ "plugins": ["@typescript-eslint", "react-hooks"], "extends": [ "airbnb", - "prettier/@typescript-eslint", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", + "prettier/@typescript-eslint" ], "env": { "browser": true From 7b44e37fa696015a4bc4831421c9a66793ac86ef Mon Sep 17 00:00:00 2001 From: Onur Laru Date: Fri, 23 Aug 2019 14:52:48 +0200 Subject: [PATCH 03/25] chore: Add build to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9de55a7b46..4613a28ff3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ package-lock.json # Build directory /public .DS_Store +build .env .firebase/* From b7d316136d262bae7169c81a620e146e4c4f62bd Mon Sep 17 00:00:00 2001 From: Onur Laru Date: Fri, 23 Aug 2019 14:57:30 +0200 Subject: [PATCH 04/25] chore: Eslint fixes after config change --- gatsby-node.js | 37 +- src/components/article.tsx | 6 +- src/components/edit-link.tsx | 6 +- src/components/header.tsx | 8 +- src/components/hero.tsx | 4 +- src/components/layout.css | 558 +++++++++++++++++++++----- src/components/layout.tsx | 10 +- src/components/mobile.css | 22 +- src/components/navigation-item.tsx | 9 +- src/components/navigation-section.tsx | 44 +- src/components/navigation.tsx | 22 +- src/components/pagination.tsx | 6 +- src/components/seo.tsx | 6 +- src/config.js | 34 +- src/pages/404.tsx | 9 +- src/templates/learn.tsx | 40 +- src/util/createSlug.js | 3 +- src/util/scrollTo.tsx | 40 +- 18 files changed, 617 insertions(+), 247 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index a841e63ed8..473f6e41c5 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,8 +1,10 @@ -const createSlug = require('./src/util/createSlug'); +/* eslint-disable @typescript-eslint/no-var-requires */ +// Use in this file CommonJS syntax see https://www.gatsbyjs.org/docs/migrating-from-v1-to-v2/#convert-to-either-pure-commonjs-or-pure-es6 const path = require('path'); +const createSlug = require('./src/util/createSlug'); exports.createPages = ({ graphql, actions }) => { - const { createPage, createRedirect, createNodeField } = actions; + const { createPage } = actions; return new Promise((resolve, reject) => { const docTemplate = path.resolve('./src/templates/learn.tsx'); @@ -54,9 +56,10 @@ exports.createPages = ({ graphql, actions }) => { } } } - ` - ).then(result => { + `, + ).then((result) => { if (result.errors) { + // eslint-disable-next-line no-console console.log(result.errors); reject(result.errors); } @@ -65,7 +68,7 @@ exports.createPages = ({ graphql, actions }) => { const docPages = []; edges.forEach(({ node }, index) => { const { - fields: { slug, authors }, + fields: { slug }, frontmatter: { title, section }, parent: { relativePath }, } = node; @@ -80,8 +83,7 @@ exports.createPages = ({ graphql, actions }) => { } let nextNodeData = null; - const nextNode = - index === edges.length - 1 ? undefined : edges[index + 1].node; + const nextNode = index === edges.length - 1 ? undefined : edges[index + 1].node; if (nextNode) { nextNodeData = { slug: nextNode.fields.slug, @@ -108,7 +110,7 @@ exports.createPages = ({ graphql, actions }) => { }); }); - docPages.forEach(page => { + docPages.forEach((page) => { createPage({ path: `/${page.slug}`, component: docTemplate, @@ -117,44 +119,45 @@ exports.createPages = ({ graphql, actions }) => { next: page.next, previous: page.previous, relativePath: page.relativePath, - navigationData: navigationData, + navigationData, }, }); - if (page.slug === 'introduction-to-nodejs') + if (page.slug === 'introduction-to-nodejs') { createPage({ - path: `/`, + path: '/', component: docTemplate, context: { slug: page.slug, next: page.next, previous: page.previous, relativePath: page.relativePath, - navigationData: navigationData, + navigationData, }, }); + } }); - }) + }), ); }); }; -exports.onCreateNode = ({ node, getNode, actions }) => { +exports.onCreateNode = ({ node, actions }) => { if (node.internal.type === 'MarkdownRemark') { const { createNodeField } = actions; const slug = createSlug(node.frontmatter.title); createNodeField({ node, - name: `slug`, + name: 'slug', value: slug, }); - let authors = node.frontmatter.authors; + let { authors } = node.frontmatter; if (authors) { authors = authors.split(','); createNodeField({ node, - name: `authors`, + name: 'authors', value: authors, }); } diff --git a/src/components/article.tsx b/src/components/article.tsx index d160200819..98685194ae 100644 --- a/src/components/article.tsx +++ b/src/components/article.tsx @@ -5,7 +5,7 @@ import EditLink from './edit-link'; import Pagination from './pagination'; import TOC from './toc'; -type Props = { +interface Props { title: string; html: string; tableOfContents: string; @@ -13,7 +13,7 @@ type Props = { relativePath: string; next?: PaginationInfo; previous?: PaginationInfo; -}; +} const Article = ({ title, @@ -23,7 +23,7 @@ const Article = ({ next, relativePath, authors, -}: Props) => ( +}: Props): JSX.Element => (

{title}

diff --git a/src/components/edit-link.tsx b/src/components/edit-link.tsx index c2fa597a8d..7955a901c2 100644 --- a/src/components/edit-link.tsx +++ b/src/components/edit-link.tsx @@ -30,11 +30,11 @@ const icon: SerializedStyles = css` vertical-align: middle; `; -type Props = { +interface Props { relativePath?: string; -}; +} -const EditLink = ({ relativePath }: Props) => { +const EditLink = ({ relativePath }: Props): JSX.Element | null => { if (!relativePath) { return null; } diff --git a/src/components/header.tsx b/src/components/header.tsx index 73625643b8..04b0116961 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -14,7 +14,7 @@ const ulStyles: SerializedStyles = css` list-style: none; `; -const Header = () => ( +const Header = (): JSX.Element => (