Automatic Code Linting & Formatting with ESLint and Prettier in Sublime Text 3

Step 0: Install or activate a specific version of node

nvm use v14.8.0
nvm install v14.8.0

Step 1: Install the Node Packages for ESLint and Prettier

npm install -g eslint prettier
  • ESLint is a pluggable and highly configurable JavaScript code linter that can find (and fix) problems in your code.
  • Prettier is an opinionated code formatter which will automatically format your code according to specified code styling.
eslint --version
prettier --version

Step 2: Install Sublime Text 3 Plugins

  • Tools > Command Palette > Install Package Control
  • Tools > Command Palette > Install Package > SublimeLinter
  • Tools > Command Palette > Install Package > SublimeLinter-eslint
  • Tools > Command Palette > Install Package > jsPrettier

Step 3: Configure SublimeLinter and jsPrettier

which eslint prettier
/Users/[USERNAME]/.nvm/versions/node/v14.8.0/bin/eslint
/Users/[USERNAME]/.nvm/versions/node/v14.8.0/bin/prettier
  • Tools > Command Palette > Preferences: SublimeLinter Settings
// SublimeLinter Settings - User
{
"linters": {
"eslint": {
"env": {
"PATH": "/Users/[USERNAME]/.nvm/versions/node/v14.8.0/bin/"
},
"args": ["--env=es6"]
}
}
}
npm install --save-dev eslint
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": "error"
}
}
  • Tools > Command Palette > Preferences: jsPrettier Settings — User
{
"prettier_cli_path": "/Users/[USERNAME]/.nvm/versions/node/v14.8.0/bin/prettier",
"node_path": "/Users/[USERNAME]/.nvm/versions/node/v14.8.0/bin/node",
"auto_format_on_save": true
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nafeu Nasir

Nafeu Nasir

is a musician and full-stack web developer from Toronto, Canada who studied Computer Science and Linguistics at the University of Toronto.