Non base ten numerals are hard for humans to parse. This rule limits literals to only being base ten.
- Rule details
- Patterns considered warnings/errors
- Patterns not considered warnings/errors
- Installation
- Options
- When not to use it
Numeric literals, broadly, are easier to understand when they're not in octal, binary, or hex. There are situations where that might be useful, but in general, sticking to numbers people can read is the safer path.
Additionally, this rule can be used to deobfuscate a compiled JS file, like the ones coming out of https://obfuscator.io/ via the provided --fix method.
console.log(0x123);
const a = 0b1010;
const b = 0123;
const c = 0o123;
console.log(1);
const a = 32_000;
const b = 123n;
Install the pocket-fluff eslint plugin in your project.
# NPM
npm install eslint-plugin-pocket-fluff --dev
# Yarn
yarn add eslint-plugin-pocket-fluff --dev
Enable the plugin and the rule in your .eslintrc (or other config) file.
{
"plugins": ["pocket-fluff"],
"rules": {
"pocket-fluff/base-ten-numeric-literals": "error"
}
}
No options.
When you don't care about being able to read numbers, or are working with binary, hex, or octal values directly.