Skip to content

Latest commit

Β 

History

History
79 lines (57 loc) Β· 1.58 KB

no-zero-fractions.md

File metadata and controls

79 lines (57 loc) Β· 1.58 KB

no-zero-fractions

πŸ“ Require consistent decimal numbers without redundant zeros.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, 🎨 recommended-css, 🧩 recommended-json, πŸ’Ž recommended-soml, πŸ› οΈ recommended-toml, πŸ“‹ recommended-yaml, β˜‘οΈ unopinionated.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

Use a leading zero before the decimal point, and remove redundant trailing fractional zeros and dangling decimal points. For example, prefer 0.5 over .5, 1.5 over 1.50, and 1 over 1.0 or 1..

The rule also supports JSON, JSONC, JSON5, SOML, TOML, YAML, and CSS. It preserves CSS units (2.0px β†’ 2px, .5s β†’ 0.5s) and SOML/TOML/YAML float types (1.00 β†’ 1.0). Tagged YAML scalars, strings, .inf, and .nan are skipped.

Examples

// ❌
const foo = 1.0;

// ❌
const foo = 1.;

// βœ…
const foo = 1;
// ❌
const foo = -1.0;

// βœ…
const foo = -1;
// ❌
const foo = 123_456.000_000;

// βœ…
const foo = 123_456;
// ❌
const foo = 123.111000000;

// βœ…
const foo = 123.111;
// ❌
const foo = 123.00e20;

// βœ…
const foo = 123e20;
// βœ…
const foo = 1.1;
// βœ…
const foo = -1.1;
// βœ…
const foo = 123.456;
// βœ…
const foo = 1e3;