no-octal.js 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @fileoverview Rule to flag when initializing octal literal
  3. * @author Ilya Volodin
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "suggestion",
  12. docs: {
  13. description: "disallow octal literals",
  14. category: "Best Practices",
  15. recommended: true,
  16. url: "https://eslint.org/docs/rules/no-octal"
  17. },
  18. schema: [],
  19. messages: {
  20. noOcatal: "Octal literals should not be used."
  21. }
  22. },
  23. create(context) {
  24. return {
  25. Literal(node) {
  26. if (typeof node.value === "number" && /^0[0-9]/u.test(node.raw)) {
  27. context.report({
  28. node,
  29. messageId: "noOcatal"
  30. });
  31. }
  32. }
  33. };
  34. }
  35. };