Skip to content

Commit f3e8ef1

Browse files
committed
refactor
1 parent 711f878 commit f3e8ef1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/eslint-plugin-svelte/src/utils/svelte-context.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function getSvelteVersion(filePath: string): SvelteContext['svelteVersion'] {
145145
if (typeof version !== 'string') {
146146
continue;
147147
}
148-
const major = extractMajorVersion(version);
148+
const major = extractMajorVersion(version, false);
149149
if (major === '3' || major === '4') {
150150
return '3/4';
151151
}
@@ -186,10 +186,7 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
186186
return null;
187187
}
188188

189-
if (version.includes('1.0.0-next')) {
190-
return '1.0.0-next';
191-
}
192-
return extractMajorVersion(version) as SvelteContext['svelteKitVersion'];
189+
return extractMajorVersion(version, true) as SvelteContext['svelteKitVersion'];
193190
}
194191
} catch {
195192
/** do nothing */
@@ -198,7 +195,14 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
198195
return null;
199196
}
200197

201-
function extractMajorVersion(version: string): string | null {
198+
function extractMajorVersion(version: string, recognizePrereleaseVersion: boolean): string | null {
199+
if (recognizePrereleaseVersion) {
200+
const match = /^(?:\^|~)?(\d+\.0\.0-next)/.exec(version);
201+
if (match && match[1]) {
202+
return match[1];
203+
}
204+
}
205+
202206
const match = /^(?:\^|~)?(\d+)\./.exec(version);
203207
if (match && match[1]) {
204208
return match[1];

0 commit comments

Comments
 (0)