File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed 
packages/eslint-plugin-svelte/src/utils Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 1+ --- 
2+ ' eslint-plugin-svelte '  : patch 
3+ --- 
4+ 
5+ fix: update method for extracting major version
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ function getSvelteVersion(filePath: string): SvelteContext['svelteVersion'] {
145145			if  ( typeof  version  !==  'string' )  { 
146146				continue ; 
147147			} 
148- 			const  major  =  version . split ( '.' ) [ 0 ] ; 
148+ 			const  major  =  extractMajorVersion ( version ,   false ) ; 
149149			if  ( major  ===  '3'  ||  major  ===  '4' )  { 
150150				return  '3/4' ; 
151151			} 
@@ -185,7 +185,8 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
185185			if  ( typeof  version  !==  'string' )  { 
186186				return  null ; 
187187			} 
188- 			return  version . split ( '.' ) [ 0 ]  as  SvelteContext [ 'svelteKitVersion' ] ; 
188+ 
189+ 			return  extractMajorVersion ( version ,  true )  as  SvelteContext [ 'svelteKitVersion' ] ; 
189190		} 
190191	}  catch  { 
191192		/** do nothing */ 
@@ -194,6 +195,21 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
194195	return  null ; 
195196} 
196197
198+ function  extractMajorVersion ( version : string ,  recognizePrereleaseVersion : boolean ) : string  |  null  { 
199+ 	if  ( recognizePrereleaseVersion )  { 
200+ 		const  match  =  / ^ (?: \^ | ~ ) ? ( \d + \. 0 \. 0 - n e x t ) / . exec ( version ) ; 
201+ 		if  ( match  &&  match [ 1 ] )  { 
202+ 			return  match [ 1 ] ; 
203+ 		} 
204+ 	} 
205+ 
206+ 	const  match  =  / ^ (?: \^ | ~ ) ? ( \d + ) \. / . exec ( version ) ; 
207+ 	if  ( match  &&  match [ 1 ] )  { 
208+ 		return  match [ 1 ] ; 
209+ 	} 
210+ 	return  null ; 
211+ } 
212+ 
197213/** 
198214 * Gets a  project root folder path. 
199215 * @param  filePath A file path to lookup. 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments