Repository: eslint/eslint
File: tests/lib/rules/no-case-declarations.js (JavaScript)

Code before:
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 }
        },
        {
            code: `
                switch (a) { 
                    case 1: 
                    case 2: {} 
                }
            `,
            parserOptions: { ecmaVersion: 6 }
        },
        {
            code: `
                switch (a) {
                    case 1: var x; 
                }
            `,
            parserOptions: { ecmaVersion: 6 }
        }
    ],
    invalid: [
        {
            code: `
                switch (a) { 
                    case 1: 
                        {} 
                        function f() {} 
                        break; 
                }
            `,
            parserOptions: { ecmaVersion: 6 },
            errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }]
        },
        {
            code: `

Review comment (suggestion):
Just noting, in case it wasn't clear, that `parserOptions` is not required here, since no ES6 features are being used.

Code after:
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 }
        },
        `
                switch (a) { 
                    case 1: 
                    case 2: {} 
                }
            `,
        `
                switch (a) {
                    case 1: var x; 
                }
            `
    ],
    invalid: [
        {
            code: `
                switch (a) { 
                    case 1: 
                        {} 
                        function f() {} 
                        break; 
                }
            `,
            errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }]
        },
        {
            code: `
                switch (a) { 
                    case 1: 
                    case 2: 
                        let x; 
                }
            `,
            parserOptions: { ecmaVersion: 6 },