项目原始demo,不改动
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
Это архивный репозиторий. Вы можете его клонировать или просматривать файлы, но не вносить изменения или открывать задачи/запросы на слияние.
 
 
 
 

53 строки
1.4 KiB

  1. /**
  2. * @fileoverview A rule to disallow modifying variables that are declared using `const`
  3. * @author Toru Nagashima
  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 `const` variables",
  14. category: "ECMAScript 6",
  15. recommended: true,
  16. url: "https://eslint.org/docs/rules/no-const-assign"
  17. },
  18. schema: [],
  19. messages: {
  20. const: "'{{name}}' is constant."
  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: "const", data: { name: reference.identifier.name } });
  32. });
  33. }
  34. return {
  35. VariableDeclaration(node) {
  36. if (node.kind === "const") {
  37. context.getDeclaredVariables(node).forEach(checkVariable);
  38. }
  39. }
  40. };
  41. }
  42. };