mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-08-23 19:15:10 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
83 lines
3.0 KiB
JavaScript
83 lines
3.0 KiB
JavaScript
/**
|
|
* @fileoverview Tests for no-case-declarations rule.
|
|
* @author Erik Arvidsson
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/no-case-declarations"),
|
|
{ RuleTester } = require("../../../lib/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester();
|
|
|
|
ruleTester.run("no-case-declarations", rule, {
|
|
valid: [
|
|
{
|
|
code: "switch (a) { case 1: { let x = 1; break; } default: { let x = 2; break; } }",
|
|
parserOptions: { ecmaVersion: 6 }
|
|
},
|
|
{
|
|
code: "switch (a) { case 1: { const x = 1; break; } default: { const x = 2; break; } }",
|
|
parserOptions: { ecmaVersion: 6 }
|
|
},
|
|
{
|
|
code: "switch (a) { case 1: { function f() {} break; } default: { function f() {} break; } }",
|
|
parserOptions: { ecmaVersion: 6 }
|
|
},
|
|
{
|
|
code: "switch (a) { case 1: { class C {} break; } default: { class C {} break; } }",
|
|
parserOptions: { ecmaVersion: 6 }
|
|
}
|
|
],
|
|
invalid: [
|
|
{
|
|
code: "switch (a) { case 1: let x = 1; break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "VariableDeclaration" }]
|
|
},
|
|
{
|
|
code: "switch (a) { default: let x = 2; break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "VariableDeclaration" }]
|
|
},
|
|
{
|
|
code: "switch (a) { case 1: const x = 1; break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "VariableDeclaration" }]
|
|
},
|
|
{
|
|
code: "switch (a) { default: const x = 2; break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "VariableDeclaration" }]
|
|
},
|
|
{
|
|
code: "switch (a) { case 1: function f() {} break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }]
|
|
},
|
|
{
|
|
code: "switch (a) { default: function f() {} break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }]
|
|
},
|
|
{
|
|
code: "switch (a) { case 1: class C {} break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "ClassDeclaration" }]
|
|
},
|
|
{
|
|
code: "switch (a) { default: class C {} break; }",
|
|
parserOptions: { ecmaVersion: 6 },
|
|
errors: [{ messageId: "unexpected", type: "ClassDeclaration" }]
|
|
}
|
|
]
|
|
});
|