Complete ESLint conversion and cleanup#490
Conversation
|
Excellent work, with the move to ES6, i would also really-really like to deprecate the older node versions. This fixes #486, btw. |
|
I read that issue when you posted it but forgot all about it. I hope I didn't step on any work you may have been doing. |
|
No worries, i was busy figuring out how to use ecdsa-certificates with JWKS and this library. If i get that working i was planning on doing the OpenID improvements |
|
In another project the linter gave an error about shadowed variables. I have seen that also as comments on PR's in this project, so i recommend adding no-shadow as well ;-) |
|
I limited this PR to only contain the conversions from JSHint to ESLint. I do agree that there are a lot of other rules that could be added, including |
|
@ziluvatar Care to join us in the discussion? |
|
I'd like to review both JSHint and ESLint rules (I don't have too much knowledge about them) and the changes in this PR before merging. The move JSHint to ESLint is fine for me, just give me some time to investigate :) |
|
@ziluvatar I will try to add some links to the PR description that will help in your investigations this evening. :) |
package.json
Outdated
There was a problem hiding this comment.
In #486 It was mentioned to break the build early when linting fails and it was therefor proposed to move the lint in front of the test.
There was a problem hiding this comment.
I've moved linting first.
The .eslintrc file without an extension was deprecated a few years ago, so this change renames the file to add the required extension. See: eslint/eslint@c9a8883
This change adds ESLint as a dev-dependency and adds a lint script that will run ESLint.
Convert all the JSHint rules to the ESLint equivalents where possible. The no-undef rule in ESLint caught a few cases of undefined usages in the tests, so they were also fixed.
|
I've rebased the branch to fix the conflict. |
|
I've updated the PR description with some more information on each conversion. I will gladly go into more detail on anything if needed. |
.eslintignore
Outdated
There was a problem hiding this comment.
In addition to any patterns in a .eslintignore file, ESLint always ignores files in /node_modules/* and /bower_components/*.
https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories
The HTML coverage report is currently being linted, which causes a lot if invalid linting errors. This change adds a ignore file to ensure these files are properly skipped during linting.
| "no-invalid-regexp": "error", | ||
| "no-trailing-spaces": "error", | ||
| "no-undef": "error", | ||
| "no-unused-vars": "error" |
There was a problem hiding this comment.
Maybe this could be ignored in tests, where you usually don't use all the variables from a function. For now it is fine since you fixed them. Let's keep that in mind now that you will play a lot with tests.
@JacoKoster started using ESLint in Pull Request #480, this change completes the work stared in that PR.
There are three commits to this PR that are related but I will gladly separate into separate PRs if desired.
ESLint config rename
The first change is to rename the ESLint configuration file to use a file extension as the config file without an extension was deprecated several years ago. source
Running ESLint
The second change adds ESLint as a development dependency for the project and adds a lint script to run ESLint against the project. This should also make it so that the TravisCI will also run the linting script.
JSHint to ESLint conversion
This is the largest change in the PR. This removes the JSHint configuration file and adds ESLint rules that are equivalent. In the process there were a few files in
test/that were failing the linting process that had to be fixed.Changes
"evil": trueIn JSHint this made sure
evalwas not used. It is replaced with the equivalent"no-eval": "error"and"no-implied-eval": "error". ESLint detects a bit more than what JSHint did in this regard."regexdash": trueThis was removed some time ago from JSHint, but it caught "an unescaped last dash (-) inside brackets". It is replaced with
"no-div-regex": "error","no-invalid-regexp": "error", and"no-control-regex": "error". The ESLint rules go further than the JSHint rule in validating regular expressions."browser": falseWith JSHint this added some globals around the use in the browser. This was set to
falsein the configuration, so was not enabled. By default ESLint does not add these globals, and instead is added using thebrowser environment configuration."wsh": trueThis adds globals for Windows Script Host, and does not make sense in this project, and I would assume was not meant to be added.
"trailing": trueThis ensures no trailing whitespave on files, and was removed from JSHint. JSHint recommended using JSCS for this rule, which was eventually merged into ESLint. The
"no-trailing-spaces": "error"ESLint rule is a direct replacement for this rule."sub": trueLike
trailingthis rule has been moved to JSCS, and is a direct replacement with"dot-notation": "error"in ESLint."unused": trueWarns on unused variables, This is directly replaced with
"no-unused-vars": "error"in ESLint. The ESLint rule also catches some cases the JSHint does not, as seen in the updates required to the tests."undef": trueWarns on using variables before they are defined, replaced with
"no-undef": "error"in ESLint."laxcomma": trueAnother rule that was moved to JSCS, and can be directly replaced with
"comma-style": "error"from ESLint."node": trueAdds globals that are only available in Node projects, directly replaced with
"node": trueinenvin ESLint"esnext": trueAdds support to JSHint for ECMAScript 6, directly replaced with
"es6": trueinenvand"ecmaVersion": 6inparserOptions.Globals
"describe": true,"it": true,"before": trueReplaced with
"mocha" trueinenvwhich adds the same globalsGlobal
"require": trueAdded with
"node": trueinenvin ESLintGlobals
"atob": falseand"escape": trueThese are considered built-ins and are allowed by default in ESLint.