@@ -90,27 +90,31 @@ module.exports = {
90
90
const otherProps = openingElement . attributes . filter ( attr => attr !== iconProp )
91
91
const propsText = otherProps . map ( attr => sourceCode . getText ( attr ) ) . join ( ' ' )
92
92
93
- // Helper function to determine if this is the last Octicon in the file
94
- function isLastOcticon ( ) {
95
- // Get all Octicon elements using the source code
93
+ // Helper function to determine if this is the last Octicon in the file that needs fixing
94
+ function isLastOcticonToFix ( ) {
95
+ // Get all JSX elements in the source code that are Octicons with icon props
96
96
const sourceText = sourceCode . getText ( )
97
- const octiconMatches = [ ... sourceText . matchAll ( / < O c t i c o n \s / g ) ]
97
+ const lines = sourceText . split ( '\n' )
98
98
99
- if ( octiconMatches . length <= 1 ) {
100
- return true
101
- }
99
+ // Find all potential Octicon lines
100
+ const octiconLines = [ ]
101
+ lines . forEach ( ( line , index ) => {
102
+ if ( line . includes ( '<Octicon' ) && line . includes ( 'icon=' ) ) {
103
+ octiconLines . push ( index + 1 ) // 1-based line numbers
104
+ }
105
+ } )
102
106
103
- // Find the position of the current node in the source
104
- const currentNodeStart = node . range [ 0 ]
107
+ // Get the line number of the current node
108
+ const currentLine = sourceCode . getLocFromIndex ( node . range [ 0 ] ) . line
105
109
106
- // Check if there are any more Octicon elements after this one
107
- const laterOcticons = octiconMatches . filter ( match => match . index > currentNodeStart )
108
- return laterOcticons . length === 0
110
+ // Check if this is the last one
111
+ const currentIndex = octiconLines . indexOf ( currentLine )
112
+ return currentIndex === octiconLines . length - 1
109
113
}
110
114
111
115
// Helper function to generate import fixes if this is the last Octicon usage
112
116
function * generateImportFixes ( fixer ) {
113
- if ( isLastOcticon ( ) && octiconImports . length > 0 ) {
117
+ if ( isLastOcticonToFix ( ) && octiconImports . length > 0 ) {
114
118
const importNode = octiconImports [ 0 ]
115
119
const octiconSpecifier = importNode . specifiers . find (
116
120
specifier => specifier . imported && specifier . imported . name === 'Octicon' ,
0 commit comments