In Recruitee, enforce correct formatting of our files with js-beautify for all src/ng2/**/*.html
files and prettier for all **/*.{ts,js,css,less}
files.
We also lint all **/*.ts
files (and components' .html
templates) code style with TSLint, although during the automatic linting, we ignore legacy files listed in ./tslint.without-legacy.json
.
During npm install
, husky automatically sets up a pre-commit hook in this repository, that will check your code before each commit and fail if it's wrong. If you want to skip the pre-commit hook, you can run git commit --no-verify
.
Additionally, our CI will also check your code with npm run format-test && npm run lint
command and fail if it's badly formatted or its' non-legacy files have tslint errors.
We strongly recommend to configure your IDE to show all TSLint errors on-the-fly and also automatically format your files on save:
-
VSCode:
- Install prettier-vscode.
- Add
"editor.formatOnSave": true
into your user settings. - Install beautify.
- Add following settings to your User or Workspace Settings:
{
"editor.formatOnSave": true,
"prettier.disableLanguages": ["html", "vue", "markdown"],
"beautify.language": {
"js": [],
"css": [],
"html": ["htm", "html"]
}
}
-
Atom:
- Install prettier-atom.
- Enable Atom → Preferences... → Packages, find Prettier Atom toggle Format Files on Save, then find Exclude (list of globs) and add
*.json
. - Install atom-beautify.
- Go to Atom-Beautify's package settings (Preferences ➔ Search for atom-beautify), find HTML, and toggle the Beautify On Save option. (Don't enable it for the rest of the files)
-
VIM:
- Install vim-prettier and vim-autoformat, e.g. using Plug
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['typescript', 'css', 'less', 'scss', 'json'] }
Plug 'Chiel92/vim-autoformat'
- Configure them in
.vimrc
" prettier
let g:prettier#autoformat = 0
autocmd BufWritePre *.ts,*.tsx,*.css,*.less,*.scss,*.json Prettier
" vim-autoformat
autocmd BufWritePre *.html Autoformat