Use githooks to prettify, lint and analyse staged files
Summary of the new feature/enhancement
Use pre-commit githooks in order to prettify, lint and run accessibility tests
Justify the new feature/enhancement
Developers make mistakes, githooks are a (not so gentle way) to remind them the they forgot to fix lint errors. On the other hand prettier is a code formatter that apply those rules.
So a combination of those two is a fine option. For the staged files we can run the prettier and the run the linter for any other tasks.
A drawback is that depending on the tool we can not have partially staged file (a file the is at the stage, but then staged again).
Proposed technical implementation details (optional)
- Use husky to apply those githooks at repository level (githooks normally are not git-tracked).
- Use prettier with the .editorconfig rules
- Use list-staged and/or the pretty-quick to format the code and then lint it.
- Use codelyzer to test code for accessibility features
Note that tslint is not that friendly with the lint-staged
scripts, as is discussed at the angular repo, but there is someone who picked the most popular answer and made an npm package out of it, see more here https://www.npmjs.com/package/ng-lint-staged
proposed .prettierrc
:
{
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"bracketSpacing": true
}
edit: tslint stopped being developed and will stop be maintained in 2020-12-01, see: [https://github.com/palantir/tslint/issues/4534](https://github.com/palantir/tslint/issues/4534
So the issue with the lint-staged
will be resolved when we start using eslint.