octalNumbers
Reports using legacy octal numeric literals.
✅ This rule is included in the ts untyped
preset.
Legacy octal numeric literals (e.g., 077
, 0123
) are a deprecated feature in JavaScript that can lead to confusion and errors.
They are forbidden in strict mode and are less readable than their modern alternatives.
The explicit octal syntax 0o
(e.g., 0o77
) introduced in ES6 is clearer and works in both strict and non-strict modes.
The digit 0
by itself is allowed as it represents zero, not an octal literal.
This rule reports on numeric literals with a preceding 0
.
Examples
Section titled “Examples”const permissions = 0755; // Evaluates to 493, not 755!const value = 077; // Evaluates to 63, not 77!const numbers = [01, 02, 03, 04, 05, 06, 07];
// Use explicit octal syntax if you intended octalconst permissions = 0o755; // Clearly octal: 493 in decimalconst value = 0o77; // Clearly octal: 63 in decimalconst numbers = [0o1, 0o2, 0o3, 0o4, 0o5, 0o6, 0o7];
// Or use decimal if you meant the decimal valueconst permissions = 755; // Clearly decimalconst value = 77; // Clearly decimal
// The number zero is allowedconst zero = 0;
// Other number formats are allowedconst decimal = 123;const hex = 0xff;const binary = 0b1010;
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you need to maintain compatibility with very old JavaScript engines that don’t support the explicit octal syntax (ES6+), you might choose to disable this rule. However, this is extremely rare in modern development, as ES6 has been widely supported since 2015.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-octal