@@ -31,11 +31,16 @@ export default defineConfig(
3131 } ,
3232 //#endregion
3333
34+ //#region prettier
35+ eslintPluginPrettierRecommended ,
36+ //#endregion
37+
3438 //#region eslint (js)
3539 eslint . configs . recommended ,
3640 {
3741 name : 'eslint overrides' ,
3842 rules : {
43+ curly : [ 'error' , 'all' ] ,
3944 eqeqeq : [ 'error' , 'always' , { null : 'ignore' } ] ,
4045 'logical-assignment-operators' : 'error' ,
4146 'no-else-return' : 'error' ,
@@ -167,7 +172,7 @@ export default defineConfig(
167172 //#endregion
168173
169174 //#region unicorn
170- eslintPluginUnicorn . configs [ 'flat/ recommended' ] ,
175+ eslintPluginUnicorn . configs . recommended ,
171176 {
172177 name : 'unicorn overrides' ,
173178 rules : {
@@ -199,10 +204,6 @@ export default defineConfig(
199204 } ,
200205 //#endregion
201206
202- //#region prettier
203- eslintPluginPrettierRecommended ,
204- //#endregion
205-
206207 //#region overrides
207208 {
208209 name : 'test/**/*.ts overrides' ,
@@ -246,6 +247,127 @@ export default defineConfig(
246247 '@typescript-eslint/no-throw-literal' : 'off' ,
247248 'unicorn/no-array-reduce' : 'off' ,
248249 } ,
249- }
250+ } ,
250251 //#endregion
252+
253+ {
254+ name : 'custom' ,
255+ plugins : {
256+ custom : {
257+ rules : {
258+ 'no-arrow-parameter-types' : {
259+ meta : {
260+ fixable : 'code' ,
261+ hasSuggestions : true ,
262+ type : 'suggestion' ,
263+ dialects : [ 'typescript' ] ,
264+ schema : [
265+ {
266+ type : 'object' ,
267+ properties : {
268+ allowOptional : {
269+ type : 'boolean' ,
270+ default : false ,
271+ description :
272+ 'Allow type annotations when the parameter is optional. Sometimes useful for overloaded functions.' ,
273+ } ,
274+ } ,
275+ } ,
276+ ] ,
277+ defaultOptions : [
278+ {
279+ allowOptional : false ,
280+ } ,
281+ ] ,
282+ } ,
283+ create ( context ) {
284+ const options = context . options [ 0 ] as { allowOptional : boolean } ;
285+
286+ return {
287+ ArrowFunctionExpression ( node ) {
288+ const paramsWithTypeAnnotation = node . params . filter (
289+ (
290+ // @ts -expect-error: will be inferred when moved into an official plugin
291+ param
292+ ) => param . typeAnnotation !== undefined
293+ ) ;
294+
295+ const isCatchClause =
296+ node . parent . callee ?. property ?. name === 'catch' ;
297+
298+ if ( paramsWithTypeAnnotation . length > 0 && ! isCatchClause ) {
299+ for ( const param of paramsWithTypeAnnotation ) {
300+ if ( param . optional && options . allowOptional ) {
301+ continue ;
302+ }
303+
304+ context . report ( {
305+ node : param ,
306+ message :
307+ 'Arrow function parameters should not have type annotations. Instead the Object where the operation is used should be typed correctly.' ,
308+ fix ( fixer ) {
309+ if ( param . optional ) {
310+ return null ;
311+ }
312+
313+ // TODO @Shinigami 92 2025-06-16: Handle async arrow functions
314+ if ( node . parent . type === 'VariableDeclarator' ) {
315+ const variableDeclaratorNode = node . parent ;
316+
317+ return [
318+ // Remove ` =>`
319+ fixer . replaceTextRange (
320+ [ node . body . range [ 0 ] - 3 , node . body . range [ 0 ] ] ,
321+ ''
322+ ) ,
323+ // Remove ` = `
324+ fixer . replaceTextRange (
325+ [
326+ variableDeclaratorNode . id . range [ 1 ] ,
327+ variableDeclaratorNode . init . range [ 0 ] ,
328+ ] ,
329+ ''
330+ ) ,
331+ // Replace `const ` with `function `
332+ fixer . replaceTextRange (
333+ [
334+ variableDeclaratorNode . parent . range [ 0 ] ,
335+ variableDeclaratorNode . range [ 0 ] ,
336+ ] ,
337+ 'function '
338+ ) ,
339+ ] ;
340+ }
341+
342+ return fixer . removeRange ( param . typeAnnotation . range ) ;
343+ } ,
344+ suggest : [
345+ {
346+ desc : 'Remove type annotation' ,
347+ fix ( fixer ) {
348+ if ( param . optional ) {
349+ return fixer . removeRange ( [
350+ param . typeAnnotation . range [ 0 ] - 1 , // Remove the `?` before the type annotation
351+ param . typeAnnotation . range [ 1 ] ,
352+ ] ) ;
353+ }
354+
355+ return null ;
356+ } ,
357+ } ,
358+ ] ,
359+ } ) ;
360+ }
361+ }
362+ } ,
363+ } ;
364+ } ,
365+ } ,
366+ } ,
367+ } ,
368+ } ,
369+ rules : {
370+ 'custom/no-arrow-parameter-types' : [ 'error' , { allowOptional : true } ] ,
371+ } ,
372+ }
251373) ;
0 commit comments