11import { describe , expect , test } from 'vitest'
22import { octiconAriaLabels } from '../../lib/linting-rules/octicon-aria-labels'
33
4+ interface ErrorInfo {
5+ lineNumber : number
6+ detail ?: string
7+ context ?: string
8+ range ?: [ number , number ]
9+ fixInfo ?: any // Matches RuleErrorCallback signature - fixInfo structure varies by rule
10+ }
11+
412describe ( 'octicon-aria-labels' , ( ) => {
513 const rule = octiconAriaLabels
614
7- test ( 'detects octicon without aria-label' , ( ) => {
8- const errors = [ ]
9- const onError = ( errorInfo ) => {
15+ // Helper to create onError callback that captures errors
16+ function createErrorCollector ( ) {
17+ const errors : ErrorInfo [ ] = [ ]
18+ // Using any because the actual rule implementation calls onError with an object,
19+ // not individual parameters as defined in RuleErrorCallback
20+ const onError = ( errorInfo : any ) => {
1021 errors . push ( errorInfo )
1122 }
23+ return { errors, onError }
24+ }
25+
26+ test ( 'detects octicon without aria-label' , ( ) => {
27+ const { errors, onError } = createErrorCollector ( )
1228
1329 const content = [ 'This is a test with an octicon:' , '{% octicon "alert" %}' , 'Some more text.' ]
1430
15- rule . function ( { lines : content } , onError )
31+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
1632
1733 expect ( errors . length ) . toBe ( 1 )
1834 expect ( errors [ 0 ] . lineNumber ) . toBe ( 2 )
@@ -21,27 +37,21 @@ describe('octicon-aria-labels', () => {
2137 } )
2238
2339 test ( 'ignores octicons with aria-label' , ( ) => {
24- const errors = [ ]
25- const onError = ( errorInfo ) => {
26- errors . push ( errorInfo )
27- }
40+ const { errors, onError } = createErrorCollector ( )
2841
2942 const content = [
3043 'This is a test with a proper octicon:' ,
3144 '{% octicon "alert" aria-label="alert" %}' ,
3245 'Some more text.' ,
3346 ]
3447
35- rule . function ( { lines : content } , onError )
48+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
3649
3750 expect ( errors . length ) . toBe ( 0 )
3851 } )
3952
4053 test ( 'detects multiple octicons without aria-label' , ( ) => {
41- const errors = [ ]
42- const onError = ( errorInfo ) => {
43- errors . push ( errorInfo )
44- }
54+ const { errors, onError } = createErrorCollector ( )
4555
4656 const content = [
4757 'This is a test with multiple octicons:' ,
@@ -51,7 +61,7 @@ describe('octicon-aria-labels', () => {
5161 'More text.' ,
5262 ]
5363
54- rule . function ( { lines : content } , onError )
64+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
5565
5666 expect ( errors . length ) . toBe ( 2 )
5767 expect ( errors [ 0 ] . lineNumber ) . toBe ( 2 )
@@ -61,10 +71,7 @@ describe('octicon-aria-labels', () => {
6171 } )
6272
6373 test ( 'ignores non-octicon liquid tags' , ( ) => {
64- const errors = [ ]
65- const onError = ( errorInfo ) => {
66- errors . push ( errorInfo )
67- }
74+ const { errors, onError } = createErrorCollector ( )
6875
6976 const content = [
7077 'This is a test with non-octicon tags:' ,
@@ -74,24 +81,21 @@ describe('octicon-aria-labels', () => {
7481 '{% endif %}' ,
7582 ]
7683
77- rule . function ( { lines : content } , onError )
84+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
7885
7986 expect ( errors . length ) . toBe ( 0 )
8087 } )
8188
8289 test ( 'suggests correct fix for octicon with other attributes' , ( ) => {
83- const errors = [ ]
84- const onError = ( errorInfo ) => {
85- errors . push ( errorInfo )
86- }
90+ const { errors, onError } = createErrorCollector ( )
8791
8892 const content = [
8993 'This is a test with an octicon with other attributes:' ,
9094 '{% octicon "plus" aria-hidden="true" class="foo" %}' ,
9195 'Some more text.' ,
9296 ]
9397
94- rule . function ( { lines : content } , onError )
98+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
9599
96100 expect ( errors . length ) . toBe ( 1 )
97101 expect ( errors [ 0 ] . lineNumber ) . toBe ( 2 )
@@ -101,29 +105,23 @@ describe('octicon-aria-labels', () => {
101105 } )
102106
103107 test ( 'handles octicons with unusual spacing' , ( ) => {
104- const errors = [ ]
105- const onError = ( errorInfo ) => {
106- errors . push ( errorInfo )
107- }
108+ const { errors, onError } = createErrorCollector ( )
108109
109110 const content = [
110111 'This is a test with unusual spacing:' ,
111112 '{% octicon "x" %}' ,
112113 'Some more text.' ,
113114 ]
114115
115- rule . function ( { lines : content } , onError )
116+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
116117
117118 expect ( errors . length ) . toBe ( 1 )
118119 expect ( errors [ 0 ] . lineNumber ) . toBe ( 2 )
119120 expect ( errors [ 0 ] . detail ) . toContain ( 'aria-label=x' )
120121 } )
121122
122123 test ( 'handles octicons split across multiple lines' , ( ) => {
123- const errors = [ ]
124- const onError = ( errorInfo ) => {
125- errors . push ( errorInfo )
126- }
124+ const { errors, onError } = createErrorCollector ( )
127125
128126 const content = [
129127 'This is a test with a multi-line octicon:' ,
@@ -133,25 +131,22 @@ describe('octicon-aria-labels', () => {
133131 'Some more text.' ,
134132 ]
135133
136- rule . function ( { lines : content } , onError )
134+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
137135
138136 expect ( errors . length ) . toBe ( 1 )
139137 expect ( errors [ 0 ] . detail ) . toContain ( 'aria-label=chevron-down' )
140138 } )
141139
142140 test ( 'falls back to "icon" when octicon name cannot be determined' , ( ) => {
143- const errors = [ ]
144- const onError = ( errorInfo ) => {
145- errors . push ( errorInfo )
146- }
141+ const { errors, onError } = createErrorCollector ( )
147142
148143 const content = [
149144 'This is a test with a malformed octicon:' ,
150145 '{% octicon variable %}' ,
151146 'Some more text.' ,
152147 ]
153148
154- rule . function ( { lines : content } , onError )
149+ rule . function ( { name : 'test.md' , lines : content , frontMatterLines : [ ] } , onError )
155150
156151 expect ( errors . length ) . toBe ( 1 )
157152 expect ( errors [ 0 ] . detail ) . toContain ( 'aria-label=icon' )
0 commit comments