Skip to content
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

Merged
merged 4 commits into from
Jun 25, 2018

Conversation

MitMaro
Copy link
Contributor

@MitMaro MitMaro commented Jun 14, 2018

@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 the browser 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 in env in ESLint

"esnext": true

Adds support to JSHint for ECMAScript 6, directly replaced with "es6": true in env and "ecmaVersion": 6 in parserOptions.

Globals "describe": true, "it": true, "before": true

Replaced with "mocha" true in env which adds the same globals

Global "require": true

Added with "node": true in env in ESLint

Globals "atob": false and "escape": true

These are considered built-ins and are allowed by default in ESLint.

@MitMaro MitMaro changed the title Complete Eslint conversion and cleanup Complete ESLint conversion and cleanup Jun 14, 2018
@JacoKoster
Copy link
Contributor

JacoKoster commented Jun 14, 2018

Excellent work, with the move to ES6, i would also really-really like to deprecate the older node versions.

This fixes #486, btw.

@MitMaro
Copy link
Contributor Author

MitMaro commented Jun 14, 2018

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.

@JacoKoster
Copy link
Contributor

JacoKoster commented Jun 14, 2018

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

@JacoKoster
Copy link
Contributor

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 ;-)

@JacoKoster JacoKoster mentioned this pull request Jun 19, 2018
@MitMaro
Copy link
Contributor Author

MitMaro commented Jun 19, 2018

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 no-shadow, and I wouldn't mind putting up a PR with some of those rules later. Assuming that this PR can be merged. :)

@JacoKoster
Copy link
Contributor

@ziluvatar Care to join us in the discussion?

@ziluvatar
Copy link
Contributor

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 :)

@MitMaro
Copy link
Contributor Author

MitMaro commented Jun 20, 2018

@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"
Copy link
Contributor

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.

Copy link
Contributor Author

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.

MitMaro added 3 commits June 20, 2018 16:49
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.
@MitMaro
Copy link
Contributor Author

MitMaro commented Jun 20, 2018

I've rebased the branch to fix the conflict.

@MitMaro
Copy link
Contributor Author

MitMaro commented Jun 20, 2018

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/
Copy link
Contributor

@JacoKoster JacoKoster Jun 20, 2018

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

Copy link
Contributor Author

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.
Copy link
Contributor

@ziluvatar ziluvatar left a 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"
Copy link
Contributor

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.

@ziluvatar ziluvatar merged commit cb1d2e1 into auth0:master Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants