mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
107 lines
1.9 KiB
JavaScript
107 lines
1.9 KiB
JavaScript
/**
|
|
* @fileoverview Disallow sparse arrays
|
|
* @author Nicholas C. Zakas
|
|
*/
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/no-sparse-arrays"),
|
|
RuleTester = require("../../../lib/rule-tester/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester();
|
|
|
|
ruleTester.run("no-sparse-arrays", rule, {
|
|
valid: ["var a = [ 1, 2, ]"],
|
|
|
|
invalid: [
|
|
{
|
|
code: "var a = [,];",
|
|
errors: [
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 1,
|
|
column: 10,
|
|
endLine: 1,
|
|
endColumn: 11,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "var a = [ 1,, 2];",
|
|
errors: [
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 1,
|
|
column: 13,
|
|
endLine: 1,
|
|
endColumn: 14,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "[\r\n\t/* comment */,\n// comment\n ,];",
|
|
errors: [
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 2,
|
|
column: 15,
|
|
endLine: 2,
|
|
endColumn: 16,
|
|
},
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 4,
|
|
column: 2,
|
|
endLine: 4,
|
|
endColumn: 3,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "[(( [a,] )),,,];",
|
|
errors: [
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 1,
|
|
column: 13,
|
|
endLine: 1,
|
|
endColumn: 14,
|
|
},
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 1,
|
|
column: 14,
|
|
endLine: 1,
|
|
endColumn: 15,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "[,(( [a,] )),,];",
|
|
errors: [
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 1,
|
|
column: 2,
|
|
endLine: 1,
|
|
endColumn: 3,
|
|
},
|
|
{
|
|
messageId: "unexpectedSparseArray",
|
|
line: 1,
|
|
column: 14,
|
|
endLine: 1,
|
|
endColumn: 15,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|