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

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

Closed

Conversation

shobhitchittora
Copy link
Contributor

@shobhitchittora shobhitchittora commented Oct 31, 2017

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 nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Oct 31, 2017
Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

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

fix: (fixer) => {
return fixer.insertTextAfter(
node,
'\n\nif (!common.hasCrypto)\n\tcommon.skip("missing crypto");'
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

@shobhitchittora shobhitchittora Oct 31, 2017

Choose a reason for hiding this comment

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

Thanks for the comments. Working on commit to fix.

Copy link
Contributor Author

@shobhitchittora shobhitchittora Oct 31, 2017

Choose a reason for hiding this comment

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

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 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
@apapirovski
Copy link
Member

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

message: msg,
fix: (fixer) => {
return fixer.insertTextAfter(
commonModuleNode,
Copy link
Contributor Author

@shobhitchittora shobhitchittora Nov 1, 2017

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

@@ -13,6 +13,16 @@ module.exports.isRequired = function(node, modules) {
};

/**
* Return true if common module is present as a require call
* in AST
*/
Copy link
Member

Choose a reason for hiding this comment

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

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
Contributor Author

Choose a reason for hiding this comment

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

@tniessen Please check now. Suggest if any corrections.

@apapirovski
Copy link
Member

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.

@shobhitchittora
Copy link
Contributor Author

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

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

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.

* in AST Node under inspection
*/
module.exports.isCommonModule = function(node) {
var regExp = new RegExp(/^(\.\.\/)*common(\.js)?$/);
Copy link
Member

Choose a reason for hiding this comment

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

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
Contributor Author

Choose a reason for hiding this comment

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

done.

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

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

}
require('crypto');
if (!common.hasCrypto) {
common.skip();
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done now.

@BridgeAR
Copy link
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
Copy link
Member

targos commented Jan 20, 2018

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

@BridgeAR
Copy link
Member

Ping @shobhitchittora

@shobhitchittora
Copy link
Contributor Author

@BridgeAR I'm on it.

@shobhitchittora
Copy link
Contributor Author

shobhitchittora commented Feb 4, 2018

@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?

Copy link
Contributor

@XadillaX XadillaX left a comment

Choose a reason for hiding this comment

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

lgtm.

`if (!common.hasCrypto) {
common.skip();
}
require("crypto");
`
Copy link
Member

Choose a reason for hiding this comment

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

Nit: unnecessary change.

`if (!common.hasCrypto) {
common.skip("missing crypto");
}
require("crypto");
Copy link
Member

Choose a reason for hiding this comment

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

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

`if (!common.hasCrypto) {
common.skip("missing crypto");
}
require("crypto");
Copy link
Member

Choose a reason for hiding this comment

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

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.

@BridgeAR
Copy link
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
Review comments + updates test cases

Refs : nodejs#16636
Copy link
Contributor Author

@shobhitchittora shobhitchittora left a comment

Choose a reason for hiding this comment

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

Working tests now. Please check.

}
require('crypto');
if (!common.hasCrypto) {
common.skip();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done now.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM with the comment addressed and a green CI.

var commonModuleRegExp = new RegExp(/^(\.\.\/)*common(\.js)?$/);
module.exports.isCommonModule = function(node) {
return node.callee.name === 'require' &&
commonModuleRegExp.test(node.arguments[0].value);
Copy link
Member

Choose a reason for hiding this comment

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

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

@BridgeAR
Copy link
Member

@BridgeAR
Copy link
Member

Seems like there are linting errors.

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

Refs : nodejs#16636
@BridgeAR
Copy link
Member

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, 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>
@BridgeAR
Copy link
Member

Landed in f242d4b 🎉

@shobhitchittora thanks for being patient :-)

@BridgeAR 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 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 MylesBorins mentioned this pull request Aug 16, 2018
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 pending requests for changes, 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