Skip to content

Instantly share code, notes, and snippets.

@alextes
Last active January 25, 2018 03:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextes/cf2163e7a65ba514259db74139533b2b to your computer and use it in GitHub Desktop.
Save alextes/cf2163e7a65ba514259db74139533b2b to your computer and use it in GitHub Desktop.
Helpful pointers when getting started with ESLint.

Getting Started With ESLint

So you have a JavaScript project and want to start linting it, great! There are a couple choices you need to make and a few things you should know. I will try to make the process a breeze.

Setting Up ESLint

Before we dive in, there are two things you'll have to keep in mind:

  • You can install ESLint globally and locally. I would advise you use the local installation method. We'll make it convenient later.
  • When running ESLint's initialization command: ./node_modules/.bin/eslint --init you'll get a few options to kick-start configuration. I would encourage you to opt to Use a popular style guide followed by picking the airbnb one. It is the most popular style guide and I feel a great starting point. You can always overwrite the rules later.
  • Complete the local installation guide.

Adding ESLint to your workflow

Now that you can lint let's give you and anyone using your project a more convenient way to do it.

Adding ESLint to your JavaScript project

At this point, you should be able to run ESLint, if installed globally by running eslint yourfile.js, if installed locally by running ./node_modules/.bin/eslint yourfile.js. The latter isn't very convenient. Furthermore, your project should feature linting but not necessarily through ESLint. A convenient solution most projects use is to add an npm script called 'lint'. Since npm is familiar with its node_modules/ you can drop the part specifying where ESLint is and just add the following property to the npm script object "lint": "eslint src/". You should now be able to npm run lint and see if your code still lints.

Adding ESLint to your editor

Check Integrations.

Feedback

If you got stuck anywhere, feel I should add something, have a correction I should make or just wonder why I'm telling you to do things a particular way, please tell me! You can leave a comment here, find me in the #node.js IRC channel, twitter and even the NodeJS slack group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment