Blame view
node_modules/eslint/lib/rules/no-floating-decimal.js
1.45 KB
f7563de62
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/** * @fileoverview Rule to flag use of a leading/trailing decimal point in a numeric literal * @author James Allardice */ "use strict"; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ module.exports = { meta: { docs: { description: "disallow leading or trailing decimal points in numeric literals", category: "Best Practices", recommended: false }, schema: [], fixable: "code" }, create(context) { return { Literal(node) { if (typeof node.value === "number") { if (node.raw.indexOf(".") === 0) { context.report({ node, message: "A leading decimal point can be confused with a dot.", fix: fixer => fixer.insertTextBefore(node, "0") }); } if (node.raw.indexOf(".") === node.raw.length - 1) { context.report({ node, message: "A trailing decimal point can be confused with a dot.", fix: fixer => fixer.insertTextAfter(node, "0") }); } } } }; } }; |