blob: 99ea3a7905b6a8cfda72f8f999be2719c702999a [file] [log] [blame]
Yang Guo4fd355c2019-09-19 10:59:03 +02001/**
2 * @fileoverview Rule to disallow an empty pattern
3 * @author Alberto Rodríguez
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = {
12 meta: {
13 type: "problem",
14
15 docs: {
16 description: "disallow empty destructuring patterns",
Yang Guo4fd355c2019-09-19 10:59:03 +020017 recommended: true,
18 url: "https://eslint.org/docs/rules/no-empty-pattern"
19 },
20
21 schema: [],
22
23 messages: {
24 unexpected: "Unexpected empty {{type}} pattern."
25 }
26 },
27
28 create(context) {
29 return {
30 ObjectPattern(node) {
31 if (node.properties.length === 0) {
32 context.report({ node, messageId: "unexpected", data: { type: "object" } });
33 }
34 },
35 ArrayPattern(node) {
36 if (node.elements.length === 0) {
37 context.report({ node, messageId: "unexpected", data: { type: "array" } });
38 }
39 }
40 };
41 }
42};