In AppUnite, we enforce proper code style by:
-
formatting of all our
**/*.{js,jsx,ts,tsx,css,less,scss}
files with prettier, -
linting all
**/*.js
files with ESLint, -
linting all
**/*.ts
files with TSLint.
Code style is enforced by the following ways:
-
Our IDE autoformats our code after each file save.
-
On each commit, git is running a pre-commit hook (configured with husky), that runs formatter and lint checks for our commited files. (NOTE: If for some reasons you want to skip the pre-commit hook, you can run
git commit --no-verify
.) -
Last but not least, our CI will also check our whole code base for proper code style with
npm run format-test && npm run lint
commands and fail when it's badly formatted or has lint errors.
We strongly recommend to configure your IDE to show all ESLint errors on-the-fly and also automatically format your files on save:
-
VSCode:
- Install prettier-vscode.
- Add
"editor.formatOnSave": true
into your user settings.
-
Atom:
- Install prettier-atom.
- Enable Atom → Preferences... → Packages, find Prettier Atom toggle Format Files on Save.
-
VIM:
- Install vim-prettier and vim-autoformat, e.g. using Plug
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json'] }
- Configure them in
.vimrc
" prettier
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.css,*.less,*.scss,*.json Prettier