feat(core): PERF010 — namespace (whole-library) import - #75
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds PERF010, a performance lint for bare-package namespace imports. The PR extends ChangesPERF010 Namespace Import Rule
Sequence Diagram(s)sequenceDiagram
participant SvelteFile
participant parseComponentFacts
participant ComponentFacts
participant perf010NamespaceImport
SvelteFile->>parseComponentFacts: script content
parseComponentFacts->>ComponentFacts: namespaceImports [source, line]
perf010NamespaceImport->>ComponentFacts: read namespaceImports
perf010NamespaceImport->>perf010NamespaceImport: dedupe by source
perf010NamespaceImport-->>perf010NamespaceImport: emit findings
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/superpowers/plans/2026-07-01-perf010-namespace-import.md (1)
195-197: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNested markdown fences trigger markdownlint warnings.
Static analysis flags spaces inside code spans (MD038) and fenced blocks without a language tag (MD040) in this planning doc. Since this is an internal plan/spec artifact (not published docs), these are cosmetic and non-blocking.
Also applies to: 337-337, 345-345, 353-353, 417-417, 451-451
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/superpowers/plans/2026-07-01-perf010-namespace-import.md` around lines 195 - 197, The planning doc has markdownlint issues caused by nested fenced blocks and spacing inside inline code spans, so clean up the affected examples by removing the nested fence pattern and ensuring every fenced block has an explicit language tag. Also trim the extra spaces inside the inline code spans in the sections around the `namespaceImports` examples so the MD038/MD040 warnings are cleared without changing the plan content.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@docs/superpowers/plans/2026-07-01-perf010-namespace-import.md`:
- Around line 195-197: The planning doc has markdownlint issues caused by nested
fenced blocks and spacing inside inline code spans, so clean up the affected
examples by removing the nested fence pattern and ensuring every fenced block
has an explicit language tag. Also trim the extra spaces inside the inline code
spans in the sections around the `namespaceImports` examples so the MD038/MD040
warnings are cleared without changing the plan content.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2449857f-b297-4da6-98b6-a6f0709c7aae
📒 Files selected for processing (16)
.changeset/perf010-namespace-import.mddocs/src/content/docs/ja/rules/perf010.mddocs/src/content/docs/rules/perf010.mddocs/superpowers/plans/2026-07-01-perf010-namespace-import.mddocs/superpowers/specs/2026-07-01-perf010-namespace-import-design.mdpackages/cli/src/providers/source/components.tspackages/cli/src/providers/source/parse.tspackages/cli/test/parse-component-facts.test.tspackages/core/src/component.tspackages/core/src/index.tspackages/core/src/rules/index.tspackages/core/src/rules/performance/perf010-namespace-import.tspackages/core/test/architecture-rules.test.tspackages/core/test/bundle-rules.test.tspackages/core/test/correctness-rules.test.tspackages/core/test/security-rules.test.ts
There was a problem hiding this comment.
Pull request overview
Adds a new PERF010 performance rule to flag namespace (“whole-library”) imports from bare package specifiers (e.g. import * as X from 'pkg') to help prevent tree-shaking defeats, by extending the CLI component-facts collector and surfacing the rule via core exports and docs.
Changes:
- Extend
ComponentFactswithnamespaceImportsand collect them from both<script>and<script module>in the CLI parser. - Add and register
perf010NamespaceImport(info/performance/component) plus core tests verifying flagging + per-package dedupe behavior. - Add PERF010 documentation (EN/JA) and a changeset bumping core / svelte-vitals / mcp (minor).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/test/security-rules.test.ts | Updates ComponentFacts test helper to include namespaceImports. |
| packages/core/test/correctness-rules.test.ts | Updates ComponentFacts test helper to include namespaceImports. |
| packages/core/test/bundle-rules.test.ts | Adds PERF010 unit tests and updates helper shape. |
| packages/core/test/architecture-rules.test.ts | Updates ComponentFacts test helper to include namespaceImports. |
| packages/core/src/rules/performance/perf010-namespace-import.ts | Introduces PERF010 rule implementation (namespace import detection/dedupe). |
| packages/core/src/rules/index.ts | Registers PERF010 in allRules and re-exports it. |
| packages/core/src/index.ts | Re-exports PERF010 from core public entrypoint. |
| packages/core/src/component.ts | Adds ComponentFacts.namespaceImports field. |
| packages/cli/test/parse-component-facts.test.ts | Adds parser coverage for collecting namespace imports (bare/module/type-only/non-bare). |
| packages/cli/src/providers/source/parse.ts | Implements bare-specifier check + namespace import collector; returns namespaceImports. |
| packages/cli/src/providers/source/components.ts | Adds namespaceImports: [] to error/fallback facts. |
| docs/superpowers/specs/2026-07-01-perf010-namespace-import-design.md | Design spec documenting PERF010 behavior and implementation details. |
| docs/superpowers/plans/2026-07-01-perf010-namespace-import.md | Implementation plan/checklist for PERF010 work. |
| docs/src/content/docs/rules/perf010.md | New English rule reference page for PERF010. |
| docs/src/content/docs/ja/rules/perf010.md | New Japanese rule reference page for PERF010. |
| .changeset/perf010-namespace-import.md | Changeset for minor bumps and release notes for PERF010. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collection order is module-then-instance, not always source order, so dedupe by taking the minimum line per source and sort findings by line, matching the documented 'first occurrence' behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Completes the Bundle/perf slice of #69 (heavy deps shipped as PERF009). Adds PERF010 — namespace import, flagging a value
import * as X from '<bare package>'— a whole-library import that keeps the entire module in the bundle and defeats tree-shaking. Advisory, soinfo.Covers the "whole-library import" of arbitrary packages that PERF009 doesn't: PERF009 matches a curated heavy list by exact specifier; for any other package a named import is tree-shakeable and carries no signal, but a namespace import of any package is the whole-library form.
What's flagged
Not flagged: type-only (
import type * as T), named/default imports, and non-bare specifiers (./x,$lib,$app,$env,#…). Bare = doesn't start with./$#. No allowlist.How it works
ComponentFacts.namespaceImports: { source; line }[]field, populated in the CLI Svelte-AST parser over both<script>and<script module>. Excludes type-only via declarationimportKind === 'type'; captures 1-based line.ComponentFacts.imports(PERF009) is untouched.componentRulefactory (CLI/static only; no-ops in rendered mode). Dedupes findings bysource.info/performance/component.analyze/explain_rulesurface it automatically viaallRules.Docs & release
@svelte-vitals/core+svelte-vitals+@svelte-vitals/mcpminor (CLI/static rule; not@svelte-vitals/vite, matching PERF009).Validation
pnpm -r test(546: core 247 / vite 76 / cli 214 / mcp 9),pnpm -r typecheck,pnpm lint,pnpm --filter docs build(109 pages incl. the 2 new) — all green.Process
Built spec → plan → subagent-driven (3 impl tasks, each spec + quality reviewed) + a whole-branch review on Opus (verdict: ready to merge). The reviewer verified the collector against the live Svelte parser, including the subtle point that a value
import * as Uhas declarationimportKind === undefined(not'value'), so excluding only=== 'type'is correct.🤖 Generated with Claude Code
Summary by CodeRabbit