-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
tools: auto fix custom eslint rule for crypto-check.js #16647
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
Changes from 1 commit
b35d423
803357b
6d6cdc6
1f52446
2ecf517
1018b5b
46206b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
1. Fixer for crypto-check.js 2. extends tests Refs : #16636
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,20 +13,32 @@ new RuleTester().run('crypto-check', rule, { | |
| 'foo', | ||
| 'crypto', | ||
| ` | ||
| if (!common.hasCrypto) { | ||
| common.skip(); | ||
| } | ||
| require('crypto'); | ||
| if (!common.hasCrypto) { | ||
| common.skip(); | ||
| } | ||
| require('crypto'); | ||
| ` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: unnecessary change. |
||
| ], | ||
| invalid: [ | ||
| { | ||
| code: 'require("crypto")', | ||
| errors: [{ message }] | ||
| errors: [{ message }], | ||
| output: ` | ||
| if (!common.hasCrypto) { | ||
| common.skip(); | ||
| } | ||
| require('crypto'); | ||
| ` | ||
| }, | ||
| { | ||
| code: 'if (common.foo) {} require("crypto")', | ||
| errors: [{ message }] | ||
| errors: [{ message }], | ||
| output: ` | ||
| if (!common.hasCrypto) { | ||
| common.skip(); | ||
| } | ||
| require('crypto'); | ||
| ` | ||
| } | ||
| ] | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,16 @@ module.exports.isRequired = function(node, modules) { | |
| modules.includes(node.arguments[0].value); | ||
| }; | ||
|
|
||
| /** | ||
| * Return true if common module is required | ||
| * in AST Node under inspection | ||
| */ | ||
| var commonModuleRegExp = new RegExp(/^(\.\.\/)*common(\.js)?$/); | ||
| module.exports.isCommonModule = function(node) { | ||
| return node.callee.name === 'require' && | ||
| commonModuleRegExp.test(node.arguments[0].value); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| }; | ||
|
|
||
| /** | ||
| * Returns true if any of the passed in modules are used in | ||
| * binding calls. | ||
|
|
@@ -45,8 +55,8 @@ module.exports.usesCommonProperty = function(node, properties) { | |
| module.exports.inSkipBlock = function(node) { | ||
| var hasSkipBlock = false; | ||
| if (node.test && | ||
| node.test.type === 'UnaryExpression' && | ||
| node.test.operator === '!') { | ||
| node.test.type === 'UnaryExpression' && | ||
| node.test.operator === '!') { | ||
| const consequent = node.consequent; | ||
| if (consequent.body) { | ||
| consequent.body.some(function(expressionStatement) { | ||
|
|
@@ -64,8 +74,8 @@ module.exports.inSkipBlock = function(node) { | |
|
|
||
| function hasSkip(expression) { | ||
| return expression && | ||
| expression.callee && | ||
| (expression.callee.name === 'skip' || | ||
| expression.callee.property && | ||
| expression.callee.property.name === 'skip'); | ||
| expression.callee && | ||
| (expression.callee.name === 'skip' || | ||
| expression.callee.property && | ||
| expression.callee.property.name === 'skip'); | ||
| } | ||
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.
Does this (and other occurences below) pass the test? I think the
'missing crypto'message is missing.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.
Added the string
'missing crypto'in tests. But there's still something wrong. Any help?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.
Done now.