Seamlessness
Lettere å skrive
Raskere å lese
Mer meningsfulle reviews
Real diff: 0
// package.json
{
...
"devDependencies": {
...
"husky": "^4.2.5",
"lint-staged": "^10.2.2",
"prettier": "^2.1.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,css,md}": [
"prettier --write"
]
}
}
Using husky and lint-staged
husky-hook kan re-addes med npm rebuild
# .pre-commit-config.yaml
- repo: local
hooks:
- id: eslint
name: eslint
entry: yarn eslint --quiet --fix
language: system
files: \.[jt]sx?$
types: [file]
- id: prettier
name: prettier
entry: yarn prettier --write
language: system
files: \.[jt]sx?$
types: [file]
Using pre-commit.com
Using VSCode Prettier
Lettere å skrive konsekvent og bugfritt
Raskere å lese
Mer meningsfulle reviews
Google it!
Skru den av i .eslintrc eller i @askeladden/eslint-config
// .eslintrc
{
...
"rules": {
// TODO: Fix this, we got e.g. components
// accepting style without using it.
"@typescript-eslint/no-unused-vars": 0
}
}
// .eslintrc
{
...
"rules": {
// We try to avoid using classes, but when we
// do, it's often to be compatible with a third-party
// library who might require methods in a certain way.
"class-methods-use-this": 0
}
}
// .eslintrc
{
...
"rules": {
// Avoid unnecessary imports
"unused-imports/no-unused-imports-ts": 2,
}
}
Using VSCode ESLint
Fixes Prettier and some ESLint errors
// VSCode settings.json
{
...
// Formats Prettier on save
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.formatOnSave": true
},
"[html]": {
"editor.formatOnSave": true
},
"[json]": {
"editor.formatOnSave": true
},
// Fixes some ESLint errors (e.g. import)
"editor.codeActionsOnSave": {
"source.fixAll": true
},
}
Med ESLint / Prettier
Funker pre-commit hooken?
Kan re-addes med npm rebuild
// package.json
{
...
"scripts": {
"lint:ignore-warnings": "eslint . --quiet",
"lint:prettier-check": "prettier --check \"**/*.{js,jsx,ts,tsx,json}\"",
"lint:prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,json}\""
}
}