Skip to content

fix(linting): single-export-per-file false positives on @fusionElement pattern - #5187

Merged
odinr merged 2 commits into
mainfrom
fix/single-export-per-file-fusion-element
Jul 30, 2026
Merged

fix(linting): single-export-per-file false positives on @fusionElement pattern#5187
odinr merged 2 commits into
mainfrom
fix/single-export-per-file-fusion-element

Conversation

@odinr

@odinr odinr commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Why

Fixes #5185.

The single-export-per-file rule flagged the standard @fusionElement custom-element registration pattern:

export const tag = 'fwc-button';

@fusionElement(tag)
export default class _ extends ButtonElement {}

with '_' is the 2nd export in this file, even though the file conceptually only exports one thing (the tag const purely parameterizes the default class). Verified identically across ~30 packages in fusion-web-components.

Also, the index.ts barrel exemption only applied when options.match was left unconfigured — any repo (like fusion-web-components) supplying its own match/ignorePatterns config lost that exemption and got flagged on every barrel file.

What

  • packages/linting/rules/src/single-export-per-file/index.ts:
    • Barrel files (index.ts, index.tsx, index.mts, index.cts) are now always exempt, ANDed with any options.match override rather than being replaced by it.
    • Added competingExports(): when a file has an export default class ... {}, companion top-level const/let exports are dropped from the competing-exports count before the one-symbol check runs.
  • Added regression tests, including the exact case from the issue that export class Foo {} + export default Foo; (re-export, not a genuine 2nd export) continues to report 0 violations, and that a genuinely competing export alongside the pattern still gets flagged.

Validation

  • npx vitest run packages/linting/rules/src/__tests__/single-export-per-file.test.ts — 19/19 passing.
  • pnpm exec biome lint + pnpm exec fusion-lint lint on both changed files — clean.
  • Added a changeset (patch for @equinor/fusion-framework-lint-rules).

…pattern

Fixes #5185

- Barrel exemption (index.ts/.tsx/.mts/.cts) now always applies, even when
  options.match overrides the matcher.
- A companion const/let (e.g. a tag string) that only parameterizes an
  export default class no longer counts as a competing export.
@odinr
odinr requested a review from a team as a code owner July 30, 2026 12:58
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 62f8cec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@equinor/fusion-framework-lint-rules Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the 🐞 bug Something isn't working label Jul 30, 2026
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 65.59% 3106 / 4735
🔵 Statements 65.01% 3732 / 5740
🔵 Functions 50.79% 1080 / 2126
🔵 Branches 55.17% 1706 / 3092
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/linting/rules/src/single-export-per-file/index.ts 96.22% 83.33% 100% 100% 129, 169
Generated in workflow #15035 for commit 62f8cec by the Vitest Coverage Report Action

@odinr
odinr merged commit 43183d8 into main Jul 30, 2026
9 checks passed
@odinr
odinr deleted the fix/single-export-per-file-fusion-element branch July 30, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fusion-lint: single-export-per-file flags the standard @fusionElement registration index.ts pattern

1 participant