项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @fileoverview Rule to flag assignment of the exception parameter
  3. * @author Stephen Murray <spmurrayzzz>
  4. */
  5. "use strict";
  6. const astUtils = require("../ast-utils");
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. docs: {
  13. description: "disallow reassigning exceptions in `catch` clauses",
  14. category: "Possible Errors",
  15. recommended: true,
  16. url: "https://eslint.org/docs/rules/no-ex-assign"
  17. },
  18. schema: [],
  19. messages: {
  20. unexpected: "Do not assign to the exception parameter."
  21. }
  22. },
  23. create(context) {
  24. /**
  25. * Finds and reports references that are non initializer and writable.
  26. * @param {Variable} variable - A variable to check.
  27. * @returns {void}
  28. */
  29. function checkVariable(variable) {
  30. astUtils.getModifyingReferences(variable.references).forEach(reference => {
  31. context.report({ node: reference.identifier, messageId: "unexpected" });
  32. });
  33. }
  34. return {
  35. CatchClause(node) {
  36. context.getDeclaredVariables(node).forEach(checkVariable);
  37. }
  38. };
  39. }
  40. };