UNPKG

1.07 kBJavaScriptView Raw
1/**
2 * @fileoverview Disallow sparse arrays
3 * @author Nicholas C. Zakas
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = {
12 meta: {
13 docs: {
14 description: "disallow sparse arrays",
15 category: "Possible Errors",
16 recommended: true,
17 url: "https://eslint.org/docs/rules/no-sparse-arrays"
18 },
19
20 schema: []
21 },
22
23 create(context) {
24
25
26 //--------------------------------------------------------------------------
27 // Public
28 //--------------------------------------------------------------------------
29
30 return {
31
32 ArrayExpression(node) {
33
34 const emptySpot = node.elements.indexOf(null) > -1;
35
36 if (emptySpot) {
37 context.report({ node, message: "Unexpected comma in middle of array." });
38 }
39 }
40
41 };
42
43 }
44};