]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-floating-decimal.js
2 * @fileoverview Rule to flag use of a leading/trailing decimal point in a numeric literal
3 * @author James Allardice
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const astUtils
= require("./utils/ast-utils");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
23 description
: "disallow leading or trailing decimal points in numeric literals",
25 url
: "https://eslint.org/docs/rules/no-floating-decimal"
31 leading
: "A leading decimal point can be confused with a dot.",
32 trailing
: "A trailing decimal point can be confused with a dot."
37 const sourceCode
= context
.getSourceCode();
42 if (typeof node
.value
=== "number") {
43 if (node
.raw
.startsWith(".")) {
48 const tokenBefore
= sourceCode
.getTokenBefore(node
);
49 const needsSpaceBefore
= tokenBefore
&&
50 tokenBefore
.range
[1] === node
.range
[0] &&
51 !astUtils
.canTokensBeAdjacent(tokenBefore
, `0${node.raw}`);
53 return fixer
.insertTextBefore(node
, needsSpaceBefore
? " 0" : "0");
57 if (node
.raw
.indexOf(".") === node
.raw
.length
- 1) {
60 messageId
: "trailing",
61 fix
: fixer
=> fixer
.insertTextAfter(node
, "0")