@@ -177,24 +177,40 @@ impl Rule for ArrayType {
177177 }
178178
179179 fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
180- let default_config = & self . default ;
181- let readonly_config: & ArrayOption =
182- & self . readonly . clone ( ) . unwrap_or_else ( || default_config. clone ( ) ) ;
183-
184180 match node. kind ( ) {
185181 AstKind :: TSArrayType ( ts_array_type) => {
186- check ( & ts_array_type. element_type , default_config, readonly_config, ctx) ;
182+ check (
183+ & ts_array_type. element_type ,
184+ self . default_config ( ) ,
185+ self . readonly_config ( ) ,
186+ ctx,
187+ ) ;
187188 }
188189 AstKind :: TSTypeAnnotation ( ts_type_annotation) => {
189- check ( & ts_type_annotation. type_annotation , default_config, readonly_config, ctx) ;
190+ check (
191+ & ts_type_annotation. type_annotation ,
192+ self . default_config ( ) ,
193+ self . readonly_config ( ) ,
194+ ctx,
195+ ) ;
190196 }
191197 // for example: type barUnion = (string | number | boolean)[];
192198 AstKind :: TSTypeAliasDeclaration ( ts_alias_annotation) => {
193- check ( & ts_alias_annotation. type_annotation , default_config, readonly_config, ctx) ;
199+ check (
200+ & ts_alias_annotation. type_annotation ,
201+ self . default_config ( ) ,
202+ self . readonly_config ( ) ,
203+ ctx,
204+ ) ;
194205 }
195206 // for example: let ya = [[1, '2']] as [number, string][];
196207 AstKind :: TSAsExpression ( ts_as_expression) => {
197- check ( & ts_as_expression. type_annotation , default_config, readonly_config, ctx) ;
208+ check (
209+ & ts_as_expression. type_annotation ,
210+ self . default_config ( ) ,
211+ self . readonly_config ( ) ,
212+ ctx,
213+ ) ;
198214 }
199215 AstKind :: TSTypeReference ( ts_type_reference)
200216 if outermost_paren_parent ( node, ctx) . is_some_and ( |x| match x. kind ( ) {
@@ -209,30 +225,34 @@ impl Rule for ArrayType {
209225 } ) =>
210226 {
211227 check_and_report_error_reference (
212- default_config,
213- readonly_config,
228+ self . default_config ( ) ,
229+ self . readonly_config ( ) ,
214230 ts_type_reference,
215231 ctx,
216232 ) ;
217233 }
218234 AstKind :: TSTypeParameterInstantiation ( ts_type_param_instantiation) => {
219235 for param in & ts_type_param_instantiation. params {
220- check ( param, default_config, readonly_config, ctx) ;
236+ check ( param, self . default_config ( ) , self . readonly_config ( ) , ctx) ;
221237 }
222238 }
223239 AstKind :: TSConditionalType ( ts_conditional_type) => {
240+ let default_config = self . default_config ( ) ;
241+ let readonly_config = self . readonly_config ( ) ;
224242 check ( & ts_conditional_type. check_type , default_config, readonly_config, ctx) ;
225243 check ( & ts_conditional_type. extends_type , default_config, readonly_config, ctx) ;
226244 check ( & ts_conditional_type. true_type , default_config, readonly_config, ctx) ;
227245 check ( & ts_conditional_type. false_type , default_config, readonly_config, ctx) ;
228246 }
229247 AstKind :: TSIndexedAccessType ( ts_indexed_access_type) => {
248+ let default_config = self . default_config ( ) ;
249+ let readonly_config = self . readonly_config ( ) ;
230250 check ( & ts_indexed_access_type. object_type , default_config, readonly_config, ctx) ;
231251 check ( & ts_indexed_access_type. index_type , default_config, readonly_config, ctx) ;
232252 }
233253 AstKind :: TSMappedType ( ts_mapped_type) => {
234254 if let Some ( type_annotation) = & ts_mapped_type. type_annotation {
235- check ( type_annotation, default_config, readonly_config, ctx) ;
255+ check ( type_annotation, self . default_config ( ) , self . readonly_config ( ) , ctx) ;
236256 }
237257 }
238258 _ => { }
@@ -244,6 +264,16 @@ impl Rule for ArrayType {
244264 }
245265}
246266
267+ impl ArrayType {
268+ fn default_config ( & self ) -> & ArrayOption {
269+ & self . default
270+ }
271+
272+ fn readonly_config ( & self ) -> & ArrayOption {
273+ if let Some ( readonly) = & self . readonly { readonly } else { & self . default }
274+ }
275+ }
276+
247277fn check (
248278 type_annotation : & TSType ,
249279 default_config : & ArrayOption ,
0 commit comments