Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-students-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

fix: update method for extracting major version
20 changes: 18 additions & 2 deletions packages/eslint-plugin-svelte/src/utils/svelte-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function getSvelteVersion(filePath: string): SvelteContext['svelteVersion'] {
if (typeof version !== 'string') {
continue;
}
const major = version.split('.')[0];
const major = extractMajorVersion(version, false);
if (major === '3' || major === '4') {
return '3/4';
}
Expand Down Expand Up @@ -185,7 +185,8 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
if (typeof version !== 'string') {
return null;
}
return version.split('.')[0] as SvelteContext['svelteKitVersion'];

return extractMajorVersion(version, true) as SvelteContext['svelteKitVersion'];
}
} catch {
/** do nothing */
Expand All @@ -194,6 +195,21 @@ function getSvelteKitVersion(filePath: string): SvelteContext['svelteKitVersion'
return null;
}

function extractMajorVersion(version: string, recognizePrereleaseVersion: boolean): string | null {
if (recognizePrereleaseVersion) {
const match = /^(?:\^|~)?(\d+\.0\.0-next)/.exec(version);
if (match && match[1]) {
return match[1];
}
}

const match = /^(?:\^|~)?(\d+)\./.exec(version);
if (match && match[1]) {
return match[1];
}
return null;
}

/**
* Gets a project root folder path.
* @param filePath A file path to lookup.
Expand Down
Loading