Skip to content

feat(core): PERF010 — namespace (whole-library) import - #75

Merged
oekazuma merged 7 commits into
mainfrom
feat/perf010-namespace-import
Jul 2, 2026
Merged

oekazuma merged 7 commits into
mainfrom
feat/perf010-namespace-import

Conversation

@oekazuma

@oekazuma oekazuma commented Jul 1, 2026 •

Copy link
Copy Markdown
Owner

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, so info.

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

import * as _ from 'lodash';      // ✗ flag
import * as THREE from 'three';   // ✗ flag (named imports tree-shake better)

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

  • Capture: a new ComponentFacts.namespaceImports: { source; line }[] field, populated in the CLI Svelte-AST parser over both <script> and <script module>. Excludes type-only via declaration importKind === 'type'; captures 1-based line. ComponentFacts.imports (PERF009) is untouched.
  • Rule: built with the existing componentRule factory (CLI/static only; no-ops in rendered mode). Dedupes findings by source. info / performance / component.
  • MCP analyze / explain_rule surface it automatically via allRules.

Docs & release

  • 2 rule reference pages (PERF010, en + ja).
  • @svelte-vitals/core + svelte-vitals + @svelte-vitals/mcp minor (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 U has declaration importKind === undefined (not 'value'), so excluding only === 'type' is correct.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a new PERF010 performance rule that flags value namespace imports from bare packages (to encourage named/default imports and improve tree-shaking).
    • Wired the rule into the rule set so findings are surfaced during lint runs.
  • Bug Fixes
    • Enhanced static parsing to detect namespace imports from both instance and module scripts, with proper type-only and non-bare exclusions.
    • Improved robustness when parsing fails by providing an empty namespace-imports result.
  • Documentation
    • Added English and Japanese rule docs, plus an accompanying Changeset entry.

oekazuma and others added 6 commits July 1, 2026 14:19
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>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b3f05a2-463b-4670-92f0-a4ae5ddf0f37

📥 Commits

Reviewing files that changed from the base of the PR and between ae13743 and 8495259.

📒 Files selected for processing (2)
  • packages/core/src/rules/performance/perf010-namespace-import.ts
  • packages/core/test/bundle-rules.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/rules/performance/perf010-namespace-import.ts
  • packages/core/test/bundle-rules.test.ts

📝 Walkthrough

Walkthrough

Adds PERF010, a performance lint for bare-package namespace imports. The PR extends ComponentFacts and CLI parsing to capture namespace imports, registers and implements the rule in core, updates tests, and adds related docs, spec, plan, and changeset files.

Changes

PERF010 Namespace Import Rule

Layer / File(s) Summary
ComponentFacts contract and CLI parsing
packages/core/src/component.ts, packages/cli/src/providers/source/parse.ts, packages/cli/src/providers/source/components.ts, packages/cli/test/parse-component-facts.test.ts
Adds namespaceImports to ComponentFacts and populates it from bare import * as declarations in module and instance scripts, including parse-failure fallback and parser tests.
Rule implementation and registration
packages/core/src/rules/performance/perf010-namespace-import.ts, packages/core/src/rules/index.ts, packages/core/src/index.ts, packages/core/test/bundle-rules.test.ts, packages/core/test/architecture-rules.test.ts, packages/core/test/correctness-rules.test.ts, packages/core/test/security-rules.test.ts
Implements perf010NamespaceImport, registers it in rule exports and allRules, and updates rule fixtures/tests for the new namespaceImports shape.
Documentation and planning artifacts
docs/src/content/docs/rules/perf010.md, docs/src/content/docs/ja/rules/perf010.md, .changeset/perf010-namespace-import.md, docs/superpowers/plans/..., docs/superpowers/specs/...
Adds PERF010 docs in English and Japanese, plus supporting plan, spec, and changeset documents.
Estimated code review effort: 2 (Simple) ~15 minutes

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
Loading

Possibly related PRs

  • oekazuma/svelte-vitals#36: Extends the same rule registration/export plumbing in packages/core/src/index.ts and packages/core/src/rules/index.ts to add new performance rules.
  • oekazuma/svelte-vitals#68: Builds on the same ComponentFacts/parseComponentFacts extension pattern for capturing new static-analysis facts consumed by rules.
  • oekazuma/svelte-vitals#70: Extends ComponentFacts and CLI parsing output with new template facts before registering category-specific rules, mirroring this PR's approach.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding PERF010 for namespace imports in core.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/perf010-namespace-import

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/superpowers/plans/2026-07-01-perf010-namespace-import.md (1)

195-197: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Nested 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

📥 Commits

Reviewing files that changed from the base of the PR and between a78c085 and ae13743.

📒 Files selected for processing (16)
  • .changeset/perf010-namespace-import.md
  • docs/src/content/docs/ja/rules/perf010.md
  • docs/src/content/docs/rules/perf010.md
  • docs/superpowers/plans/2026-07-01-perf010-namespace-import.md
  • docs/superpowers/specs/2026-07-01-perf010-namespace-import-design.md
  • packages/cli/src/providers/source/components.ts
  • packages/cli/src/providers/source/parse.ts
  • packages/cli/test/parse-component-facts.test.ts
  • packages/core/src/component.ts
  • packages/core/src/index.ts
  • packages/core/src/rules/index.ts
  • packages/core/src/rules/performance/perf010-namespace-import.ts
  • packages/core/test/architecture-rules.test.ts
  • packages/core/test/bundle-rules.test.ts
  • packages/core/test/correctness-rules.test.ts
  • packages/core/test/security-rules.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ComponentFacts with namespaceImports and 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.

Comment thread packages/core/src/rules/performance/perf010-namespace-import.ts
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>
@oekazuma
oekazuma merged commit 61132a5 into main Jul 2, 2026
5 checks passed
@oekazuma
oekazuma deleted the feat/perf010-namespace-import branch July 2, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants