This took me way longer than expected due to me losing the repl twice. So without further ado, let's get into the world of eslint and good, clean code!
What is ESLINT?
EsLint is a way for people to enforce code style and good coding practices. They allow you to clean up your code, and also even give you insights about redundant code and code that won't ever be reached.
Getting EsLint
Getting eslint is super easy. Just go to the shell (hit ctrl + shift + s if you can't find it), and type in this:
npm i -D eslint ; npm init -y ; npx eslint --init
First, it will install eslint, then it will initiate your package.json with default values, and then it will initiate eslint. If all of that goes well, it will look something like this:
Go through the form, and soon you will find yourself a very nice eslintrc.js (given you chose JS as your config file)!
Configuring EsLint even more
In order to configure eslint more, and get in more options, you will first need to know what those options available are! This is a doc of all the available configurations. You can also add some yourself, but eslint has a ridiculous amount of avaible configurations, and I never had to actually use that.
EsLint Syntax
So now we know what our options are, but how do we use them? Simple! Inside your rules are where all the options (or as eslint calls them, rules) are.
They can either be a string or an array or a number. If it is a string, it has to be: "none", "warning", or "error". "none" means eslint doesn't enforce it, "warning" warns you about it, and "error" well, errors. For some reason eslinters are super rash and we always use "error" so that's what we are using. The numbers also correspond to that, here's a table:
number
error code
0
none
1
warning
2
error!!
Ok, lets look at an example! We will look at the no-extra-parens rule.
"no-extra-parens": 2
Now, by default, it:
disallows unnecessary parentheses around any expression
Hopefully this was a good introduction to eslint. It's actually quite simple, and I think they did a good job designing something that would be simple to use, but also very powerful.
Nice, but I'm not that big on code readability, since I do my projects alone 99% of the time. Also, this tends to be a nuisance since it since most code linters mess up from time to time, also it just gives extra errors/warnings (which I stress about when I shouldn't).
JavaScript Code Style
This took me way longer than expected due to me losing the repl twice. So without further ado, let's get into the world of eslint and good, clean code!
What is ESLINT?
EsLint is a way for people to enforce code style and good coding practices. They allow you to clean up your code, and also even give you insights about redundant code and code that won't ever be reached.
Getting EsLint
Getting eslint is super easy. Just go to the shell (hit
ctrl + shift + s
if you can't find it), and type in this:First, it will install eslint, then it will initiate your
package.json
with default values, and then it will initiate eslint. If all of that goes well, it will look something like this:Go through the form, and soon you will find yourself a very nice
eslintrc.js
(given you chose JS as your config file)!Configuring EsLint even more
In order to configure eslint more, and get in more options, you will first need to know what those options available are!
This is a doc of all the available configurations. You can also add some yourself, but eslint has a ridiculous amount of avaible configurations, and I never had to actually use that.
EsLint Syntax
So now we know what our options are, but how do we use them? Simple! Inside your
rules
are where all the options (or as eslint calls them, rules) are.They can either be a string or an array or a number.
If it is a string, it has to be:
"none"
,"warning"
, or"error"
."none"
means eslint doesn't enforce it,"warning"
warns you about it, and"error"
well, errors. For some reason eslinters are super rash and we always use"error"
so that's what we are using. The numbers also correspond to that, here's a table:Ok, lets look at an example! We will look at the
no-extra-parens
rule.Now, by default, it:
Seems pretty useful! Now, lets look at a more complex rule,
array-element-newline
.This takes in an object sometimes! Make sure to read the documentation carefully.
My Code Style
Here's my
eslintrc.js
:Closing
Hopefully this was a good introduction to eslint. It's actually quite simple, and I think they did a good job designing something that would be simple to use, but also very powerful.
Nice, but I'm not that big on code readability, since I do my projects alone 99% of the time. Also, this tends to be a nuisance since it since most code linters mess up from time to time, also it just gives extra errors/warnings (which I stress about when I shouldn't).
lol yeah @Baconman321