Skip to content

Instantly share code, notes, and snippets.

@olitreadwell
Last active April 28, 2017 19:33
Show Gist options
  • Save olitreadwell/8cada521d91137cd5d5155cba020e897 to your computer and use it in GitHub Desktop.
Save olitreadwell/8cada521d91137cd5d5155cba020e897 to your computer and use it in GitHub Desktop.
Installing ESlint in your JavaScript Application

Include the following within your Bash Profile to make it simple to install eslint in one step.

Warning: this bash command curl's a gist and runs a command without further security checks.

You include this command without further security measures as your own discretion

Add to your Bash Profile

# initiate npm and install eslint in a file
function ei-eslint-install()
{
  rm -f ./eslint-install-script-temporary.sh

  curl https://gist.githubusercontent.com/olitreadwell/8cada521d91137cd5d5155cba020e897/raw/c309842994a4d8620e00e32a22b04dd77902025e/install-eslint.sh > eslint-install-script-temporary.sh;

  chmod +x ./eslint-install-script-temporary.sh;

  cat ./eslint-install-script-temporary.sh;

  ./eslint-install-script-temporary.sh;

  rm -f ./eslint-install-script-temporary.sh
}
alias "ei-eslint-install"=ei-eslint-install

Load the new CLI configuration

$ source ~/path/to/your/terminal_profile

Try the command

Run es-eslint-install in an empty directory where you will make use of JavaScript linting

npm init --y;
sleep 5;
(
export PKG=eslint-config-airbnb;
npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
);
sleep 5;
yarn;
sleep 5;
./node_modules/eslint/bin/eslint.js --init;
sleep 5;
./node_modules/eslint/bin/eslint.js --fix ./**/**.js

Installing ESlint in your JavaScript Application

  1. Check your package.json
$ cat package.json
  1. Open your current directory in your edit of choice. I'm using Github Atom
$ atom .
  1. In order to install the ESlint Configuration file for the Airbnb style-guide we were told to execute the following line.
$ (
export PKG=eslint-config-airbnb;
npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)
  1. Initiate ESlint with the Airbnb Style Guide
$ ./node_modules/eslint/bin/eslint.js --init

? How would you like to configure ESLint? Use a popular style guide

? Which style guide do you want to follow? Airbnb

? What format do you want your config file to be in? JavaScript

Successfully created .eslintrc.js file in /Users/oliver.treadwell/code/galvanize/g37/q2/w1/eslint-lecture
  1. Let's run our local ESlint executable node module against all JavaScript files within our current directory and their subdirectories.
$ ./node_modules/eslint/bin/eslint.js ./*/*.js
  1. Let's have ESlint fix as much as it can of our JavaScript files within our current local directory and their subdirectories
$ ./node_modules/eslint/bin/eslint.js --fix ./*/*.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment