|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @fileoverview Disallow sparse arrays
|
|---|
| 3 | * @author Nicholas C. Zakas
|
|---|
| 4 | */
|
|---|
| 5 | "use strict";
|
|---|
| 6 |
|
|---|
| 7 | //------------------------------------------------------------------------------
|
|---|
| 8 | // Rule Definition
|
|---|
| 9 | //------------------------------------------------------------------------------
|
|---|
| 10 |
|
|---|
| 11 | /** @type {import('../shared/types').Rule} */
|
|---|
| 12 | module.exports = {
|
|---|
| 13 | meta: {
|
|---|
| 14 | type: "problem",
|
|---|
| 15 |
|
|---|
| 16 | docs: {
|
|---|
| 17 | description: "Disallow sparse arrays",
|
|---|
| 18 | recommended: true,
|
|---|
| 19 | url: "https://eslint.org/docs/latest/rules/no-sparse-arrays"
|
|---|
| 20 | },
|
|---|
| 21 |
|
|---|
| 22 | schema: [],
|
|---|
| 23 |
|
|---|
| 24 | messages: {
|
|---|
| 25 | unexpectedSparseArray: "Unexpected comma in middle of array."
|
|---|
| 26 | }
|
|---|
| 27 | },
|
|---|
| 28 |
|
|---|
| 29 | create(context) {
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | //--------------------------------------------------------------------------
|
|---|
| 33 | // Public
|
|---|
| 34 | //--------------------------------------------------------------------------
|
|---|
| 35 |
|
|---|
| 36 | return {
|
|---|
| 37 |
|
|---|
| 38 | ArrayExpression(node) {
|
|---|
| 39 |
|
|---|
| 40 | const emptySpot = node.elements.includes(null);
|
|---|
| 41 |
|
|---|
| 42 | if (emptySpot) {
|
|---|
| 43 | context.report({ node, messageId: "unexpectedSparseArray" });
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| 49 | }
|
|---|
| 50 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.