{"record":{"id":"7a0178265b532961","repo":"oxc-project/oxc","slug":"don-t-use-a-zero-fraction-in-the-number","errorCode":null,"errorMessage":"Don't use a zero fraction in the number.","messagePattern":"Don't use a zero fraction in the number\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs","lineNumber":10,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::identifier::is_identifier_part;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn zero_fraction(span: Span, lit: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Don't use a zero fraction in the number.\")\n        .with_help(format!(\"Replace the number literal with `{lit}`\"))\n        .with_label(span)\n}\n\nfn dangling_dot(span: Span, lit: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Don't use a dangling dot in the number.\")\n        .with_help(format!(\"Replace the number literal with `{lit}`\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoZeroFractions;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prevents the use of zero fractions.\n    ///","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs#L1-L28","documentation":"Diagnostic from the oxlint rule `unicorn/no-zero-fractions` (style, autofixable). It fires on a numeric literal whose fractional part is all zeros, such as `1.0`, `1.00000`, `-1.0`, `123.11100000000` (trailing zeros), or the leading-dot form `.0`. `1`, `1.0`, and `1.` are the same number in JavaScript, so the zeros add noise. The fixer replaces the literal (wrapping it in parentheses before member access like `1.00.toFixed(2)` -> `(1).toFixed(2)`, and inserting a space after keywords like `return.0` -> `return 0`).","triggerScenarios":"`const foo = 1.0`, `const foo = -1.0`, `const foo = 1.00`, `const foo = 123.11100000000`, `a = .0;`, `1.00e10`, `1.00.toFixed(2)`, `function foo(){return.0}`. Not fired for string literals (`'123.1000'`), non-zero fractions (`1.1`), or plain integers.","commonSituations":"Code ported from languages where `1.0` marks float type (Python, C), CSV/config values pasted as floats, and scientific constants. Appears when the oxlint style category is enabled.","solutions":["Drop the zero fraction: `const foo = 1.0;` -> `const foo = 1;`, `123.11100000000` -> `123.111`, `.0` -> `0`.","Run `oxlint --fix`; the fixer handles the `(1).toFixed(2)` and `return 0` spacing edge cases.","If you want to signal 'this is a float', use a comment or type annotation instead of `.0`.","Keep the literal and disable inline only if a parser/format downstream requires the trailing zeros (none exist in standard JS)."],"exampleFix":"// before\nconst foo = 1.0;\nconst bar = 123.11100000000;\nconst baz = .0;\n\n// after\nconst foo = 1;\nconst bar = 123.111;\nconst baz = 0;","handlingStrategy":"validation","validationCode":"# detect all-zero fractions and leading-dot zeros\nrg -n --type js '(?:\\.0+\\b|\\b\\d+\\.0+(?!\\d))' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write integers without fractional suffix; JS has no int/float literal distinction.","Run `oxlint --fix` in pre-commit so literals are normalized automatically (including `.toFixed` paren cases).","When porting float-style code from other languages, strip `.0` in the same change."],"tags":["lint","oxlint","unicorn","number-literal","style","autofix"],"backgroundTag":"zero-fraction-number-literal","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}