@@ -270,6 +270,11 @@ ruleTester.run("no-unused-vars", rule, {
270270options :[ { destructuredArrayIgnorePattern :"^_" , ignoreRestSiblings :true } ] ,
271271languageOptions :{ ecmaVersion :2018 }
272272} ,
273+ {
274+ code :"try {} catch ([firstError]) {}" ,
275+ options :[ { destructuredArrayIgnorePattern :"Error$" } ] ,
276+ languageOptions :{ ecmaVersion :2015 }
277+ } ,
273278
274279// for-in loops (see #2342)
275280"(function(obj) { var name; for ( name in obj ) return; })({});" ,
@@ -316,6 +321,16 @@ ruleTester.run("no-unused-vars", rule, {
316321code :"try{}catch(ignoreErr){}" ,
317322options :[ { caughtErrors :"all" , caughtErrorsIgnorePattern :"^ignore" } ]
318323} ,
324+ {
325+ code :"try {} catch ({ message, stack }) {}" ,
326+ options :[ { caughtErrorsIgnorePattern :"message|stack" } ] ,
327+ languageOptions :{ ecmaVersion :2015 }
328+ } ,
329+ {
330+ code :"try {} catch ({ errors: [firstError] }) {}" ,
331+ options :[ { caughtErrorsIgnorePattern :"Error$" } ] ,
332+ languageOptions :{ ecmaVersion :2015 }
333+ } ,
319334
320335// caughtErrors with other combinations
321336{
@@ -329,6 +344,11 @@ ruleTester.run("no-unused-vars", rule, {
329344options :[ { ignoreRestSiblings :true } ] ,
330345languageOptions :{ ecmaVersion :2018 }
331346} ,
347+ {
348+ code :"try {} catch ({ foo, ...bar }) { console.log(bar); }" ,
349+ options :[ { ignoreRestSiblings :true } ] ,
350+ languageOptions :{ ecmaVersion :2018 }
351+ } ,
332352
333353// https://github.com/eslint/eslint/issues/6348
334354"var a = 0, b; b = a = a + 1; foo(b);" ,
@@ -1674,6 +1694,30 @@ c = foo1`,
16741694options :[ { caughtErrors :"all" , caughtErrorsIgnorePattern :"^_" , reportUsedIgnorePattern :true } ] ,
16751695errors :[ usedIgnoredError ( "_err" , ". Used caught errors must not match /^_/u" ) ]
16761696} ,
1697+ {
1698+ code :"try {} catch ({ message }) { console.error(message); }" ,
1699+ options :[ { caughtErrorsIgnorePattern :"message" , reportUsedIgnorePattern :true } ] ,
1700+ languageOptions :{ ecmaVersion :2015 } ,
1701+ errors :[ usedIgnoredError ( "message" , ". Used caught errors must not match /message/u" ) ]
1702+ } ,
1703+ {
1704+ code :"try {} catch ([_a, _b]) { doSomething(_a, _b); }" ,
1705+ options :[ { caughtErrorsIgnorePattern :"^_" , reportUsedIgnorePattern :true } ] ,
1706+ languageOptions :{ ecmaVersion :6 } ,
1707+ errors :[
1708+ usedIgnoredError ( "_a" , ". Used caught errors must not match /^_/u" ) ,
1709+ usedIgnoredError ( "_b" , ". Used caught errors must not match /^_/u" )
1710+ ]
1711+ } ,
1712+ {
1713+ code :"try {} catch ([_a, _b]) { doSomething(_a, _b); }" ,
1714+ options :[ { destructuredArrayIgnorePattern :"^_" , reportUsedIgnorePattern :true } ] ,
1715+ languageOptions :{ ecmaVersion :6 } ,
1716+ errors :[
1717+ usedIgnoredError ( "_a" , ". Used elements of array destructuring must not match /^_/u" ) ,
1718+ usedIgnoredError ( "_b" , ". Used elements of array destructuring must not match /^_/u" )
1719+ ]
1720+ } ,
16771721{
16781722code :`
16791723try {
@@ -1705,6 +1749,35 @@ try {
17051749}
17061750]
17071751} ,
1752+ {
1753+ code :"try {} catch ({ message, errors: [firstError] }) {}" ,
1754+ options :[ { caughtErrorsIgnorePattern :"foo" } ] ,
1755+ languageOptions :{ ecmaVersion :2015 } ,
1756+ errors :[
1757+ {
1758+ message :"'message' is defined but never used. Allowed unused caught errors must match /foo/u." ,
1759+ column :17 ,
1760+ endColumn :24
1761+ } ,
1762+ {
1763+ message :"'firstError' is defined but never used. Allowed unused caught errors must match /foo/u." ,
1764+ column :35 ,
1765+ endColumn :45
1766+ }
1767+ ]
1768+ } ,
1769+ {
1770+ code :"try {} catch ({ stack: $ }) { $ = 'Something broke: ' + $; }" ,
1771+ options :[ { caughtErrorsIgnorePattern :"\\w" } ] ,
1772+ languageOptions :{ ecmaVersion :2015 } ,
1773+ errors :[
1774+ {
1775+ message :"'$' is assigned a value but never used. Allowed unused caught errors must match /\\w/u." ,
1776+ column :31 ,
1777+ endColumn :32
1778+ }
1779+ ]
1780+ } ,
17081781{
17091782code :`
17101783_ => { _ = _ + 1 };