no-octal.js 856 B

123456789101112131415161718192021222324252627282930313233343536
  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. docs: {
  12. description: "disallow octal literals",
  13. category: "Best Practices",
  14. recommended: true,
  15. url: "https://eslint.org/docs/rules/no-octal"
  16. },
  17. schema: []
  18. },
  19. create(context) {
  20. return {
  21. Literal(node) {
  22. if (typeof node.value === "number" && /^0[0-7]/.test(node.raw)) {
  23. context.report({ node, message: "Octal literals should not be used." });
  24. }
  25. }
  26. };
  27. }
  28. };