Skip to content

Commit 87af64f

Browse files
committed
fix: prevent imported_runes suggestion from being added for libs that are not svelte
1 parent c1678b2 commit 87af64f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.changeset/clear-buckets-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/mcp': patch
3+
---
4+
5+
fix: prevent `imported_runes` suggestion from being added for libs that are not svelte

packages/mcp-server/src/mcp/autofixers/add-autofixers-issues.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,19 @@ describe('add_autofixers_issues', () => {
412412
});
413413
},
414414
);
415+
416+
describe.each(dollarless_runes)('importing $rune from external lib', ({ rune }) => {
417+
it(`should not add suggestions when importing from packages that are not svelte`, () => {
418+
const content = run_autofixers_on_code(`
419+
<script>
420+
import { ${rune} } from 'svelte-something-something';
421+
</script>`);
422+
423+
expect(content.suggestions).not.toContain(
424+
`You are importing "${rune}" from "svelte-something-something". This is not necessary, all runes are globally available. Please remove this import and use "$${rune}" directly.`,
425+
);
426+
});
427+
});
415428
});
416429

417430
describe('derived_with_function', () => {

packages/mcp-server/src/mcp/autofixers/visitors/imported-runes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const dollarless_runes = base_runes.map((r) => r.replace('$', ''));
66
export const imported_runes: Autofixer = {
77
ImportDeclaration(node, { state, next }) {
88
const source = (node.source.value || node.source.raw?.slice(1, -1))?.toString();
9-
if (source && source.startsWith('svelte')) {
9+
if (source && (source === 'svelte' || source.startsWith('svelte/'))) {
1010
for (const specifier of node.specifiers) {
1111
const id =
1212
specifier.type === 'ImportDefaultSpecifier'

0 commit comments

Comments
 (0)