]>
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 | ||
34eeec05 | 11 | /** @type {import('../shared/types').Rule} */ |
eb39fafa DC |
12 | module.exports = { |
13 | meta: { | |
14 | type: "problem", | |
15 | ||
16 | docs: { | |
8f9d1d4d | 17 | description: "Disallow empty destructuring patterns", |
eb39fafa | 18 | recommended: true, |
f2a92ac6 | 19 | url: "https://eslint.org/docs/latest/rules/no-empty-pattern" |
eb39fafa DC |
20 | }, |
21 | ||
22 | schema: [], | |
23 | ||
24 | messages: { | |
25 | unexpected: "Unexpected empty {{type}} pattern." | |
26 | } | |
27 | }, | |
28 | ||
29 | create(context) { | |
30 | return { | |
31 | ObjectPattern(node) { | |
32 | if (node.properties.length === 0) { | |
33 | context.report({ node, messageId: "unexpected", data: { type: "object" } }); | |
34 | } | |
35 | }, | |
36 | ArrayPattern(node) { | |
37 | if (node.elements.length === 0) { | |
38 | context.report({ node, messageId: "unexpected", data: { type: "array" } }); | |
39 | } | |
40 | } | |
41 | }; | |
42 | } | |
43 | }; |