]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Rule to disallow an empty pattern | |
3 | * @author Alberto RodrÃguez | |
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 empty destructuring patterns", | |
eb39fafa DC |
17 | 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 | }; |