Skip to content

Commit 9cc8f4d

Browse files
lipispieh
authored andcommitted
chore: add git hooks and simplify scripts (#8427)
- [x] Add git hooks to make sure the files are formatted before commiting - [x] Simplify `format*` scripts - [x] Drop prettier-eslint (is just a wrapper for ESLint and Prettier that we are using already) ---- ### The actual formats will happen in follow up PRs - [Format preview for `format:code`](https://github.com/gatsbyjs/gatsby/pull/8623/files) - [Format preview for `format:other`](https://github.com/gatsbyjs/gatsby/pull/8622/files)
1 parent fd63da9 commit 9cc8f4d

9 files changed

+578
-291
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ end_of_line = lf
77
indent_size = 2
88
indent_style = space
99
insert_final_newline = true
10-
trim_trailing_whitespace = true
10+
trim_trailing_whitespace = true

.eslintrc.json

+25-27
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"prettier/flowtype",
1010
"prettier/react"
1111
],
12-
"plugins": ["flowtype", "react"],
12+
"plugins": ["flowtype", "prettier", "react"],
1313
"parserOptions": {
1414
"ecmaVersion": 2016,
1515
"sourceType": "module",
@@ -27,36 +27,22 @@
2727
"spyOn": true
2828
},
2929
"rules": {
30-
"no-console": "off",
31-
"no-inner-declarations": "off",
32-
"valid-jsdoc": "off",
33-
"require-jsdoc": "off",
34-
"quotes": ["error", "backtick"],
35-
"consistent-return": ["error"],
3630
"arrow-body-style": [
3731
"error",
3832
"as-needed",
3933
{ "requireReturnForObjectLiteral": true }
4034
],
41-
"jsx-quotes": ["error", "prefer-double"],
42-
"semi": ["error", "never"],
43-
"object-curly-spacing": ["error", "always"],
44-
"comma-dangle": [
45-
"error",
46-
{
47-
"arrays": "always-multiline",
48-
"objects": "always-multiline",
49-
"imports": "always-multiline",
50-
"exports": "always-multiline",
51-
"functions": "ignore"
52-
}
53-
],
54-
"react/prop-types": [
55-
"error",
56-
{
57-
"ignore": ["children"]
58-
}
59-
]
35+
"consistent-return": ["error"],
36+
"no-console": "off",
37+
"no-inner-declarations": "off",
38+
"prettier/prettier": "error",
39+
"quotes": ["error", "backtick"],
40+
"react/display-name": "off",
41+
"react/jsx-key": "warn",
42+
"react/no-unescaped-entities": "warn",
43+
"react/prop-types": "off",
44+
"require-jsdoc": "off",
45+
"valid-jsdoc": "off"
6046
},
6147
"overrides": [
6248
{
@@ -71,6 +57,18 @@
7157
"___loader": false,
7258
"___emitter": false
7359
}
60+
},
61+
{
62+
"files": ["**/cypress/integration/**/*"],
63+
"globals": {
64+
"cy": false,
65+
"Cypress": false
66+
}
67+
}
68+
],
69+
"settings": {
70+
"react": {
71+
"version": "16.4.2"
7472
}
75-
]
73+
}
7674
}

.prettierignore

+27-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
/package.json
1+
*.min.js
2+
**/node_modules/**
3+
flow-typed
4+
5+
# webfont demo styles
6+
**/specimen_files
7+
8+
# built sites
9+
benchmarks/**/public
10+
e2e-tests/**/public
11+
examples/**/public
12+
integration-tests/**/public
13+
www/public
14+
15+
# cache-dirs
16+
**/.cache
17+
18+
# ignore built packages
19+
packages/*/*.js
20+
packages/gatsby/cache-dir/commonjs
21+
packages/gatsby/dist
22+
23+
# fixtures
24+
**/__testfixtures__/**
25+
**/__tests__/fixtures/**
26+
27+
infrastructure

.prettierrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"trailingComma": "es5",
32
"semi": false,
4-
"tabWidth": 2
3+
"singleQuote": false,
4+
"tabWidth": 2,
5+
"trailingComma": "es5"
56
}

package.json

+36-23
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@
88
"babel-jest": "^22.4.3",
99
"chokidar": "^1.7.0",
1010
"cross-env": "^5.1.4",
11-
"eslint": "^4.19.1",
12-
"eslint-config-google": "^0.9.1",
13-
"eslint-config-prettier": "^2.9.0",
14-
"eslint-plugin-flowtype": "^2.46.1",
15-
"eslint-plugin-import": "^2.9.0",
16-
"eslint-plugin-jsx-a11y": "^6.0.2",
17-
"eslint-plugin-prettier": "^2.6.0",
18-
"eslint-plugin-react": "^7.7.0",
11+
"eslint": "^5.6.1",
12+
"eslint-config-google": "^0.10.0",
13+
"eslint-config-prettier": "^3.1.0",
14+
"eslint-plugin-flow-vars": "^0.5.0",
15+
"eslint-plugin-flowtype": "^2.50.3",
16+
"eslint-plugin-import": "^2.14.0",
17+
"eslint-plugin-jsx-a11y": "^6.1.2",
18+
"eslint-plugin-prettier": "^3.0.0",
19+
"eslint-plugin-react": "^7.11.1",
1920
"flow-bin": "^0.42.0",
2021
"fs-extra": "^7.0.0",
2122
"glob": "^7.1.1",
23+
"husky": "1.1.1",
2224
"jest": "^23.5.0",
2325
"jest-cli": "^23.5.0",
2426
"lerna": "^3.3.0",
27+
"lint-staged": "^8.0.4",
2528
"npm-run-all": "4.1.2",
2629
"plop": "^1.8.1",
27-
"prettier": "^1.12",
28-
"prettier-eslint-cli": "4.7.1",
30+
"prettier": "^1.14.3",
2931
"rimraf": "^2.6.1",
3032
"yargs": "^10.0.3"
3133
},
@@ -38,27 +40,39 @@
3840
"**/__tests__/fixtures/"
3941
],
4042
"private": true,
43+
"lint-staged": {
44+
"*.{js,jsx}": [
45+
"eslint --ignore-path .gitignore --ignore-path .prettierignore --fix",
46+
"git add"
47+
],
48+
"*.{md,css,scss,yaml,yml}": [
49+
"prettier --write",
50+
"git add"
51+
]
52+
},
53+
"husky": {
54+
"hooks": {
55+
"pre-commit": "lint-staged || node scripts/on-lint-error.js"
56+
}
57+
},
4158
"scripts": {
4259
"bootstrap": "npm-run-all -s check-versions lerna-prepare",
4360
"check-versions": "babel-node scripts/check-versions.js",
44-
"format": "npm-run-all -p format-packages format-cache-dir format-www format-integration format-examples format-scripts format-markdown format-yaml",
45-
"format-cache-dir": "prettier-eslint --write \"packages/gatsby/cache-dir/*.js\"",
46-
"format-examples": "prettier-eslint --write \"examples/**/gatsby-node.js\" \"examples/**/gatsby-config.js\" \"examples/**/src/**/*.js\"",
47-
"format-markdown": "prettier --write \"**/*.md\" --no-semi",
48-
"format-packages": "prettier-eslint --write \"packages/*/src/**/*.js\"",
49-
"format-scripts": "prettier-eslint --write \"scripts/**/*.js\"",
50-
"format-www": "prettier-eslint --write \"www/*.js\" \"www/src/**/*.js\"",
51-
"format-integration": "prettier-eslint --write \"integration-tests/**/src/**/*.js\" \"integration-tests/**/cypress/**/*.js\"",
52-
"format-yaml": "prettier --write \"**/*.y?(a)ml\"",
61+
"format": "npm run format:code && npm run format:other",
62+
"format:other": "npm run prettier -- --write",
63+
"format:code": "npm run lint:code -- --fix",
64+
"hooks:uninstall": "node node_modules/husky/husky.js uninstall",
65+
"hooks:install": "node node_modules/husky/husky.js install",
5366
"jest": "jest",
5467
"lerna": "lerna",
5568
"lerna-prepare": "lerna run prepare",
56-
"lint": "npm-run-all --continue-on-error --parallel lint:js lint:yaml",
57-
"lint:js": "eslint --ext .js,.jsx packages/**/src integration-tests/**/src",
69+
"lint": "npm-run-all --continue-on-error -p lint:code lint:other",
70+
"lint:code": "eslint --ignore-path .gitignore --ignore-path .prettierignore --ext .js,.jsx .",
5871
"lint:flow": "babel-node scripts/flow-check.js",
59-
"lint:yaml": "prettier --list-different \"**/*.y?(a)ml\"",
72+
"lint:other": "npm run prettier -- --list-different",
6073
"plop": "plop",
6174
"prebootstrap": "yarn",
75+
"prettier": "prettier \"**/*.{md,css,scss,yaml,yml}\"",
6276
"publish": "node scripts/check-publish-access && lerna publish",
6377
"publish-canary": "lerna publish --canary --yes",
6478
"publish-next": "lerna publish --npm-tag=next --bump=prerelease",
@@ -67,7 +81,6 @@
6781
"test:update": "jest --updateSnapshot",
6882
"test:watch": "jest --watch",
6983
"test:integration": "jest --config=integration-tests/jest.config.js",
70-
"version": "prettier --write \"**/CHANGELOG.md\" --no-semi",
7184
"watch": "lerna run watch --no-sort --stream --concurrency 999"
7285
},
7386
"workspaces": [

scripts/on-lint-error.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
console.log(
2+
`Gatsby uses precommit hooks to run our linting and style checks. We do this
3+
to avoid additional hassle during pull request reviews, so please fix any linting
4+
problems before submitting pull request, because all PRs must pass these checks.
5+
6+
If you're doing something temporary, you can disable this hook with:
7+
git commit --no-verify
8+
9+
If you want disable this hook for all future commits:
10+
npm run hooks:uninstall
11+
`
12+
)

www/.eslintrc.json

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
22
"globals": {
33
"graphql": true
4-
},
5-
"rules": {
6-
"react/display-name": [0],
7-
"react/jsx-key": [1],
8-
"react/prop-types": [0]
94
}
105
}

www/package.json

-8
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,10 @@
101101
"front-matter": "^2.3.0",
102102
"get-package-json-from-github": "^1.2.1",
103103
"github-api": "^3.0.0",
104-
"husky": "^1.0.0-rc.14",
105-
"prettier": "^1.14.2",
106-
"pretty-quick": "^1.6.0",
107104
"stylelint": "^9.6.0",
108105
"stylelint-config-standard": "^18.2.0",
109106
"stylelint-config-styled-components": "^0.1.1",
110107
"stylelint-processor-styled-components": "^1.5.0",
111108
"webshot": "^0.18.0"
112-
},
113-
"husky": {
114-
"hooks": {
115-
"pre-commit": "pretty-quick --staged"
116-
}
117109
}
118110
}

0 commit comments

Comments
 (0)