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-octal-escape.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @fileoverview Rule to flag octal escape sequences in string literals.
  3. * @author Ian Christian Myers
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow octal escape sequences in string literals",
  14. category: "Best Practices",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-octal-escape"
  17. },
  18. schema: []
  19. },
  20. create(context) {
  21. return {
  22. Literal(node) {
  23. if (typeof node.value !== "string") {
  24. return;
  25. }
  26. const match = node.raw.match(/^([^\\]|\\[^0-7])*\\([0-3][0-7]{1,2}|[4-7][0-7]|[0-7])/);
  27. if (match) {
  28. const octalDigit = match[2];
  29. // \0 is actually not considered an octal
  30. if (match[2] !== "0" || typeof match[3] !== "undefined") {
  31. context.report({ node, message: "Don't use octal: '\\{{octalDigit}}'. Use '\\u....' instead.", data: { octalDigit } });
  32. }
  33. }
  34. }
  35. };
  36. }
  37. };