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