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.
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 toUse a popular style guide
followed by picking theairbnb
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.
Now that you can lint let's give you and anyone using your project a more convenient way to do it.
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.
Check Integrations.
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.