|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @fileoverview Rule to restrict what can be thrown as an exception.
|
|---|
| 3 | * @author Dieter Oberkofler
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const astUtils = require("./utils/ast-utils");
|
|---|
| 9 |
|
|---|
| 10 | //------------------------------------------------------------------------------
|
|---|
| 11 | // Rule Definition
|
|---|
| 12 | //------------------------------------------------------------------------------
|
|---|
| 13 |
|
|---|
| 14 | /** @type {import('../shared/types').Rule} */
|
|---|
| 15 | module.exports = {
|
|---|
| 16 | meta: {
|
|---|
| 17 | type: "suggestion",
|
|---|
| 18 |
|
|---|
| 19 | docs: {
|
|---|
| 20 | description: "Disallow throwing literals as exceptions",
|
|---|
| 21 | recommended: false,
|
|---|
| 22 | url: "https://eslint.org/docs/latest/rules/no-throw-literal"
|
|---|
| 23 | },
|
|---|
| 24 |
|
|---|
| 25 | schema: [],
|
|---|
| 26 |
|
|---|
| 27 | messages: {
|
|---|
| 28 | object: "Expected an error object to be thrown.",
|
|---|
| 29 | undef: "Do not throw undefined."
|
|---|
| 30 | }
|
|---|
| 31 | },
|
|---|
| 32 |
|
|---|
| 33 | create(context) {
|
|---|
| 34 |
|
|---|
| 35 | return {
|
|---|
| 36 |
|
|---|
| 37 | ThrowStatement(node) {
|
|---|
| 38 | if (!astUtils.couldBeError(node.argument)) {
|
|---|
| 39 | context.report({ node, messageId: "object" });
|
|---|
| 40 | } else if (node.argument.type === "Identifier") {
|
|---|
| 41 | if (node.argument.name === "undefined") {
|
|---|
| 42 | context.report({ node, messageId: "undef" });
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | }
|
|---|
| 51 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.