32
loading...
This website collects cookies to deliver better user experience
npm init -y
in the terminal (for Linux, npm users obv) if you hadn't done so yet. You know now you have a package.json file. npm install eslint --save-dev
in the terminal. Now you have npm_modules and a package.lock.json file too. Anyway, now you need to initiate ESLint in your folder. Write npx eslint --init
in the terminal. Now you'll be prompted with various questions like "How would you like to use ESLint=" or "Which style guide do you want to follow?", I think this part is pretty self-explanatory and depends on personal choices, so I'm not talking about them. Just choose whatever suits you."scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
}```
add the following code: `"Lint": "npx eslint yourfile.js"` Of course, in here `yourfile.js` is the Javascript file you'd wish to use ESLint in, so change that name accordingly. The outcome should be something like this:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "npx eslint app.js"
npm run lint
in the terminal, there you'll see all the comments on the terminal. But, like, this is not so good or efficient, I want to see my mistakes on my text editor you say? Well, fear not, because there's an extension for that.preferences-settings-extensions-eslint
( you can search for ESLint once in the settings and do not forget to click on Workspace
because that's where we're gonna change the settings) and there, on the right top of the page, you'll see an icon, and if you hover on it it'll read Open Settings (JSON)
. This will take you to a file named workspace.json
. There, add the following to the settings
so it'll look something like this:"settings": {
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}```
And voilà! Now whenever you save your code, ESLint will run and do its magic.
Happy coding!