Skip to content

Instantly share code, notes, and snippets.

@jtomaszewski
Created April 5, 2018 12:00
Show Gist options
  • Save jtomaszewski/426604873e4b567aa374c060c5263b39 to your computer and use it in GitHub Desktop.
Save jtomaszewski/426604873e4b567aa374c060c5263b39 to your computer and use it in GitHub Desktop.

Code formatting & linting

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:

    1. Install prettier-vscode.
    2. Add "editor.formatOnSave": true into your user settings.
    3. Install beautify.
    4. 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:

    1. Install prettier-atom.
    2. Enable Atom → Preferences... → Packages, find Prettier Atom toggle Format Files on Save, then find Exclude (list of globs) and add *.json .
    3. Install atom-beautify.
    4. 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)
  • WebStorm

  • VIM:

    1. 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'
  1. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment