tools: fix custom eslint rule errors
This fixes a few rules by making sure the input is actually ready to be checked. Otherwise those can throw TypeErrors or result in faulty error messages. PR-URL: https://github.com/nodejs/node/pull/18853 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
20dae8540b
commit
7107c9201d
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { isDefiningError } = require('./rules-utils.js');
|
||||||
|
|
||||||
const prefix = 'Out of ASCIIbetical order - ';
|
const prefix = 'Out of ASCIIbetical order - ';
|
||||||
const opStr = ' >= ';
|
const opStr = ' >= ';
|
||||||
|
|
||||||
@ -7,13 +9,6 @@ function errorForNode(node) {
|
|||||||
return node.expression.arguments[0].value;
|
return node.expression.arguments[0].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDefiningError(node) {
|
|
||||||
return node.expression &&
|
|
||||||
node.expression.type === 'CallExpression' &&
|
|
||||||
node.expression.callee &&
|
|
||||||
node.expression.callee.name === 'E';
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create: function(context) {
|
create: function(context) {
|
||||||
let previousNode;
|
let previousNode;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { isDefiningError } = require('./rules-utils.js');
|
||||||
|
|
||||||
const doc = fs.readFileSync(path.resolve(__dirname, '../../doc/api/errors.md'),
|
const doc = fs.readFileSync(path.resolve(__dirname, '../../doc/api/errors.md'),
|
||||||
'utf8');
|
'utf8');
|
||||||
@ -18,18 +19,11 @@ function errorForNode(node) {
|
|||||||
return node.expression.arguments[0].value;
|
return node.expression.arguments[0].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDefiningError(node) {
|
|
||||||
return node.expression &&
|
|
||||||
node.expression.type === 'CallExpression' &&
|
|
||||||
node.expression.callee &&
|
|
||||||
node.expression.callee.name === 'E';
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create: function(context) {
|
create: function(context) {
|
||||||
return {
|
return {
|
||||||
ExpressionStatement: function(node) {
|
ExpressionStatement: function(node) {
|
||||||
if (!isDefiningError(node)) return;
|
if (!isDefiningError(node) || !errorForNode(node)) return;
|
||||||
const code = errorForNode(node);
|
const code = errorForNode(node);
|
||||||
if (!isInDoc(code)) {
|
if (!isInDoc(code)) {
|
||||||
const message = `"${code}" is not documented in doc/api/errors.md`;
|
const message = `"${code}" is not documented in doc/api/errors.md`;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { isDefiningError } = require('./rules-utils.js');
|
||||||
|
|
||||||
const errMsg = 'Please use a printf-like formatted string that util.format' +
|
const errMsg = 'Please use a printf-like formatted string that util.format' +
|
||||||
' can consume.';
|
' can consume.';
|
||||||
|
|
||||||
@ -8,18 +10,11 @@ function isArrowFunctionWithTemplateLiteral(node) {
|
|||||||
node.body.type === 'TemplateLiteral';
|
node.body.type === 'TemplateLiteral';
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDefiningError(node) {
|
|
||||||
return node.expression &&
|
|
||||||
node.expression.type === 'CallExpression' &&
|
|
||||||
node.expression.callee &&
|
|
||||||
node.expression.callee.name === 'E';
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create: function(context) {
|
create: function(context) {
|
||||||
return {
|
return {
|
||||||
ExpressionStatement: function(node) {
|
ExpressionStatement: function(node) {
|
||||||
if (!isDefiningError(node))
|
if (!isDefiningError(node) || node.expression.arguments.length < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const msg = node.expression.arguments[1];
|
const msg = node.expression.arguments[1];
|
||||||
|
@ -3,6 +3,14 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
module.exports.isDefiningError = function(node) {
|
||||||
|
return node.expression &&
|
||||||
|
node.expression.type === 'CallExpression' &&
|
||||||
|
node.expression.callee &&
|
||||||
|
node.expression.callee.name === 'E' &&
|
||||||
|
node.expression.arguments.length !== 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if any of the passed in modules are used in
|
* Returns true if any of the passed in modules are used in
|
||||||
* require calls.
|
* require calls.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user