{"record":{"id":"e407367f06205057","repo":"oxc-project/oxc","slug":"don-t-use-a-dangling-dot-in-the-number","errorCode":null,"errorMessage":"Don't use a dangling dot in the number.","messagePattern":"Don't use a dangling dot in the number\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs","lineNumber":16,"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    ///\n    /// ### Why is this bad?\n    ///\n    /// There is no difference in JavaScript between, for example, `1`, `1.0` and `1.`, so prefer the former for consistency and brevity.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs#L1-L34","documentation":"Diagnostic from the oxlint rule `unicorn/no-zero-fractions` (style, autofixable). This variant (`dangling_dot`) fires on a numeric literal that ends with a bare decimal point: `1.`, `+1.`, `-1.`, `0.`, and scientific forms like `1.e10` or `-1.e+10`. The dangling dot is valid JavaScript but adds nothing over `1`, so the rule flags it for consistency. The fixer removes the dot (and rewrites `1.e10` to `1e10`), adding parentheses or spaces where token boundaries require them.","triggerScenarios":"`const foo = 1.;`, `const foo = -1.;`, `const foo = 1.e10;`, `const foo = +1.e-10;`, `(1.).toString()`, `Test(0.)`. Not fired for normal fractions (`1.1`), strings containing `'1.'`, or integers.","commonSituations":"Typing shortcuts and minified/hand-trimmed code, or numbers edited down from `1.0`. Appears with the oxlint style category enabled.","solutions":["Remove the dangling dot: `const foo = 1.;` -> `const foo = 1;`, `1.e10` -> `1e10`.","Run `oxlint --fix` to apply the safe rewrite, including member-access cases like `(1.).toString()` -> `(1).toString()`.","Add the missing digits if you actually meant a fraction (`1.5`).","Disable inline for generated code where the form is not under your control."],"exampleFix":"// before\nconst foo = 1.;\nconst bar = -1.e+10;\n\n// after\nconst foo = 1;\nconst bar = -1e+10;","handlingStrategy":"validation","validationCode":"# detect dangling-dot number literals\nrg -n --type js '\\d\\.\\s*(?:[,;)]|$|\\.|e|E)' src/ | rg -v '\\d\\.\\d'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write at least one digit after a decimal point, or drop the point entirely.","Enable format-on-save with oxfmt/Prettier plus oxlint --fix to catch typos like `1.`.","Review literals after hand-trimming numbers (for example `1.50` -> `1.5`, never `1.`)."],"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"}