pve-eslint/eslint/tests/lib/rules/no-catch-shadow.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

56 lines
2.0 KiB
JavaScript

/**
* @fileoverview Tests for no-catch-shadow rule.
* @author Ian Christian Myers
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-catch-shadow"),
{ RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("no-catch-shadow", rule, {
valid: [
"var foo = 1; try { bar(); } catch(baz) { }",
{
code: [
"'use strict';",
"",
"function broken() {",
" try {",
" throw new Error();",
" } catch (e) {",
" //",
" }",
"}",
"",
"module.exports = broken;"
].join("\n"),
parserOptions: { ecmaVersion: 6 }
},
{
code: "try {} catch (error) {}",
env: { shelljs: false }
},
{
code: "try {} catch {}",
parserOptions: { ecmaVersion: 2019 }
}
],
invalid: [
{ code: "var foo = 1; try { bar(); } catch(foo) { }", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] },
{ code: "function foo(){} try { bar(); } catch(foo) { }", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] },
{ code: "function foo(){ try { bar(); } catch(foo) { } }", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] },
{ code: "var foo = function(){ try { bar(); } catch(foo) { } };", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] }
]
});