Skip to content

Commit

Permalink
tools: auto fix custom eslint rule for crypto-check.js
Browse files Browse the repository at this point in the history
Review comments + updates test cases

Refs : #16636
  • Loading branch information
shobhitchittora committed Feb 15, 2018
1 parent 2ecf517 commit 1018b5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
35 changes: 19 additions & 16 deletions test/parallel/test-eslint-crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,35 @@ new RuleTester().run('crypto-check', rule, {
valid: [
'foo',
'crypto',
`if (!common.hasCrypto) {
common.skip();
`
if (!common.hasCrypto) {
common.skip("missing crypto");
}
require("crypto");
`
],
invalid: [
{
code: 'require("crypto")',
code: 'require("common")\n' +
'require("crypto")',
errors: [{ message }],
output:
`if (!common.hasCrypto) {
common.skip("missing crypto");
}
require("crypto");
`
output: 'require("common")\n' +
'if (!common.hasCrypto) {' +
' common.skip("missing crypto");' +
'}\n' +
'require("crypto")'
},
{
code: 'if (common.foo) {} require("crypto")',
code: 'require("common")\n' +
'if (common.foo) {}\n' +
'require("crypto")',
errors: [{ message }],
output:
`if (!common.hasCrypto) {
common.skip("missing crypto");
}
require("crypto");
`
output: 'require("common")\n' +
'if (!common.hasCrypto) {' +
' common.skip("missing crypto");' +
'}\n' +
'if (common.foo) {}\n' +
'require("crypto")'
}
]
});
6 changes: 3 additions & 3 deletions tools/eslint-rules/crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ module.exports = function(context) {
if (commonModuleNode) {
return fixer.insertTextAfter(
commonModuleNode,
`\nif (!common.hasCrypto) {
common.skip("missing crypto");
}`
'\nif (!common.hasCrypto) {' +
' common.skip("missing crypto");' +
'}'
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/eslint-rules/rules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports.isRequired = function(node, modules) {
modules.includes(node.arguments[0].value);
};

/**
/**
* Return true if common module is required
* in AST Node under inspection
*/
Expand Down

0 comments on commit 1018b5b

Please sign in to comment.