main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[d565449] | 1 | /**
|
---|
| 2 | * @fileoverview Rule to flag assignment of the exception parameter
|
---|
| 3 | * @author Stephen Murray <spmurrayzzz>
|
---|
| 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: "problem",
|
---|
| 18 |
|
---|
| 19 | docs: {
|
---|
| 20 | description: "Disallow reassigning exceptions in `catch` clauses",
|
---|
| 21 | recommended: true,
|
---|
| 22 | url: "https://eslint.org/docs/latest/rules/no-ex-assign"
|
---|
| 23 | },
|
---|
| 24 |
|
---|
| 25 | schema: [],
|
---|
| 26 |
|
---|
| 27 | messages: {
|
---|
| 28 | unexpected: "Do not assign to the exception parameter."
|
---|
| 29 | }
|
---|
| 30 | },
|
---|
| 31 |
|
---|
| 32 | create(context) {
|
---|
| 33 |
|
---|
| 34 | const sourceCode = context.sourceCode;
|
---|
| 35 |
|
---|
| 36 | /**
|
---|
| 37 | * Finds and reports references that are non initializer and writable.
|
---|
| 38 | * @param {Variable} variable A variable to check.
|
---|
| 39 | * @returns {void}
|
---|
| 40 | */
|
---|
| 41 | function checkVariable(variable) {
|
---|
| 42 | astUtils.getModifyingReferences(variable.references).forEach(reference => {
|
---|
| 43 | context.report({ node: reference.identifier, messageId: "unexpected" });
|
---|
| 44 | });
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | return {
|
---|
| 48 | CatchClause(node) {
|
---|
| 49 | sourceCode.getDeclaredVariables(node).forEach(checkVariable);
|
---|
| 50 | }
|
---|
| 51 | };
|
---|
| 52 |
|
---|
| 53 | }
|
---|
| 54 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.