Skip to content

fix(eslint): preserve enum export and values in fixer#626

Open
Ocheretovich wants to merge 2 commits intoInjectiveLabs:devfrom
Ocheretovich:patch-1
Open

fix(eslint): preserve enum export and values in fixer#626
Ocheretovich wants to merge 2 commits intoInjectiveLabs:devfrom
Ocheretovich:patch-1

Conversation

@Ocheretovich
Copy link
Copy Markdown

@Ocheretovich Ocheretovich commented Mar 19, 2026

avoid exporting non-exported enums and preserve original member values

Summary by CodeRabbit

  • Bug Fixes
    • Enum conversion now preserves export keywords so exported and non-exported enums are handled correctly.
    • Generated enum member values retain their original name casing rather than being lowercased.
    • Conversion now targets the correct declaration form for exported enums, ensuring replacements apply to the intended code region.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f0cc07be-2a8e-48ae-b2a2-df48709847cb

📥 Commits

Reviewing files that changed from the base of the PR and between 897219b and 2592ea9.

📒 Files selected for processing (1)
  • scripts/eslint-rules/no-enum.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/eslint-rules/no-enum.js

📝 Walkthrough

Walkthrough

Flips export-keyword logic and adjusts replacement range for the enum-to-type+const fixer; also preserves original enum member key casing for generated const member values in scripts/eslint-rules/no-enum.js.

Changes

Cohort / File(s) Summary
ESLint rule: enum fixer
scripts/eslint-rules/no-enum.js
Reversed exportKeyword computation so exported enums get 'export ' and non-exported get ''; changed const member value generation from key.toLowerCase() to original key; when enum is exported replace parentNode range, otherwise replace node.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇
I hopped through enums, neat and spry,
Swapped export words and kept caps high,
I fixed the ranges, trimmed the fray,
Consts now sing the keys my way. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: preserving enum exports and values in the ESLint fixer, which directly aligns with the changeset modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

CodeRabbit can use your project's `biome` configuration to improve the quality of JS/TS/CSS/JSON code reviews.

Add a configuration file to your project to customize how CodeRabbit runs biome.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/eslint-rules/no-enum.js (1)

36-40: Fallback member value converts numeric enum semantics without detection.

Line 40 maps uninitialized enum members to string literals ('${key}'). In TypeScript, uninitialized enum members default to numeric values (0, 1, 2...), so this changes semantics from numeric to string enums. While this project enforces the rule to prevent all enum declarations, consider adding a comment or clarifying the intended behavior for cases where this rule might be applied elsewhere or if numeric enum detection becomes relevant.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/eslint-rules/no-enum.js` around lines 36 - 40, The current fallback
maps uninitialized enum members to string literals (`'${key}'`), which
incorrectly converts TypeScript numeric enum semantics to strings; update the
members mapping in the no-enum rule so that when member.initializer is absent it
preserves numeric semantics by computing the numeric value (start at 0 for the
first uninitialized member and increment from the previous numeric value), and
still use sourceCode.getText(member.initializer) when present; reference the
existing variables: node.members, member.id.name, member.initializer,
sourceCode.getText and maintain any existing formatting logic for non-numeric
initializers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/eslint-rules/no-enum.js`:
- Around line 31-33: The autofix currently prepends exportKeyword to
suggestedCode but then calls fixer.replaceText(node, suggestedCode) which
replaces only the TSEnumDeclaration and leaves the existing
ExportNamedDeclaration export token, producing duplicate "export export"; update
the fixer so that when isExported (computed from parentNode && parentNode.type
=== 'ExportNamedDeclaration') you call fixer.replaceText on parentNode instead
of node (i.e., replace the entire ExportNamedDeclaration), or alternatively
remove the exportKeyword from suggestedCode and keep replacing only node; adjust
the fixer.replaceText call accordingly and ensure symbols involved are
isExported, parentNode, exportKeyword, suggestedCode, fixer.replaceText, node,
TSEnumDeclaration, and ExportNamedDeclaration are used to locate the change.

---

Nitpick comments:
In `@scripts/eslint-rules/no-enum.js`:
- Around line 36-40: The current fallback maps uninitialized enum members to
string literals (`'${key}'`), which incorrectly converts TypeScript numeric enum
semantics to strings; update the members mapping in the no-enum rule so that
when member.initializer is absent it preserves numeric semantics by computing
the numeric value (start at 0 for the first uninitialized member and increment
from the previous numeric value), and still use
sourceCode.getText(member.initializer) when present; reference the existing
variables: node.members, member.id.name, member.initializer, sourceCode.getText
and maintain any existing formatting logic for non-numeric initializers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f41999d-7681-4cad-9140-bef6c558e797

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4b9f2 and 897219b.

📒 Files selected for processing (1)
  • scripts/eslint-rules/no-enum.js

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.

1 participant