-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
@@ -4,7 +4,8 @@ | |||
"description": "JSON Web Token implementation (symmetric and asymmetric)", | |||
"main": "index.js", | |||
"scripts": { | |||
"test": "mocha --require test/util/fakeDate && nsp check && cost-of-modules" | |||
"lint": "eslint .", | |||
"test": "mocha --require test/util/fakeDate && npm run lint && nsp check && cost-of-modules" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -0,0 +1,3 @@ | |||
.nyc_output/ | |||
coverage/ | |||
node_modules/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Removed.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @MitMaro when I came back and saw how you modified the description ❤️
"no-invalid-regexp": "error", | ||
"no-trailing-spaces": "error", | ||
"no-undef": "error", | ||
"no-unused-vars": "error" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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": true
In JSHint this made sure
eval
was 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": true
This 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": false
With JSHint this added some globals around the use in the browser. This was set to
false
in the configuration, so was not enabled. By default ESLint does not add these globals, and instead is added using thebrowser environment configuration
."wsh": true
This 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": true
This 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": true
Like
trailing
this rule has been moved to JSCS, and is a direct replacement with"dot-notation": "error"
in ESLint."unused": true
Warns 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": true
Warns on using variables before they are defined, replaced with
"no-undef": "error"
in ESLint."laxcomma": true
Another rule that was moved to JSCS, and can be directly replaced with
"comma-style": "error"
from ESLint."node": true
Adds globals that are only available in Node projects, directly replaced with
"node": true
inenv
in ESLint"esnext": true
Adds support to JSHint for ECMAScript 6, directly replaced with
"es6": true
inenv
and"ecmaVersion": 6
inparserOptions
.Globals
"describe": true
,"it": true
,"before": true
Replaced with
"mocha" true
inenv
which adds the same globalsGlobal
"require": true
Added with
"node": true
inenv
in ESLintGlobals
"atob": false
and"escape": true
These are considered built-ins and are allowed by default in ESLint.