- [Instructor] There's more than one way to install ESLint.
So let's compare the approaches.
The first and most tempting is to install ESLint globally.
The good thing about this approach
is you can just type ESLint to run the program.
However, it comes with a terrible curse,
installing ESLint globally
is a package management anti-pattern for several reasons.
The locally installed version
will not likely be in sync with the other developers.
Different projects may be expecting
different versions of ESLint.
Finally, a globally installed version of use of ESLint,
means plugin management can be difficult to maintain.
Believe me, I felt this particular pain before.
Instead, the optimal approach
is to install ESLint within a project.
This is good because ESLint
can be managed like any other package
that you're going to be using.
Just add ESLint to the development dependencies,
on installation ESLint will be installed
in the node modules folder.
What's the best way to run it?
The solution is to use npx,
which is npm package runner,
npx has been available since npm version 5.2
and it makes it easy to use command line interface tools.
I'd like to clear up some misconceptions
around task runners and linters
A question that I've heard is,
do I need gulp, grunt or something similar to run a linter?
Nope, you do not.
Why not?
ESLint is a flexible platform with granular configuration
and it's completely functional as a standalone application.
Also, linting is not a compilation task,
it's a type of testing.
What about editors?
Can they lint files without using a task runner?
Yes they can, and I'll show you how.
All right, so if I'm recommending not to use a task runner,
what if it's necessary
for additional ESLint runtime configurations?
Just use the package.json scripts property instead.
For example, you may want
a continuous integration build process
that links your application and generates a report.
It can be done on one line,
no separate task runner or plugins is necessary.
To summarize, you don't need a separate task runner to lint.
Lets install ESLint by adding it
to the devDependencies around project.
Switch over to VS code.
We're going to need to switch the terminal.
We're going to use npm to install ESLint,
and then a space dash D,
to add it to the devDependencies,
press enter.
After a moment, ESLint will be added to the project.
Let's execute ESLint directly from the terminal,
type npx, the package runner ESLint,
then space, then dash dash help.
The ESLint usage instructions will be shown.
You can scroll the terminal with your mouse wheel,
to see all of the instructions.
At the very top, the usage will be shown,
basically ESLint,
then options if any,
then the target to scan.
Okay, so let's scan the current directory,
type npx
space ESLint
space dot
to indicate the current directory,
press enter.
That's a bit gnarly.
Let's scroll up a little bit.
Oops, something went wrong.
ESLint couldn't find a configuration file.
We can fix this problem by creating the configuration.
How do we go about configuring ESLint?