File tree 2 files changed +23
-2
lines changed
packages/eslint-plugin-svelte/src/utils
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'] {
145
145
if ( typeof version !== 'string' ) {
146
146
continue ;
147
147
}
148
- const major = version . split ( '.' ) [ 0 ] ;
148
+ const major = extractMajorVersion ( version , false ) ;
149
149
if ( major === '3' || major === '4' ) {
150
150
return '3/4' ;
151
151
}
@@ -185,7 +185,8 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
185
185
if ( typeof version !== 'string' ) {
186
186
return null ;
187
187
}
188
- return version . split ( '.' ) [ 0 ] as SvelteContext [ 'svelteKitVersion' ] ;
188
+
189
+ return extractMajorVersion ( version , true ) as SvelteContext [ 'svelteKitVersion' ] ;
189
190
}
190
191
} catch {
191
192
/** do nothing */
@@ -194,6 +195,21 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
194
195
return null ;
195
196
}
196
197
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
+
197
213
/**
198
214
* Gets a project root folder path.
199
215
* @param filePath A file path to lookup.
You can’t perform that action at this time.
0 commit comments