Skip to content

octalNumbers

Reports using legacy octal numeric literals.

✅ This rule is included in the ts untyped presets.

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.

const
const permissions: 493
permissions
= 0755; // Evaluates to 493, not 755!
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o755'.
const
const value: 63
value
= 077; // Evaluates to 63, not 77!
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o77'.
const
const numbers: number[]
numbers
= [01, 02, 03, 04, 05, 06, 07];
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o1'.
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o2'.
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o3'.
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o4'.
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o5'.
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o6'.
Error ts(1121) ― Octal literals are not allowed. Use the syntax '0o7'.

This rule is not configurable.

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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.