This is for node 10 or above only.
Please check legacy tags for previous version of node runtime support.
AfterShip ESLint config (modified from eslint-config-airbnb)
following Airbnb JavaScript Style Guide commit a12dec90d173464a3fc4e4536b8c6f639fb93236
-
Use
camelCasefor files and folders if possible (exceptions could be made in some special cases) -
Use
camelCasewhen namingfunctions -
Use
PascalCasewhen namingclass variables -
Use
camelCasewhen namingvariablesconst name = 'John';,const emailAddress = 'john@gmail.com'; -
Use
SNAKE_UPPERCASEwhen namingconstant variablesbut no need forrequired moduleconst USER = 'John';,const DEFAULT_EMAIL = 'john@gmail.com'; -
Use
constforrequired moduleconst fs = require('fs'); -
Use JSDoc for documentation. Guidelines Here
-
When constructing class for
module.exports, create it as follows:'use strict'; // Declare imports // Class class Example { constructor() { } exampleFunction1() { } ... } module.exports = Example;
See here
We follow semver for the versioning strategy.
Major version indicates the eslint major version
Minor version indicates adding rules/options (more strict)
Path version indicates removing rules/options (more loose)
As we support frontend and backend project at the same time, please refer to the following guide for all optional dependencies.
-
If you are
AfterShipmember,grunt-init-nodealready installed it for you -
If you are not or you want to install in the existing repository:
-
npm install --save-dev eslint-config-aftership eslint eslint-plugin-import -
Keep the
^in thepackage.jsonforeslint-config-aftership, if the project is still in development. Replace the^with~if you want to prevent new rules which may brother you in travis. -
Create a
.eslintrcin the project root{ "extends": "aftership" }If your repo is a React project using webpack.js, you should extends
aftership/react, and install additional packagesnpm install eslint-plugin-html eslint-plugin-react eslint-plugin-jsx-a11y babel-eslint eslint-import-resolver-webpack
{ "extends": "aftership/react", "settings": { "import/resolver": { "webpack": { "config": "webpack.config.js" } } }If your repo is a Vue project using webpack, you should extends
aftership/vue, and install additional packagesnpm install eslint-plugin-html eslint-plugin-vue babel-eslint vue-eslint-parser eslint-import-resolver-webpack
{ "extends": "aftership/vue", "settings": { "import/resolver": { "webpack": { "config": "webpack.config.js" } } } -
Add it to
npm testso thattraviscan test it for us, for example:package.json:{ "scripts": { "lint": "eslint --ext .{jsx|vue},.js ." } }travis.yml:install: - npm install script: - npm run lint
-
-
If the repository doesn't have
eslintinstalled, you can install it as global package-
npm install -g eslint-config-aftership -
Create a
.eslintrcin$HOME{ "extends": "aftership" }
-
-
For
Atom:- Install in terminal by
apm install linter linter-eslint - If you want to use global eslint,
Preference->Packages->linter-eslint-> checkUse Global ESLint
- Install in terminal by
-
For
PhpStorm:Languages & Frameworks->JavaScript-> chooseECMAScript 6forJavaScript language versionPreference->Plugins-> clickBrowse repositories...-> searchESLint-> clickInstall pluginPreference->Languages & Frameworks->JavaScript->Code Quality Tools->ESLint-> checkEnable
-
For
Sublime Text 3:-
if you are using
nvm, add the following script to~/.bash_profileor~/.zshenv(check which shell you are using in SYSTEM DEFAULT (not the same as terminal default) byecho $SHELL)if hash brew 2> /dev/null && [[ -d "$(brew --prefix nvm)" ]]; then export NVM_DIR="$(brew --prefix nvm)" else export NVM_DIR="$HOME/.nvm" fi if [[ -s "$NVM_DIR/nvm.sh" ]]; then source "$NVM_DIR/nvm.sh" fi
remove the corresponding
nvmloading script in.bashrcor.zshrc -
Install Package Control
-
Install
SublimeLinterandSublimeLinter-contrib-eslintbyPackage Control -
Restart
Sublime Text 3 -
Restart computer if ESLint is not working
-
-
For
vimorneovim:-
neovimis preferred overvim, asneovimcan load plugin asynchronously, which highly improve performance when linting with ESLint -
Install benekastah/neomake by any plugin manager, such as vim-plug
-
Add the following lines to
~/.vimrc(vim) or~/.config/nvim/init.vim(neovim)autocmd BufWrite * :Neomake let g:neomake_javascript_enabled_makers= ['eslint'] " load local eslint in the project root " modified from https://github.com/mtscout6/syntastic-local-eslint.vim let s:eslint_path = system('PATH=$(npm bin):$PATH && which eslint') let g:neomake_javascript_eslint_exe = substitute(s:eslint_path, '^\n*\s*\(.\{-}\)\n*\s*$', '\1', '')
-
Copyright (c) 2020 AfterShip
Licensed under the MIT license.