no-octal.js 832 B

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