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: update ESLint to 8.0.0 #40394

Merged
merged 7 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 0 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const hacks = [
'eslint-plugin-node-core',
'eslint-plugin-markdown',
'@babel/eslint-parser',
'@babel/plugin-syntax-class-properties',
'@babel/plugin-syntax-import-assertions',
'@babel/plugin-syntax-top-level-await',
];
Module._findPath = (request, paths, isMain) => {
const r = ModuleFindPath(request, paths, isMain);
Expand All @@ -39,13 +36,6 @@ module.exports = {
plugins: ['markdown', 'node-core'],
parser: '@babel/eslint-parser',
parserOptions: {
babelOptions: {
plugins: [
Module._findPath('@babel/plugin-syntax-class-properties'),
Module._findPath('@babel/plugin-syntax-import-assertions'),
Module._findPath('@babel/plugin-syntax-top-level-await'),
],
},
requireConfigFile: false,
sourceType: 'script',
},
Expand Down
167 changes: 84 additions & 83 deletions tools/eslint-rules/crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,107 +20,108 @@ const cryptoModules = ['crypto', 'http2'];
const requireModules = cryptoModules.concat(['tls', 'https']);
const bindingModules = cryptoModules.concat(['tls_wrap']);

module.exports = function(context) {
const missingCheckNodes = [];
const requireNodes = [];
let commonModuleNode = null;
let hasSkipCall = false;
module.exports = {
meta: {
fixable: 'code',
},
create(context) {
const missingCheckNodes = [];
const requireNodes = [];
let commonModuleNode = null;
let hasSkipCall = false;

function testCryptoUsage(node) {
if (utils.isRequired(node, requireModules) ||
utils.isBinding(node, bindingModules)) {
requireNodes.push(node);
}

function testCryptoUsage(node) {
if (utils.isRequired(node, requireModules) ||
utils.isBinding(node, bindingModules)) {
requireNodes.push(node);
if (utils.isCommonModule(node)) {
commonModuleNode = node;
}
}

if (utils.isCommonModule(node)) {
commonModuleNode = node;
function testIfStatement(node) {
if (node.test.argument === undefined) {
return;
}
if (isCryptoCheck(node.test.argument)) {
checkCryptoCall(node);
}
}
}

function testIfStatement(node) {
if (node.test.argument === undefined) {
return;
}
if (isCryptoCheck(node.test.argument)) {
checkCryptoCall(node);
function isCryptoCheck(node) {
return utils.usesCommonProperty(node, ['hasCrypto', 'hasFipsCrypto']);
}
}

function isCryptoCheck(node) {
return utils.usesCommonProperty(node, ['hasCrypto', 'hasFipsCrypto']);
}

function checkCryptoCall(node) {
if (utils.inSkipBlock(node)) {
hasSkipCall = true;
} else {
missingCheckNodes.push(node);
function checkCryptoCall(node) {
if (utils.inSkipBlock(node)) {
hasSkipCall = true;
} else {
missingCheckNodes.push(node);
}
}
}

function testMemberExpression(node) {
if (isCryptoCheck(node)) {
checkCryptoCall(node);
function testMemberExpression(node) {
if (isCryptoCheck(node)) {
checkCryptoCall(node);
}
}
}

function reportIfMissingCheck() {
if (hasSkipCall) {
// There is a skip, which is good, but verify that the require() calls
// in question come after at least one check.
if (missingCheckNodes.length > 0) {
requireNodes.forEach((requireNode) => {
const beforeAllChecks = missingCheckNodes.every((checkNode) => {
return requireNode.range[0] < checkNode.range[0];
});

if (beforeAllChecks) {
context.report({
node: requireNode,
message: msg
function reportIfMissingCheck() {
if (hasSkipCall) {
// There is a skip, which is good, but verify that the require() calls
// in question come after at least one check.
if (missingCheckNodes.length > 0) {
requireNodes.forEach((requireNode) => {
const beforeAllChecks = missingCheckNodes.every((checkNode) => {
return requireNode.range[0] < checkNode.range[0];
});
}
});

if (beforeAllChecks) {
context.report({
node: requireNode,
message: msg
});
}
});
}
return;
}
return;
}

if (requireNodes.length > 0) {
if (missingCheckNodes.length > 0) {
report(missingCheckNodes);
} else {
report(requireNodes);
if (requireNodes.length > 0) {
if (missingCheckNodes.length > 0) {
report(missingCheckNodes);
} else {
report(requireNodes);
}
}
}
}

function report(nodes) {
nodes.forEach((node) => {
context.report({
node,
message: msg,
fix: (fixer) => {
if (commonModuleNode) {
return fixer.insertTextAfter(
commonModuleNode,
'\nif (!common.hasCrypto) {' +
' common.skip("missing crypto");' +
'}'
);
function report(nodes) {
nodes.forEach((node) => {
context.report({
node,
message: msg,
fix: (fixer) => {
if (commonModuleNode) {
return fixer.insertTextAfter(
commonModuleNode,
'\nif (!common.hasCrypto) {' +
' common.skip("missing crypto");' +
'}'
);
}
}
}
});
});
});
}

return {
'CallExpression': (node) => testCryptoUsage(node),
'IfStatement:exit': (node) => testIfStatement(node),
'MemberExpression:exit': (node) => testMemberExpression(node),
'Program:exit': () => reportIfMissingCheck()
};
};
}

module.exports.meta = {
fixable: 'code'
return {
'CallExpression': (node) => testCryptoUsage(node),
'IfStatement:exit': (node) => testIfStatement(node),
'MemberExpression:exit': (node) => testMemberExpression(node),
'Program:exit': () => reportIfMissingCheck()
};
}
};
79 changes: 40 additions & 39 deletions tools/eslint-rules/inspector-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,54 @@ const utils = require('./rules-utils.js');
const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' +
'test to be skipped when Node is built \'--without-inspector\'.';

module.exports = function(context) {
const missingCheckNodes = [];
let commonModuleNode = null;
let hasInspectorCheck = false;
module.exports = {
meta: {
fixable: 'code',
},
create(context) {
const missingCheckNodes = [];
let commonModuleNode = null;
let hasInspectorCheck = false;

function testInspectorUsage(context, node) {
if (utils.isRequired(node, ['inspector'])) {
missingCheckNodes.push(node);
}
function testInspectorUsage(context, node) {
if (utils.isRequired(node, ['inspector'])) {
missingCheckNodes.push(node);
}

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

function checkMemberExpression(context, node) {
if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) {
hasInspectorCheck = true;
function checkMemberExpression(context, node) {
if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) {
hasInspectorCheck = true;
}
}
}

function reportIfMissing(context) {
if (!hasInspectorCheck) {
missingCheckNodes.forEach((node) => {
context.report({
node,
message: msg,
fix: (fixer) => {
if (commonModuleNode) {
return fixer.insertTextAfter(
commonModuleNode,
'\ncommon.skipIfInspectorDisabled();'
);
function reportIfMissing(context) {
if (!hasInspectorCheck) {
missingCheckNodes.forEach((node) => {
context.report({
node,
message: msg,
fix: (fixer) => {
if (commonModuleNode) {
return fixer.insertTextAfter(
commonModuleNode,
'\ncommon.skipIfInspectorDisabled();'
);
}
}
}
});
});
});
}
}
}

return {
'CallExpression': (node) => testInspectorUsage(context, node),
'MemberExpression': (node) => checkMemberExpression(context, node),
'Program:exit': () => reportIfMissing(context)
};
};

module.exports.meta = {
fixable: 'code'
return {
'CallExpression': (node) => testInspectorUsage(context, node),
'MemberExpression': (node) => checkMemberExpression(context, node),
'Program:exit': () => reportIfMissing(context)
};
}
};
12 changes: 10 additions & 2 deletions tools/node_modules/@babel/core/lib/config/config-chain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/node_modules/@babel/core/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading