mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
/**
|
|
* @fileoverview Tests for no-floating-decimal rule.
|
|
* @author James Allardice
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/no-floating-decimal"),
|
|
RuleTester = require("../../../lib/rule-tester/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester();
|
|
const leadingError = {
|
|
messageId: "leading",
|
|
};
|
|
const trailingError = {
|
|
messageId: "trailing",
|
|
};
|
|
|
|
ruleTester.run("no-floating-decimal", rule, {
|
|
valid: ["var x = 2.5;", 'var x = "2.5";'],
|
|
invalid: [
|
|
{
|
|
code: "var x = .5;",
|
|
output: "var x = 0.5;",
|
|
errors: [leadingError],
|
|
},
|
|
{
|
|
code: "var x = -.5;",
|
|
output: "var x = -0.5;",
|
|
errors: [leadingError],
|
|
},
|
|
{
|
|
code: "var x = 2.;",
|
|
output: "var x = 2.0;",
|
|
errors: [trailingError],
|
|
},
|
|
{
|
|
code: "var x = -2.;",
|
|
output: "var x = -2.0;",
|
|
errors: [trailingError],
|
|
},
|
|
{
|
|
code: "typeof.2",
|
|
output: "typeof 0.2",
|
|
errors: [leadingError],
|
|
},
|
|
{
|
|
code: "for(foo of.2);",
|
|
output: "for(foo of 0.2);",
|
|
languageOptions: { ecmaVersion: 2015 },
|
|
errors: [leadingError],
|
|
},
|
|
],
|
|
});
|