11import { sep } from 'node:path' ;
22import { definePlugin } from '../../../dist/index.js' ;
3+ import type { Rule } from '../../../dist/index.js' ;
34
45// `loc` is required for ESLint
56const SPAN = {
@@ -14,10 +15,10 @@ const SPAN = {
1415const DIR_PATH_LEN = import . meta. dirname . length + 1 ;
1516
1617const relativePath = sep === '/'
17- ? path => path . slice ( DIR_PATH_LEN )
18- : path => path . slice ( DIR_PATH_LEN ) . replace ( / \\ / g, '/' ) ;
18+ ? ( path : string ) => path . slice ( DIR_PATH_LEN )
19+ : ( path : string ) => path . slice ( DIR_PATH_LEN ) . replace ( / \\ / g, '/' ) ;
1920
20- const createRule = {
21+ const createRule : Rule = {
2122 create ( context ) {
2223 context . report ( { message : `create body:\nthis === rule: ${ this === createRule } ` , node : SPAN } ) ;
2324
@@ -36,16 +37,16 @@ const createRule = {
3637// i.e. Oxlint calls `createOnce` directly, and not the `create` method that `defineRule` (via `definePlugin`)
3738// adds to the rule.
3839let createOnceCallCount = 0 ;
39- const createOnceRule = {
40+ const createOnceRule : Rule = {
4041 createOnce ( context ) {
4142 createOnceCallCount ++ ;
4243
4344 // `fileNum` should be different for each file.
4445 // `identNum` should start at 1 for each file.
45- let fileNum = 0 , identNum ;
46+ let fileNum = 0 , identNum : number ;
4647 // Note: Files are processed in unpredictable order, so `files/1.js` may be `fileNum` 1 or 2.
4748 // Therefore, collect all visits and check them in `after` hook of the 2nd file.
48- const visits = [ ] ;
49+ const visits : { fileNum : number ; identNum : number } [ ] = [ ] ;
4950
5051 // `this` should be the rule object
5152 const topLevelThis = this ;
@@ -105,7 +106,7 @@ const createOnceRule = {
105106} ;
106107
107108// Tests that `before` hook returning `false` disables visiting AST for the file.
108- const createOnceBeforeFalseRule = {
109+ const createOnceBeforeFalseRule : Rule = {
109110 createOnce ( context ) {
110111 return {
111112 before ( ) {
@@ -138,7 +139,7 @@ const createOnceBeforeFalseRule = {
138139
139140// These 3 rules test that `createOnce` without `before` and `after` hooks works correctly.
140141
141- const createOnceBeforeOnlyRule = {
142+ const createOnceBeforeOnlyRule : Rule = {
142143 createOnce ( context ) {
143144 return {
144145 before ( ) {
@@ -159,7 +160,7 @@ const createOnceBeforeOnlyRule = {
159160 } ,
160161} ;
161162
162- const createOnceAfterOnlyRule = {
163+ const createOnceAfterOnlyRule : Rule = {
163164 createOnce ( context ) {
164165 return {
165166 Identifier ( node ) {
@@ -180,7 +181,7 @@ const createOnceAfterOnlyRule = {
180181 } ,
181182} ;
182183
183- const createOnceNoHooksRule = {
184+ const createOnceNoHooksRule : Rule = {
184185 createOnce ( context ) {
185186 return {
186187 Identifier ( node ) {
0 commit comments