aboutsummaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/no-floating-decimal.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/rules/no-floating-decimal.js')
-rw-r--r--tools/eslint/lib/rules/no-floating-decimal.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/no-floating-decimal.js b/tools/eslint/lib/rules/no-floating-decimal.js
new file mode 100644
index 0000000000..c6380d5460
--- /dev/null
+++ b/tools/eslint/lib/rules/no-floating-decimal.js
@@ -0,0 +1,28 @@
+/**
+ * @fileoverview Rule to flag use of a leading/trailing decimal point in a numeric literal
+ * @author James Allardice
+ */
+
+"use strict";
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = function(context) {
+
+ return {
+ "Literal": function(node) {
+
+ if (typeof node.value === "number") {
+ if (node.raw.indexOf(".") === 0) {
+ context.report(node, "A leading decimal point can be confused with a dot.");
+ }
+ if (node.raw.indexOf(".") === node.raw.length - 1) {
+ context.report(node, "A trailing decimal point can be confused with a dot.");
+ }
+ }
+ }
+ };
+
+};