ESlint is designed to be pluggable unlike JSHint and JSLint. And will ship with stylistic rules, same rules that are dropped from JSHint.
http://eslint.org/docs/rules/
I'd like to switch considering we'll need JSHint and JSCS in the near future to enforce our coding standards because JSHint dropped all support for code style checks. Using ESlint we only have to rely on one for everything and we're able to add custom rules easily.
So far I tried with this config and things seems to work fine.
.eslintrc
{
"env": {
"browser": true
},
"globals": {
"Drupal": true,
"drupalSettings": true,
"domready": true,
"jQuery": true,
"_": true,
"matchMedia": true,
"Backbone": true,
"Modernizr": true,
"CKEDITOR": true
},
"rules": {
"quotes": [1, "single", "avoid-escape"],
"semi": [2, "always"],
"brace-style": ["2", "stroustrup"],
"new-cap": 1,
"strict": 2,
"no-extra-strict": 1,
"no-unused-vars": [2, {"vars": "local", "args": "none"}],
"no-underscore-dangle": 0,
"no-new": 0,
"camelcase": 0
}
}
.eslintignore
core/assets/vendor/*
core/modules/tour/js/jquery.joyride-2.0.3.js
core/vendor/*
sites/*/files
what's cool is that it allows us to say what is an error and what is a warning. Allowing the config to be very strict on code-style rules while not getting too much in the way and keeping the dangerous things as errors.
This config still gives 442 "problems" (errors and warnings).
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | core-eslint-2264205-2.patch | 1.87 KB | nod_ |
Comments
Comment #1
nod_Tweaked the config some more, used JSHint compatibility table to replicate the config we have.
Using ESLint shows that JSHint is pretty buggy on some rules checks and that we're still sloppy, there are a couple of straight up bugs raised by this config:
Output:
Comment #2
nod_With #2264241: Fix ESLint errors and fix js bugs and this patch, everything validates.
Now we get to pick how picky we want to be.
Comment #3
attiks commentedThis looks like it is ready for commit, I assume we discuss how picky we want to be in a separate issue?
Comment #4
nod_yeah that's fair enough with me. We'll need to fix all the stuff we get picky about so it's another task than acting on not using jshint and updating all related docs.
Comment #5
nod_I'm not kidding anyone :p
Comment #7
tim.plunkettRandom fail from when HEAD was broken (Drupal\simpletest\Tests\InstallationProfileModuleTestsTest)
Comment #8
alexpottCommitted 5f62e92 and pushed to 8.x. Thanks!
Comment #10
nod_Issue for configuration choice #2274195: Decide ESLint config
Comment #11
nod_Updated doc page: https://drupal.org/node/1955232
Will write a new change notice to replace https://drupal.org/node/1972428
Comment #12
nod_New change notice https://drupal.org/node/2274223 added a comment in the old one to say it's deprecated. Not sure the proper way to do that, we should probably delete/unpublish the previous JSHint change notice but I don't know.
Comment #13
alexpottI've unpublished the old JSHint change notice - @nod_ thanks for sorting out the change notices!