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: fix custom eslint rule errors #18853

Closed
wants to merge 1 commit into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions tools/eslint-rules/alphabetize-errors.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
'use strict';

const { isDefiningError } = require('./rules-utils.js');

const prefix = 'Out of ASCIIbetical order - ';
const opStr = ' >= ';

function errorForNode(node) {
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 = {
create: function(context) {
let previousNode;
Expand Down
10 changes: 2 additions & 8 deletions tools/eslint-rules/documented-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs');
const path = require('path');
const { isDefiningError } = require('./rules-utils.js');

const doc = fs.readFileSync(path.resolve(__dirname, '../../doc/api/errors.md'),
'utf8');
Expand All @@ -18,18 +19,11 @@ function errorForNode(node) {
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 = {
create: function(context) {
return {
ExpressionStatement: function(node) {
if (!isDefiningError(node)) return;
if (!isDefiningError(node) || !errorForNode(node)) return;
const code = errorForNode(node);
if (!isInDoc(code)) {
const message = `"${code}" is not documented in doc/api/errors.md`;
Expand Down
11 changes: 3 additions & 8 deletions tools/eslint-rules/prefer-util-format-errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { isDefiningError } = require('./rules-utils.js');

const errMsg = 'Please use a printf-like formatted string that util.format' +
' can consume.';

Expand All @@ -8,18 +10,11 @@ function isArrowFunctionWithTemplateLiteral(node) {
node.body.type === 'TemplateLiteral';
}

function isDefiningError(node) {
return node.expression &&
node.expression.type === 'CallExpression' &&
node.expression.callee &&
node.expression.callee.name === 'E';
}

module.exports = {
create: function(context) {
return {
ExpressionStatement: function(node) {
if (!isDefiningError(node))
if (!isDefiningError(node) || node.expression.arguments.length < 2)
return;

const msg = node.expression.arguments[1];
Expand Down
8 changes: 8 additions & 0 deletions tools/eslint-rules/rules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
*/
'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
* require calls.
Expand Down