File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -319,6 +319,10 @@ module.exports = {
319319 function canFix ( node ) {
320320 const variables = sourceCode . getDeclaredVariables ( node ) ;
321321 const scopeNode = getScopeNode ( node ) ;
322+ const parentStatementList = new Set ( [
323+ ...astUtils . STATEMENT_LIST_PARENTS ,
324+ "TSModuleBlock" ,
325+ ] ) ;
322326
323327 if (
324328 node . parent . type === "SwitchCase" ||
@@ -347,7 +351,7 @@ module.exports = {
347351 node . parent . type === "ForStatement" &&
348352 node . parent . init === node
349353 ) &&
350- ! astUtils . STATEMENT_LIST_PARENTS . has ( node . parent . type )
354+ ! parentStatementList . has ( node . parent . type )
351355 ) {
352356 // If the declaration is not in a block, e.g. `if (foo) var bar = 1;`, then it can't be fixed.
353357 return false ;
Original file line number Diff line number Diff line change @@ -517,12 +517,19 @@ const ruleTesterTypeScript = new RuleTester({
517517ruleTesterTypeScript . run ( "no-var" , rule , {
518518 valid : [ "declare global { var bar: 'car' }" ] ,
519519 invalid : [
520+ {
521+ code : "declare var x: number" ,
522+ output : "declare let x: number" ,
523+ errors : [ { messageId : "unexpectedVar" } ] ,
524+ } ,
520525 {
521526 code : "declare namespace ns { var bar: 'car' }" ,
527+ output : "declare namespace ns { let bar: 'car' }" ,
522528 errors : [ { messageId : "unexpectedVar" } ] ,
523529 } ,
524530 {
525531 code : "declare module 'module' { var bar: 'car' }" ,
532+ output : "declare module 'module' { let bar: 'car' }" ,
526533 errors : [ { messageId : "unexpectedVar" } ] ,
527534 } ,
528535 ] ,
You can’t perform that action at this time.
0 commit comments