.
pipe
(
babel
())
.
pipe
(
gulp
.
dest
(
"dist"
));
// browser source
gulp
.
src
(
"public/es6/**/*.js"
)
.
pipe
(
babel
())
.
pipe
(
gulp
.
dest
(
"public/dist"
));
});
Now let’s see what ESLint doesn’t like about our code. Because we included ESLint in
our
default
task in the Gulpfile, we can simply run Gulp:
$ gulp
[15:04:16] Using gulpfile ~/git/gulpfile.js
[15:04:16] Starting 'default'...
[15:04:16] Finished 'default' after 84 ms
[15:04:16]
/home/ethan/lj/es6/test.js
4:59 error Unexpected trailing comma comma-dangle
9:5 error Unexpected console statement no-console
✖ 2 problems (2 errors, 0 warnings)
Clearly, Nicholas Zakas and I disagree about trailing commas. Fortunately, ESLint lets
you make your own choices about what’s an error and what’s not. The
comma-dangle
rule defaults to
"never"
, and we have the option of turning it off altogether, or chang‐
ing it to
"always-multiline"
(my preference). Let’s edit the .eslintrc file to change
this setting (if you agree with Nicholas about trailing commas, you can use the default
of
"never"
). Each rule in the .eslintrc is an array. The first element is a number, where
0 turns the rule off, 1 considers it a warning, and 2 considers it an error:
{
"rules"
: {
/*
changed
comma-dangle
default...ironically,
we
can't
use
a
dangling
comma
here
because
this
is
a
JSON
file.
*/
"comma-dangle"
: [
2
,
"always-multiline"
],
"indent"
: [
2
,
4
],
/*
...
*/
Now if you run
gulp
again, you’ll see that our dangling comma no longer causes an
error. As a matter of fact, if we remove it, it will cause an error!
The second error refers to using
console.log
, which is generally considered “sloppy”
(even dangerous if you’re targeting legacy browsers) when used in production
browser code. For learning purposes, however, you can disable this, as we’ll be using
Linting | 29