Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 78e6d7d

Browse files
authored
Linter prettier integration (#315)
* chore: Eslint / Prettier integration. * chore: Change ext order to overwrite eslint rules * chore: Add build to gitignore * chore: Eslint fixes after config change * chore: Update yarn.lock after rebase * chore: Add eslint-plugin-jest and extend w/ reccs * chore: Disable no-var-requires for .js files * chore: Remove format-check from test script * chore: Fix eslint errors in js files * chore: Update husky pre-push to use lint script * chore: Create new .eslintrc config * chore: Update lint script, add react settings to eslint config * chore: Ignore test dir when running lint script * chore: Add airbnb config and jest env to eslintrc * chore: Disable react/jsx-filename-extension * chore: Recover .prettierrc config file that was deleted * chore: Extend eslint config with prettier/react * chore: Fix all but a few eslint errors * chore: Update eslint-plugin-prettier * chore: Disable prefer-default-exports rule * chore: Fix eslint errors after merging with staging * chore: Fix eslint errors in konami code * chore: Disable import/extensions and consistent-return rules * chore: Set return type for setPage hook in click handler to void * fix: Clean up some errors after all the merge fixing
1 parent 4c03eb7 commit 78e6d7d

43 files changed

Lines changed: 867 additions & 672 deletions

Some content is hidden

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

.eslintrc.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
parserOptions: {
4+
ecmaFeatures: {
5+
jsx: true
6+
}
7+
// project: './tsconfig.json'
8+
},
9+
extends: [
10+
"airbnb",
11+
"plugin:react/recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"prettier/@typescript-eslint",
14+
"prettier/react",
15+
"plugin:prettier/recommended"
16+
],
17+
settings: {
18+
react: {
19+
version: "detect"
20+
},
21+
"import/resolver": {
22+
typescript: {}
23+
}
24+
},
25+
env: {
26+
browser: true,
27+
node: true,
28+
jest: true
29+
},
30+
rules: {
31+
"react/jsx-filename-extension": "off",
32+
"react-hooks/rules-of-hooks": "error",
33+
"react-hooks/exhaustive-deps": "warn",
34+
"import/prefer-default-export": "off",
35+
"import/extensions": "off",
36+
"consistent-return": "off",
37+
// "camelcase": "off",
38+
// "@typescript-eslint/camelcase": ["error", { "properties": "never" }],
39+
// "no-unused-vars": "off",
40+
// "@typescript-eslint/no-unused-vars": "error",
41+
// "@typescript-eslint/indent": ["error", 2]
42+
},
43+
plugins: [
44+
"@typescript-eslint",
45+
"react-hooks"
46+
// "prettier"
47+
],
48+
overrides: [
49+
{
50+
files: ["**/*.js"],
51+
rules: {
52+
"@typescript-eslint/no-var-requires": "off"
53+
}
54+
}
55+
]
56+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package-lock.json
77
# Build directory
88
/public
99
.DS_Store
10+
build
1011

1112
.env
1213
.firebase/*

.prettierrc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"printWidth": 80,
3-
"tabWidth": 2,
4-
"useTabs": false,
5-
"semi": true,
6-
"singleQuote": true,
7-
"jsxSingleQuote": false,
8-
"trailingComma": "es5",
9-
"bracketSpacing": true,
10-
"jsxBracketSameLine": false,
11-
"arrowParens": "avoid"
2+
printWidth: 80,
3+
tabWidth: 2,
4+
useTabs: false,
5+
semi: true,
6+
singleQuote: true,
7+
jsxSingleQuote: false,
8+
trailingComma: "es5",
9+
bracketSpacing: true,
10+
jsxBracketSameLine: false,
11+
arrowParens: "avoid"
1212
}

gatsby-config.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
if (process.env.ENVIROMENT !== 'production') {
2+
// eslint-disable-next-line global-require
23
require('dotenv').config();
34
}
45

@@ -17,50 +18,54 @@ module.exports = {
1718
'gatsby-plugin-catch-links',
1819
'gatsby-plugin-react-helmet',
1920
{
20-
resolve: `gatsby-plugin-canonical-urls`,
21+
resolve: 'gatsby-plugin-canonical-urls',
2122
options: {
2223
siteUrl: config.siteUrl,
2324
},
2425
},
25-
`gatsby-plugin-sharp`,
26+
'gatsby-plugin-sharp',
2627
{
27-
resolve: `gatsby-source-filesystem`,
28+
resolve: 'gatsby-source-filesystem',
2829
options: {
29-
name: `learn`,
30+
name: 'learn',
3031
path: `${__dirname}/src/documentation/`,
31-
include: [`**/*.md`], // ignore files starting with a dot
32+
include: ['**/*.md'], // ignore files starting with a dot
3233
},
3334
},
35+
3436
{
35-
resolve: `gatsby-plugin-manifest`,
37+
resolve: 'gatsby-plugin-manifest',
3638
options: {
3739
name: config.title,
40+
/* eslint-disable @typescript-eslint/camelcase */
3841
short_name: config.title,
3942
start_url: '/',
4043
background_color: config.color,
4144
theme_color: config.color,
45+
/* eslint-disable @typescript-eslint/camelcase */
4246
display: config.display,
4347
icon: config.icon,
4448
},
4549
},
4650
'gatsby-plugin-offline',
47-
`gatsby-plugin-typescript`,
51+
'gatsby-plugin-typescript',
4852
{
4953
resolve: 'gatsby-transformer-remark',
5054
options: {
5155
plugins: [
5256
{
53-
resolve: `gatsby-remark-autolink-headers`,
57+
resolve: 'gatsby-remark-autolink-headers',
5458
options: {
55-
offsetY: `125`,
56-
icon: `<svg aria-hidden="true" height="20" version="1.1" viewBox="0 0 16 16" width="20"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>`,
57-
className: `autolink-headers`,
59+
offsetY: '125',
60+
icon:
61+
'<svg aria-hidden="true" height="20" version="1.1" viewBox="0 0 16 16" width="20"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>',
62+
className: 'autolink-headers',
5863
maintainCase: false,
5964
removeAccents: true,
6065
},
6166
},
6267
{
63-
resolve: `gatsby-remark-prismjs`,
68+
resolve: 'gatsby-remark-prismjs',
6469
options: {
6570
classPrefix: 'language-',
6671
inlineCodeMarker: null,
@@ -70,7 +75,7 @@ module.exports = {
7075
},
7176
},
7277
{
73-
resolve: `gatsby-remark-images`,
78+
resolve: 'gatsby-remark-images',
7479
options: {
7580
maxWidth: 590,
7681
},
@@ -79,7 +84,7 @@ module.exports = {
7984
},
8085
},
8186
{
82-
resolve: `gatsby-plugin-sitemap`,
87+
resolve: 'gatsby-plugin-sitemap',
8388
options: {
8489
query: `{
8590
site {
@@ -106,28 +111,23 @@ module.exports = {
106111
}
107112
}`,
108113
serialize: ({ site, allSitePage, allMarkdownRemark }) => {
109-
let pages = [];
110-
allSitePage.edges.map(edge => {
111-
pages.push({
112-
url: site.siteMetadata.siteUrlNoSlash + edge.node.path,
113-
changefreq: `daily`,
114-
priority: 0.7,
115-
});
116-
});
117-
allMarkdownRemark.edges.map(edge => {
118-
pages.push({
119-
url: `${site.siteMetadata.siteUrlNoSlash}/${edge.node.fields.slug}`,
120-
changefreq: `daily`,
121-
priority: 0.7,
122-
});
123-
});
114+
const sitePages = allSitePage.edges.map(edge => ({
115+
url: site.siteMetadata.siteUrlNoSlash + edge.node.path,
116+
changefreq: 'daily',
117+
priority: 0.7,
118+
}));
119+
const markdownRemark = allMarkdownRemark.edges.map(edge => ({
120+
url: `${site.siteMetadata.siteUrlNoSlash}/${edge.node.fields.slug}`,
121+
changefreq: 'daily',
122+
priority: 0.7,
123+
}));
124124

125-
return pages;
125+
return sitePages.concat(markdownRemark);
126126
},
127127
},
128128
},
129129
{
130-
resolve: `gatsby-plugin-emotion`,
130+
resolve: 'gatsby-plugin-emotion',
131131
},
132132
],
133133
};

gatsby-node.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const createSlug = require('./src/util/createSlug');
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
// 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
23
const path = require('path');
4+
const createSlug = require('./src/util/createSlug');
35

46
exports.createPages = ({ graphql, actions }) => {
5-
const { createPage, createRedirect, createNodeField } = actions;
7+
const { createPage } = actions;
68

79
return new Promise((resolve, reject) => {
810
const docTemplate = path.resolve('./src/templates/learn.tsx');
@@ -57,6 +59,7 @@ exports.createPages = ({ graphql, actions }) => {
5759
`
5860
).then(result => {
5961
if (result.errors) {
62+
// eslint-disable-next-line no-console
6063
console.log(result.errors);
6164
reject(result.errors);
6265
}
@@ -65,7 +68,7 @@ exports.createPages = ({ graphql, actions }) => {
6568
const docPages = [];
6669
edges.forEach(({ node }, index) => {
6770
const {
68-
fields: { slug, authors },
71+
fields: { slug },
6972
frontmatter: { title, section },
7073
parent: { relativePath },
7174
} = node;
@@ -117,10 +120,10 @@ exports.createPages = ({ graphql, actions }) => {
117120
next: page.next,
118121
previous: page.previous,
119122
relativePath: page.relativePath,
120-
navigationData: navigationData,
123+
navigationData,
121124
},
122125
});
123-
if (page.slug === 'introduction-to-nodejs')
126+
if (page.slug === 'introduction-to-nodejs') {
124127
createPage({
125128
path: `/learn`,
126129
component: docTemplate,
@@ -129,32 +132,33 @@ exports.createPages = ({ graphql, actions }) => {
129132
next: page.next,
130133
previous: page.previous,
131134
relativePath: page.relativePath,
132-
navigationData: navigationData,
135+
navigationData,
133136
},
134137
});
138+
}
135139
});
136140
})
137141
);
138142
});
139143
};
140144

141-
exports.onCreateNode = ({ node, getNode, actions }) => {
145+
exports.onCreateNode = ({ node, actions }) => {
142146
if (node.internal.type === 'MarkdownRemark') {
143147
const { createNodeField } = actions;
144148

145149
const slug = createSlug(node.frontmatter.title);
146150
createNodeField({
147151
node,
148-
name: `slug`,
152+
name: 'slug',
149153
value: slug,
150154
});
151155

152-
let authors = node.frontmatter.authors;
156+
let { authors } = node.frontmatter;
153157
if (authors) {
154158
authors = authors.split(',');
155159
createNodeField({
156160
node,
157-
name: `authors`,
161+
name: 'authors',
158162
value: authors,
159163
});
160164
}

package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dotenv": "^6.0.0",
1111
"emotion": "^10.0.7",
1212
"emotion-server": "^10.0.7",
13+
"eslint-plugin-jest": "^22.17.0",
1314
"gatsby": "^2.13.13",
1415
"gatsby-plugin-canonical-urls": "^2.0.10",
1516
"gatsby-plugin-catch-links": "^2.0.9",
@@ -31,7 +32,6 @@
3132
"react-dom": "^16.8.0",
3233
"react-emotion": "^10.0.0",
3334
"react-helmet": "^5.2.0",
34-
"tslint": "^5.11.0",
3535
"typescript": "^3.1.1"
3636
},
3737
"keywords": [
@@ -43,14 +43,15 @@
4343
"build": "gatsby build",
4444
"build-ci": "gatsby build --prefix-paths",
4545
"start": "gatsby develop",
46-
"format": "prettier --write '**/*.{ts,tsx,js}'",
46+
"format": "yarn lint:fix",
4747
"format-check": "prettier --check '**/*.{ts,tsx,js}'",
4848
"jest": "jest",
4949
"update-snapshot": "jest --updateSnapshot",
50-
"test": "yarn format-check && yarn tslint && yarn jest",
50+
"test": "yarn lint && yarn jest",
5151
"test-watch": "yarn jest --watch",
5252
"test-ci": "yarn test --coverage && codecov",
53-
"tslint": "tslint --project ./tsconfig.json",
53+
"lint": "eslint . --ext .js,.ts,.tsx --ignore-pattern test/",
54+
"lint:fix": "yarn lint --fix",
5455
"serve": "yarn build && clear && gatsby serve"
5556
},
5657
"devDependencies": {
@@ -60,16 +61,25 @@
6061
"@commitlint/config-conventional": "^7.3.1",
6162
"@types/jest": "^24.0.5",
6263
"@types/react-test-renderer": "^16.8.1",
64+
"@typescript-eslint/eslint-plugin": "^1.4.2",
6365
"babel-jest": "^24.1.0",
6466
"babel-preset-gatsby": "^0.1.7",
6567
"codecov": "^3.3.0",
68+
"eslint": "^5.14.1",
69+
"eslint-config-airbnb": "^17.1.0",
70+
"eslint-config-prettier": "^4.1.0",
71+
"eslint-import-resolver-typescript": "^1.1.1",
72+
"eslint-plugin-import": "^2.16.0",
73+
"eslint-plugin-jsx-a11y": "^6.2.1",
74+
"eslint-plugin-prettier": "^3.1.0",
75+
"eslint-plugin-react": "^7.12.4",
76+
"eslint-plugin-react-hooks": "^1.4.0",
6677
"husky": "^1.3.1",
6778
"identity-obj-proxy": "^3.0.0",
6879
"jest": "^24.1.0",
6980
"prettier": "^1.16.4",
7081
"react-test-renderer": "^16.8.2",
71-
"tslint-config-prettier": "^1.15.0",
72-
"tslint-react": "^3.6.0"
82+
"typescript": "~3.2.1"
7383
},
7484
"repository": {
7585
"type": "git",
@@ -103,7 +113,7 @@
103113
"husky": {
104114
"hooks": {
105115
"commit-msg": "commitlint --edit $HUSKY_GIT_PARAMS",
106-
"pre-push": "yarn format-check && yarn tslint"
116+
"pre-push": "yarn lint"
107117
}
108118
}
109119
}

0 commit comments

Comments
 (0)