Lately I came back into Javascript development. Although my preferred language is still Go there is the undeniable fact that JavaScript is a tool used by many modern platforms. As per request by Mr. Goern here are my lessons learned. Please comment and fill in.
I’m on a Mac and use iTerm and VSCode. I’m not going to argue about these choices.
The first thing you want to do is get eslint: The ESLint - Pluggable JavaScript linter
$ npm install -g eslint
Now the real question will be which configuration you should use. The good news is that ESlint has sharable configs and there are currently 3 suggested once: Google, AirBnB and Standard. You will get a selection when you run eslint —-init
:
○ → eslint --init
? How would you like to configure ESLint? Use a popular style guide
? Which style guide do you want to follow? (Use arrow keys)
❯ Google
Airbnb
Standard
Now you select Standard and JSON as the format you will get something like:
{
"extends": "standard",
"plugins": [
"standard",
"promise"
]
}
Now save this as .eslintrc.json
in the root of your project.
The great thing is the integration with VSCode. First make sure that you have the VSCode Extension installed.
If you now require something that is not used you should see an no-unused-vars
error.
But the best thing is that eslint has a --fix
option and the VSCode extension has a to run this. E.g. via the command Commands: "Fix all auto-fixable problems".
That's it for today. If you have any suggestions what a modern JS developer should do for his setup please let me know.