Skip to content

Commit

Permalink
chore: add git hooks and simplify scripts (gatsbyjs#8427)
Browse files Browse the repository at this point in the history
- [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)
  • Loading branch information
lipis authored and pieh committed Nov 6, 2018
1 parent fd63da9 commit 9cc8f4d
Show file tree
Hide file tree
Showing 9 changed files with 578 additions and 291 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
trim_trailing_whitespace = true
52 changes: 25 additions & 27 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"prettier/flowtype",
"prettier/react"
],
"plugins": ["flowtype", "react"],
"plugins": ["flowtype", "prettier", "react"],
"parserOptions": {
"ecmaVersion": 2016,
"sourceType": "module",
Expand All @@ -27,36 +27,22 @@
"spyOn": true
},
"rules": {
"no-console": "off",
"no-inner-declarations": "off",
"valid-jsdoc": "off",
"require-jsdoc": "off",
"quotes": ["error", "backtick"],
"consistent-return": ["error"],
"arrow-body-style": [
"error",
"as-needed",
{ "requireReturnForObjectLiteral": true }
],
"jsx-quotes": ["error", "prefer-double"],
"semi": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore"
}
],
"react/prop-types": [
"error",
{
"ignore": ["children"]
}
]
"consistent-return": ["error"],
"no-console": "off",
"no-inner-declarations": "off",
"prettier/prettier": "error",
"quotes": ["error", "backtick"],
"react/display-name": "off",
"react/jsx-key": "warn",
"react/no-unescaped-entities": "warn",
"react/prop-types": "off",
"require-jsdoc": "off",
"valid-jsdoc": "off"
},
"overrides": [
{
Expand All @@ -71,6 +57,18 @@
"___loader": false,
"___emitter": false
}
},
{
"files": ["**/cypress/integration/**/*"],
"globals": {
"cy": false,
"Cypress": false
}
}
],
"settings": {
"react": {
"version": "16.4.2"
}
]
}
}
28 changes: 27 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
/package.json
*.min.js
**/node_modules/**
flow-typed

# webfont demo styles
**/specimen_files

# built sites
benchmarks/**/public
e2e-tests/**/public
examples/**/public
integration-tests/**/public
www/public

# cache-dirs
**/.cache

# ignore built packages
packages/*/*.js
packages/gatsby/cache-dir/commonjs
packages/gatsby/dist

# fixtures
**/__testfixtures__/**
**/__tests__/fixtures/**

infrastructure
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"trailingComma": "es5",
"semi": false,
"tabWidth": 2
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5"
}
59 changes: 36 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
"babel-jest": "^22.4.3",
"chokidar": "^1.7.0",
"cross-env": "^5.1.4",
"eslint": "^4.19.1",
"eslint-config-google": "^0.9.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-flowtype": "^2.46.1",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.7.0",
"eslint": "^5.6.1",
"eslint-config-google": "^0.10.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-flow-vars": "^0.5.0",
"eslint-plugin-flowtype": "^2.50.3",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"flow-bin": "^0.42.0",
"fs-extra": "^7.0.0",
"glob": "^7.1.1",
"husky": "1.1.1",
"jest": "^23.5.0",
"jest-cli": "^23.5.0",
"lerna": "^3.3.0",
"lint-staged": "^8.0.4",
"npm-run-all": "4.1.2",
"plop": "^1.8.1",
"prettier": "^1.12",
"prettier-eslint-cli": "4.7.1",
"prettier": "^1.14.3",
"rimraf": "^2.6.1",
"yargs": "^10.0.3"
},
Expand All @@ -38,27 +40,39 @@
"**/__tests__/fixtures/"
],
"private": true,
"lint-staged": {
"*.{js,jsx}": [
"eslint --ignore-path .gitignore --ignore-path .prettierignore --fix",
"git add"
],
"*.{md,css,scss,yaml,yml}": [
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged || node scripts/on-lint-error.js"
}
},
"scripts": {
"bootstrap": "npm-run-all -s check-versions lerna-prepare",
"check-versions": "babel-node scripts/check-versions.js",
"format": "npm-run-all -p format-packages format-cache-dir format-www format-integration format-examples format-scripts format-markdown format-yaml",
"format-cache-dir": "prettier-eslint --write \"packages/gatsby/cache-dir/*.js\"",
"format-examples": "prettier-eslint --write \"examples/**/gatsby-node.js\" \"examples/**/gatsby-config.js\" \"examples/**/src/**/*.js\"",
"format-markdown": "prettier --write \"**/*.md\" --no-semi",
"format-packages": "prettier-eslint --write \"packages/*/src/**/*.js\"",
"format-scripts": "prettier-eslint --write \"scripts/**/*.js\"",
"format-www": "prettier-eslint --write \"www/*.js\" \"www/src/**/*.js\"",
"format-integration": "prettier-eslint --write \"integration-tests/**/src/**/*.js\" \"integration-tests/**/cypress/**/*.js\"",
"format-yaml": "prettier --write \"**/*.y?(a)ml\"",
"format": "npm run format:code && npm run format:other",
"format:other": "npm run prettier -- --write",
"format:code": "npm run lint:code -- --fix",
"hooks:uninstall": "node node_modules/husky/husky.js uninstall",
"hooks:install": "node node_modules/husky/husky.js install",
"jest": "jest",
"lerna": "lerna",
"lerna-prepare": "lerna run prepare",
"lint": "npm-run-all --continue-on-error --parallel lint:js lint:yaml",
"lint:js": "eslint --ext .js,.jsx packages/**/src integration-tests/**/src",
"lint": "npm-run-all --continue-on-error -p lint:code lint:other",
"lint:code": "eslint --ignore-path .gitignore --ignore-path .prettierignore --ext .js,.jsx .",
"lint:flow": "babel-node scripts/flow-check.js",
"lint:yaml": "prettier --list-different \"**/*.y?(a)ml\"",
"lint:other": "npm run prettier -- --list-different",
"plop": "plop",
"prebootstrap": "yarn",
"prettier": "prettier \"**/*.{md,css,scss,yaml,yml}\"",
"publish": "node scripts/check-publish-access && lerna publish",
"publish-canary": "lerna publish --canary --yes",
"publish-next": "lerna publish --npm-tag=next --bump=prerelease",
Expand All @@ -67,7 +81,6 @@
"test:update": "jest --updateSnapshot",
"test:watch": "jest --watch",
"test:integration": "jest --config=integration-tests/jest.config.js",
"version": "prettier --write \"**/CHANGELOG.md\" --no-semi",
"watch": "lerna run watch --no-sort --stream --concurrency 999"
},
"workspaces": [
Expand Down
12 changes: 12 additions & 0 deletions scripts/on-lint-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
console.log(
`Gatsby uses precommit hooks to run our linting and style checks. We do this
to avoid additional hassle during pull request reviews, so please fix any linting
problems before submitting pull request, because all PRs must pass these checks.
If you're doing something temporary, you can disable this hook with:
git commit --no-verify
If you want disable this hook for all future commits:
npm run hooks:uninstall
`
)
5 changes: 0 additions & 5 deletions www/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"globals": {
"graphql": true
},
"rules": {
"react/display-name": [0],
"react/jsx-key": [1],
"react/prop-types": [0]
}
}
8 changes: 0 additions & 8 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,10 @@
"front-matter": "^2.3.0",
"get-package-json-from-github": "^1.2.1",
"github-api": "^3.0.0",
"husky": "^1.0.0-rc.14",
"prettier": "^1.14.2",
"pretty-quick": "^1.6.0",
"stylelint": "^9.6.0",
"stylelint-config-standard": "^18.2.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.5.0",
"webshot": "^0.18.0"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
}
Loading

0 comments on commit 9cc8f4d

Please sign in to comment.