github-pages-deploy-action/node_modules/eslint/lib/rules/no-throw-literal.js

52 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2020-03-07 11:45:40 +08:00
/**
* @fileoverview Rule to restrict what can be thrown as an exception.
* @author Dieter Oberkofler
*/
"use strict";
2020-03-31 20:40:00 +08:00
const astUtils = require("./utils/ast-utils");
2020-03-07 11:45:40 +08:00
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "disallow throwing literals as exceptions",
category: "Best Practices",
recommended: false,
url: "https://eslint.org/docs/rules/no-throw-literal"
},
2020-03-31 20:40:00 +08:00
schema: [],
messages: {
object: "Expected an error object to be thrown.",
undef: "Do not throw undefined."
}
2020-03-07 11:45:40 +08:00
},
create(context) {
return {
ThrowStatement(node) {
if (!astUtils.couldBeError(node.argument)) {
2020-03-31 20:40:00 +08:00
context.report({ node, messageId: "object" });
2020-03-07 11:45:40 +08:00
} else if (node.argument.type === "Identifier") {
if (node.argument.name === "undefined") {
2020-03-31 20:40:00 +08:00
context.report({ node, messageId: "undef" });
2020-03-07 11:45:40 +08:00
}
}
}
};
}
};