FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

tools: auto fix custom eslint rule for crypto-check.js by shobhitchittora · Pull Request #16647 · nodejs/node · GitHub

/ node Public

tools: auto fix custom eslint rule for crypto-check.js - #16647

Closed
shobhitchittora wants to merge 7 commits into
nodejs:masterfrom
shobhitchittora:cryto-check-fix
Closed

tools: auto fix custom eslint rule for crypto-check.js#16647
shobhitchittora wants to merge 7 commits into
nodejs:masterfrom
shobhitchittora:cryto-check-fix

Conversation

shobhitchittora commented Oct 31, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

This implements an eslint fixer function to auto insert common.hasCryto check if missed out.

Refs: #16636

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
  • test cases added for changes
  • python ./tools/test.py parallel/test-eslint-crypto-check
Affected core subsystem(s)

Tools

nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Oct 31, 2017

apapirovski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for starting the work! Left some minor feedback and please see the other PR re: the need for tests.

Comment thread tools/eslint-rules/crypto-check.js Outdated
fix: (fixer) => {
return fixer.insertTextAfter(
node,
'\n\nif (!common.hasCrypto)\n\tcommon.skip("missing crypto");'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What does the node refer to in this context? This should be getting inserted right after common is required rather than somewhere random.

Also, the project doesn't use tabs but rather spaces so \t should be a double space.

shobhitchittora Oct 31, 2017
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the comments. Working on commit to fix.

shobhitchittora Oct 31, 2017
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've pushed the changes. Also please note that I've added a regExp in rules-utils.js, please verify the validity of the same, or suggest if there are any better ways of doing that.

The reason for doing this was because the common module was addressed with different relative paths, such as ../../common or ../common.

shobhitchittora changed the title tools: auto fix custom eslint rule for cryto-check.js tools: auto fix custom eslint rule for crypto-check.js Oct 31, 2017

Copy link
Copy Markdown
Contributor

Thanks for the updates! I'll be happy to review again once we have the tests for all of these fixers, just so we can be sure that they're working properly (it's a bit hard to tell without actually running the code).

Comment thread tools/eslint-rules/crypto-check.js Outdated

shobhitchittora Nov 1, 2017
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Need help here @apapirovski . commonModuleNode comes as null here when running make -j4 test. I'm setting commonModuleNode in testCryptoUsage method.

PS: This works fine when running eslint with --fix to fix a generated error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Comment thread tools/eslint-rules/rules-utils.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This description is not entirely accurate. The given node must be a call to require, it does not work for nodes which contain such a call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@tniessen Please check now. Suggest if any corrections.

Copy link
Copy Markdown
Contributor

Much like with the other PR:

I won't outright block this but I'm -1 on landing this. I really don't like the idea of auto fixing these skip checks because of the potential for things going really wrong. The fact that it has to lookup an entirely unrelated part of the code to insert the check is concerning. There are so many different possibilities for what a require that passes that RegExp could actually be requiring.

Sorry @shobhitchittora.

Copy link
Copy Markdown
Contributor Author

@BridgeAR What are your views on landing this?
@apapirovski I can relate to your comment here. +1

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I personally do not see as much concern as @apapirovski here as these rules are only active for our tests and we should realize if something goes wrong. The latest in the code review.

Comment thread tools/eslint-rules/rules-utils.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why do you not write the RegExp directly? There is no dynamic part as far as I see it.
So /^(\.\.\/)*common(\.js)?$/ does the job and can be moved outside of the function. That way it is only created once.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

done.

shobhitchittora force-pushed the cryto-check-fix branch 2 times, most recently from d607020 to d8d5713 Compare December 10, 2017 12:44

Copy link
Copy Markdown
Contributor Author

@BridgeAR would you be so kind and run CI for this too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does this (and other occurences below) pass the test? I think the 'missing crypto' message is missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Added the string 'missing crypto' in tests. But there's still something wrong. Any help?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done now.

Copy link
Copy Markdown
Member

@shobhitchittora this has similar issues as the other PRs. Please run the tests by calling make -j4 test. You can also run the individual test by running python ./tools/test.py parallel/test-eslint-crypto-check.

targos commented Jan 20, 2018

Copy link
Copy Markdown
Member

You can also run the linter only with make lint-js

Copy link
Copy Markdown
Member

Ping @shobhitchittora

Copy link
Copy Markdown
Contributor Author

@BridgeAR I'm on it.

shobhitchittora commented Feb 4, 2018
edited
Loading

Copy link
Copy Markdown
Contributor Author

@BridgeAR I cannot spot the diff when running python ./tools/test.py parallel/test-eslint-crypto-check fails. Just getting this -

=== release test-eslint-crypto-check ===
Path: parallel/test-eslint-crypto-check
assert.js:43
  throw new errors.AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Output is incorrect.
[00:00|% 100|+   0|-   1]: Done

Any suggestions? Can you spot the error?

XadillaX left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nit: unnecessary change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This can not be the proper output because there is no common imported in the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This can not be the expected output because common is not imported. But not only that, the first statement if (common.foo) {} was just removed? That is definitely not right.

Copy link
Copy Markdown
Member

@shobhitchittora please rebase and run the code again. In that case the output is going to show what check failed. Please carefully check what change you expect and what not with what input.

Please add another test with a case where common is actually imported in the checked code part.

1. Fixer for crypto-check.js
2. extends tests

Refs : nodejs#16636
Adds check for fixing on when require('common') is present.

Refs : nodejs#16636
Adds "missing crypto" message in tests.

Refs : nodejs#16636
1. Refactors test
2. Removes commonModule AST node as array.

Refs : nodejs#16636

shobhitchittora left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Working tests now. Please check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done now.

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM with the comment addressed and a green CI.

Comment thread tools/eslint-rules/rules-utils.js Outdated
var commonModuleRegExp = new RegExp(/^(\.\.\/)*common(\.js)?$/);
module.exports.isCommonModule = function(node) {
return node.callee.name === 'require' &&
commonModuleRegExp.test(node.arguments[0].value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This will produce access errors due to accessing nodes without arguments. Please guard against them the same as I suggested in the other PR.

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member

Seems like there are linting errors.

Removes extra spaces ( lint-error ) + rules-utils argument check
suggestoin

Refs : nodejs#16636

Copy link
Copy Markdown
Member

BridgeAR added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Feb 17, 2018
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Feb 17, 2018
1. Fixer for crypto-check.js
2. Extends tests

PR-URL: nodejs#16647
Refs: nodejs#16636
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

Copy link
Copy Markdown
Member

Landed in f242d4b 🎉

@shobhitchittora thanks for being patient :-)

BridgeAR closed this Feb 17, 2018
MylesBorins pushed a commit that referenced this pull request Feb 21, 2018
1. Fixer for crypto-check.js
2. Extends tests

PR-URL: #16647
Refs: #16636
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins mentioned this pull request Feb 21, 2018
MylesBorins pushed a commit that referenced this pull request Feb 21, 2018
1. Fixer for crypto-check.js
2. Extends tests

PR-URL: #16647
Refs: #16636
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Feb 21, 2018
1. Fixer for crypto-check.js
2. Extends tests

PR-URL: #16647
Refs: #16636
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
1. Fixer for crypto-check.js
2. Extends tests

PR-URL: nodejs#16647
Refs: nodejs#16636
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Aug 7, 2018
1. Fixer for crypto-check.js
2. Extends tests

PR-URL: #16647
Refs: #16636
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
rvagg pushed a commit that referenced this pull request Aug 16, 2018
1. Fixer for crypto-check.js
2. Extends tests

PR-URL: #16647
Refs: #16636
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins mentioned this pull request Aug 16, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. tools Issues and PRs related to the tools directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants


Back | FazBrowse Home | New Git URL