mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-08-26 00:53:54 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
56 lines
2.0 KiB
JavaScript
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" }] }
|
|
]
|
|
});
|