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

Upgrade: eslint-plugin-node to 7.0.1 #10612

Merged
merged 3 commits into from
Jul 20, 2018
Merged

Conversation

mysticatea
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] Other, please explain: upgrade eslint-plugin-node to 7.0.1 for linting our codebase.

What changes did you make? (Give an overview)

It has new features:

  • It reports the APIs of Node.js built-in modules and globals if those are not supported on the configured Node.js versions (^6.14.0 || ^8.10.0 || >=9.10.0).
  • It reports newly deprecated APIs.

Is there anything you'd like reviewers to focus on?

I'm not sure if this util.isDeepStrictEqual() part is needed.
That looks to do double checking for the AST if util.isDeepStrictEqual exists. But why?

// Feature detect the Node.js implementation and use that if available.
if ((util.isDeepStrictEqual && !util.isDeepStrictEqual(beforeAST, afterAST)) || !lodash.isEqual(beforeAST, afterAST)) {

@mysticatea mysticatea added the chore This change is not user-facing label Jul 17, 2018
@aladdin-add
Copy link
Member

I'm not sure if this util.isDeepStrictEqual() part is needed.
That looks to do double checking for the AST if util.isDeepStrictEqual exists. But why?

seems we have been inconsistent in the usage of _. isEqual vs.util.isDeepStrictEqual. it can be restricted in the eslintrc( but in another PR)

@@ -398,6 +398,7 @@ class RuleTester {
function assertASTDidntChange(beforeAST, afterAST) {

// Feature detect the Node.js implementation and use that if available.
// eslint-disable-next-line node/no-unsupported-features/node-builtins
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused about this line. Is the name of the rule "no-unsupported-features/node-builtins" (and therefore the plugin-qualified name is "node/no-unsupported-features/node-builtins"? I don't think I've ever seen a rule defined with a forward slash in its name, just wanted to make sure I understood correctly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We can use / in the rule name in plugins. #3458 (comment) mentioned this fact.

@@ -398,6 +398,7 @@ class RuleTester {
function assertASTDidntChange(beforeAST, afterAST) {

// Feature detect the Node.js implementation and use that if available.
// eslint-disable-next-line node/no-unsupported-features/node-builtins
if ((util.isDeepStrictEqual && !util.isDeepStrictEqual(beforeAST, afterAST)) || !lodash.isEqual(beforeAST, afterAST)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be right about this running two deep equal checks. Maybe it would be worthwhile to extract the logic, or change to a ternary (if (!(util.isDeepStrictEqual ? util.isDeepStrictEqual(beforeAST, afterAST) : lodash.isEqual(beforeAST, afterAST))) {)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's exactly a code I thought.
But I'm wondering we can rewrite it to simple if (!lodash.isEqual(beforeAST, afterAST)) {.
This feature detection might cause to change test results by the existence of util.isDeepStrictEqual.

@platinumazure
Copy link
Member

platinumazure commented Jul 18, 2018 via email

@aladdin-add
Copy link
Member

util.isDeepStrictEqual was introduced in Node.js 9.0.0 (https://nodejs.org/api/util.html#util_util_isdeepstrictequal_val1_val2)

@mysticatea
Copy link
Member Author

@aladdin-add It's the reason util.isDeepStrictEqual was warned by the node/no-unsupported-features/node-builtins rule.

Problem is:

!util.isDeepStrictEqual(beforeAST, afterAST) || !lodash.isEqual(beforeAST, afterAST)

That || is definitely nonsense. So I hope to fix it, but there are two ways:

  1. Ternary operator:

    !(util.isDeepStrictEqual ? util.isDeepStrictEqual(beforeAST, afterAST) : lodash.isEqual(beforeAST, afterAST))
  2. Remove the util.isDeepStrictEqual:

    !lodash.isEqual(beforeAST, afterAST)

I prefer the latter because we don't need the forking by feature detection.

@mysticatea
Copy link
Member Author

Anyway, I'll separate that matter to another PR.

@aladdin-add
Copy link
Member

I prefer the latter because we don't need the forking by feature detection.

agreed!

@mysticatea
Copy link
Member Author

I sent a PR: #10617

@aladdin-add
Copy link
Member

might need to rebase, since #10617 get merged. cc @mysticatea

@mysticatea
Copy link
Member Author

Done!

@mysticatea mysticatea merged commit 761f802 into master Jul 20, 2018
@mysticatea mysticatea deleted the upgrade-eslint-plugin-node branch July 20, 2018 08:18
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jan 17, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jan 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion chore This change is not user-facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants