pve-eslint/eslint/tests/lib/rules/no-empty-pattern.js
Dominik Csapak eb39fafa4f first commit
includes a (minimal) working wrapper

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-04-06 15:06:03 +02:00

117 lines
3.6 KiB
JavaScript

/**
* @fileoverview Tests for no-empty-pattern rule.
* @author Alberto Rodríguez
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-empty-pattern"),
{ RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("no-empty-pattern", rule, {
// Examples of code that should not trigger the rule
valid: [
{ code: "var {a = {}} = foo;", parserOptions: { ecmaVersion: 6 } },
{ code: "var {a, b = {}} = foo;", parserOptions: { ecmaVersion: 6 } },
{ code: "var {a = []} = foo;", parserOptions: { ecmaVersion: 6 } },
{ code: "function foo({a = {}}) {}", parserOptions: { ecmaVersion: 6 } },
{ code: "function foo({a = []}) {}", parserOptions: { ecmaVersion: 6 } },
{ code: "var [a] = foo", parserOptions: { ecmaVersion: 6 } }
],
// Examples of code that should trigger the rule
invalid: [
{
code: "var {} = foo",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "object" },
type: "ObjectPattern"
}]
},
{
code: "var [] = foo",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "array" },
type: "ArrayPattern"
}]
},
{
code: "var {a: {}} = foo",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "object" },
type: "ObjectPattern"
}]
},
{
code: "var {a, b: {}} = foo",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "object" },
type: "ObjectPattern"
}]
},
{
code: "var {a: []} = foo",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "array" },
type: "ArrayPattern"
}]
},
{
code: "function foo({}) {}",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "object" },
type: "ObjectPattern"
}]
},
{
code: "function foo([]) {}",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "array" },
type: "ArrayPattern"
}]
},
{
code: "function foo({a: {}}) {}",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "object" },
type: "ObjectPattern"
}]
},
{
code: "function foo({a: []}) {}",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { type: "array" },
type: "ArrayPattern"
}]
}
]
});