This is a default React app that integrates linting & formatting tools with git hooks.
- ESLint
- Prettier
- lint-staged
- husky
- Configuration files for ESLint and Prettier specify rules which will be followed for all users working on this project.
- Husky is set up to run commands listed in '.husky/pre-commit' whenever a user runs 'git commit'.
- Husky runs lint-staged, which intelligently targets only files which changed and are staged (with git add, for example).
- lint-staged runs ESLint and Prettier on the staged files based on the configuration specified in 'package.json'.
- If ESLint throws no errors, then the staged files are formatted according to Prettier rules and are actually committed.
- Otherwise, terminal displays linting errors which user must fix before committing.
Note: .vscode/settings.json sets VSCode's default formatter for this project to Prettier, and allows reformatting on save. This is a user choice, as files will be formatted automatically through lint-staged even if user does not press Ctrl+S while working on a file.
Note 2: .prettierignore is a copy of gitignore
Note 3: .eslintcache is added to gitignore - it is an auto-generated build file which will appear as a changed file and block branch switching
Potential next steps:
- Add more git hooks to .husky folder for practice
- Change lint-staged properties in 'package.json' to include other file formats (json?)