@@ -14,20 +14,33 @@ import {
1414} from "~/common/ignore-options" ;
1515import type { RuleContext , RuleMetaData , RuleResult } from "~/util/rule" ;
1616import { createRule } from "~/util/rule" ;
17+ import { inForLoopInitializer } from "~/util/tree" ;
1718
1819// The name of this rule.
1920export const name = "no-let" as const ;
2021
2122// The options this rule can take.
22- type Options = AllowLocalMutationOption & IgnorePatternOption ;
23+ type Options = AllowLocalMutationOption &
24+ IgnorePatternOption & {
25+ readonly allowInForLoopInit : boolean ;
26+ } ;
2327
2428// The schema for the rule options.
2529const schema : JSONSchema4 = [
26- deepmerge ( allowLocalMutationOptionSchema , ignorePatternOptionSchema ) ,
30+ deepmerge ( allowLocalMutationOptionSchema , ignorePatternOptionSchema , {
31+ type : "object" ,
32+ properties : {
33+ allowInForLoopInit : {
34+ type : "boolean" ,
35+ } ,
36+ } ,
37+ additionalProperties : false ,
38+ } ) ,
2739] ;
2840
2941// The default options for the rule.
3042const defaultOptions : Options = {
43+ allowInForLoopInit : false ,
3144 allowLocalMutation : false ,
3245} ;
3346
@@ -57,8 +70,10 @@ function checkVariableDeclaration(
5770 options : Options
5871) : RuleResult < keyof typeof errorMessages , Options > {
5972 if (
73+ node . kind !== "let" ||
6074 shouldIgnoreLocalMutation ( node , context , options ) ||
61- shouldIgnorePattern ( node , context , options )
75+ shouldIgnorePattern ( node , context , options ) ||
76+ ( options . allowInForLoopInit && inForLoopInitializer ( node ) )
6277 ) {
6378 return {
6479 context,
@@ -68,7 +83,7 @@ function checkVariableDeclaration(
6883
6984 return {
7085 context,
71- descriptors : node . kind === "let" ? [ { node, messageId : "generic" } ] : [ ] ,
86+ descriptors : [ { node, messageId : "generic" } ] ,
7287 } ;
7388}
7489
0 commit comments