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: custom eslint autofix for inspector-check.js #16646

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tools: custom eslint autofix for inspector-check.js
1. Removes extra indentation
2. Removes array to track commomModule AST node.
3. Refactored test

Refs: #16636
  • Loading branch information
shobhitchittora committed Feb 12, 2018
commit 4afc45d792876f3f0cc62373cb6f720d14aedb6e
8 changes: 4 additions & 4 deletions test/parallel/test-eslint-inspector-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ new RuleTester().run('inspector-check', rule, {
valid: [
'foo;',
'common.skipIfInspectorDisabled(); require("inspector");',
`require("common");
common.skipIfInspectorDisabled();
require("inspector");`
'require("common");\n' +
'common.skipIfInspectorDisabled();\n' +
'require("inspector");'
Copy link
Member

Choose a reason for hiding this comment

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

Please either use a single code line (I would do that as in the example above the added one) or indent the code so the concatenated part is deeper indented than the start of the string.

],
invalid: [
{
code: 'require("inspector")',
code: 'require("inspector");',
errors: [{ message }],
output: 'require("common");\n' +
'common.skipIfInspectorDisabled();\n' +
Expand Down
16 changes: 9 additions & 7 deletions tools/eslint-rules/inspector-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const utils = require('./rules-utils.js');
// Rule Definition
//------------------------------------------------------------------------------
const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' +
'test to be skippped when Node is built \'--without-inspector\'.';
'test to be skippped when Node is built \'--without-inspector\'.';

module.exports = function(context) {
const missingCheckNodes = [];
const commonModuleNodes = [];
var commonModuleNode = null;
var hasInspectorCheck = false;

function testInspectorUsage(context, node) {
Expand All @@ -24,7 +24,7 @@ module.exports = function(context) {
}

if (utils.isCommonModule(node)) {
commonModuleNodes.push(node);
commonModuleNode = node;
}
}

Expand All @@ -41,10 +41,12 @@ module.exports = function(context) {
node,
message: msg,
fix: (fixer) => {
return fixer.insertTextAfter(
commonModuleNodes[0],
'\ncommon.skipIfInspectorDisabled();'
);
if (commonModuleNode) {
return fixer.insertTextAfter(
commonModuleNode,
'\ncommon.skipIfInspectorDisabled();'
);
}
}
});
});
Expand Down
12 changes: 6 additions & 6 deletions tools/eslint-rules/rules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,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) {
Expand All @@ -74,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');
}