1 | /**
|
2 | * @fileoverview Rule to disallow an empty pattern
|
3 | * @author Alberto Rodríguez
|
4 | */
|
5 | ;
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Rule Definition
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | module.exports = {
|
12 | meta: {
|
13 | docs: {
|
14 | description: "disallow empty destructuring patterns",
|
15 | category: "Best Practices",
|
16 | recommended: true
|
17 | },
|
18 |
|
19 | schema: []
|
20 | },
|
21 |
|
22 | create(context) {
|
23 | return {
|
24 | ObjectPattern(node) {
|
25 | if (node.properties.length === 0) {
|
26 | context.report(node, "Unexpected empty object pattern.");
|
27 | }
|
28 | },
|
29 | ArrayPattern(node) {
|
30 | if (node.elements.length === 0) {
|
31 | context.report(node, "Unexpected empty array pattern.");
|
32 | }
|
33 | }
|
34 | };
|
35 | }
|
36 | };
|