Ohm-Management - Projektarbeit B-ME
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.

no-shadow-restricted-names.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @fileoverview Disallow shadowing of NaN, undefined, and Infinity (ES5 section 15.1.1)
  3. * @author Michael Ficarra
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow identifiers from shadowing restricted names",
  14. category: "Variables",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-shadow-restricted-names"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. const RESTRICTED = ["undefined", "NaN", "Infinity", "arguments", "eval"];
  22. return {
  23. "VariableDeclaration, :function, CatchClause"(node) {
  24. for (const variable of context.getDeclaredVariables(node)) {
  25. if (variable.defs.length > 0 && RESTRICTED.includes(variable.name)) {
  26. context.report({
  27. node: variable.defs[0].name,
  28. message: "Shadowing of global property '{{idName}}'.",
  29. data: {
  30. idName: variable.name
  31. }
  32. });
  33. }
  34. }
  35. }
  36. };
  37. }
  38. };