Skip to content

Instantly share code, notes, and snippets.

@VehpuS
Created July 17, 2021 17:48
Show Gist options
  • Save VehpuS/a6c94e06435f2a135ee08ace3fd226d2 to your computer and use it in GitHub Desktop.
Save VehpuS/a6c94e06435f2a135ee08ace3fd226d2 to your computer and use it in GitHub Desktop.
Auto linting / testing / prettifying on commits - template package.json, .eslintrc, .prettierrc, .prettierignore, .husky, .eslintignore, commitlint.config.js files from a react native project - demonstrating a setup that worked, possibly to be maintained with my continuous best practiices
node_modules
dist
.expo
.expo-shared
web-build
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["react", "@typescript-eslint", "prettier", "jest"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:jest/recommended"
],
"rules": {
"no-console": 1,
"prettier/prettier": 1,
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error",
"react/prop-types": 0,
"react/display-name": 1,
"react/no-children-prop": 0,
"@typescript-eslint/no-unused-vars": 2,
"@typescript-eslint/ban-ts-comment": 1
},
"settings": {
"jest": {
"version": 25
},
"react": {
"pragma": "React",
"version": "detect"
}
},
"env": {
"browser": true,
"node": true,
"jest/globals": true
}
}
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit ""
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run test:pre-commit
npx lint-staged
npm run lint-and-fix:pre-commit
.expo
.expo-shared
.vscode
.gitignore
tsconfig.json
package.json
package-lock.json
README.md
babel.config.js
app.json
{
"semi": true,
"trailingComma": "all",
"singleQuote": false,
"printWidth": 120
}
module.exports = {
extends: ["@commitlint/config-conventional"], // => commitlint/config-conventional
};
{
...
"scripts": {
"lint": "eslint . --ext .ts,.tsx,.js,.jsx,.json",
"lint-and-fix": "eslint --ext .ts,.itsx,.js,.jsx,.json --fix",
"lint-and-fix:pre-commit": "npm run lint-and-fix $(git diff --name-only HEAD | grep -E \"\\.[jt]s.*$\" | xargs)",
"lint-and-fix:all": "npm run lint-and-fix .",
"prettier-format": "prettier --config .prettierrc '**/*.{json,js,jsx,ts,tsx,css,scss,md}' --write",
"test": "jest",
"test:pre-commit": "if git cat-file -e origin/HEAD; then npm run test:latest-remote; else npm run test:latest-local; fi",
"test:latest-remote": "jest --changedSince=origin/HEAD",
"test:latest-local": "jest --changedSince=HEAD",
"test:watch": "jest --watchAll --coverage",
"prepare": "husky install"
...
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "~41.0.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native-web": "~0.13.12"
...
},
"devDependencies": {
...
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@types/react": "^16.9.56",
"@types/react-native": "~0.63.2",
"@types/jest": "^26.0.24",
"@typescript-eslint/eslint-plugin": "^4.28.3",
"@typescript-eslint/parser": "^4.28.3",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-react": "^1.1.7",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"husky": "^7.0.0",
"jest-expo": "^41.0.0",
"lint-staged": "^11.0.1",
"prettier": "^2.3.1",
"typescript": "~4.0.0"
},
"lint-staged": {
"*.{js,css,md}": "prettier --write"
}
...
}
@VehpuS
Copy link
Author

VehpuS commented Jul 20, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment