@@ -272,45 +272,26 @@ function traverse(ast, nodes = []) {
272272 }
273273}
274274
275- function getFirstLineOfText ( content , text ) {
276- var firstLine = 0
277- let splittedContent = content . split ( newLine )
275+ function getFirstLineWithText ( content , text ) {
276+ const contentByLine = content . split ( newLine )
278277 if ( ! content . includes ( text ) ) {
279- return splittedContent . length
278+ return contentByLine . length
280279 }
281- splittedContent . some ( ( line , index ) => {
282- if ( line . includes ( text ) ) {
283- firstLine = index
284- return true
285- } else {
286- return false
287- }
288- } )
289- return firstLine
280+ return contentByLine . findIndex ( line => line . includes ( text ) )
290281}
291282
292- function getFirstNonLineOfText ( content , text ) {
293- var firstNonCommentedLine = 0
294- let splittedContent = content . split ( newLine )
295-
283+ function getFirstLineWithoutText ( content , text ) {
284+ const contentByLine = content . split ( newLine )
296285 if ( ! content . includes ( text ) ) {
297286 return 0
298287 }
299- splittedContent . some ( ( line , index ) => {
300- if ( line . includes ( text ) ) {
301- return false
302- } else {
303- firstNonCommentedLine = index
304- return true
305- }
306- } )
307- return firstNonCommentedLine
288+ return contentByLine . findIndex ( line => ! line . includes ( text ) )
308289}
309290
310291function getFirstValidLine ( content ) {
311- let firstImport = getFirstLineOfText ( content , 'import' )
312- let firstExport = getFirstLineOfText ( content , 'export' )
313- let firstNonCommentedLine = getFirstNonLineOfText ( content , '//' )
292+ const firstImport = getFirstLineWithText ( content , 'import' )
293+ const firstExport = getFirstLineWithText ( content , 'export' )
294+ const firstNonCommentedLine = getFirstLineWithoutText ( content , '//' )
314295
315296 return Math . min ( firstImport , firstExport , firstNonCommentedLine )
316297}
0 commit comments