UNPKG

657 BJavaScriptView Raw
1'use strict';
2const getDocumentationUrl = require('./utils/get-documentation-url');
3
4const message = 'Array destructuring may not contain consecutive ignored values.';
5const isCommaFollowedWithComma = (element, index, array) =>
6 element === null && array[index + 1] === null;
7
8const create = context => {
9 return {
10 'ArrayPattern[elements.length>=3]': node => {
11 if (node.elements.some((element, index, array) => isCommaFollowedWithComma(element, index, array))) {
12 context.report({
13 node,
14 message
15 });
16 }
17 }
18 };
19};
20
21module.exports = {
22 create,
23 meta: {
24 type: 'suggestion',
25 docs: {
26 url: getDocumentationUrl(__filename)
27 }
28 }
29};