fix(eslint): preserve enum export and values in fixer#626
fix(eslint): preserve enum export and values in fixer#626Ocheretovich wants to merge 2 commits intoInjectiveLabs:devfrom
Conversation
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughFlips 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 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
scripts/eslint-rules/no-enum.js
avoid exporting non-exported enums and preserve original member values
Summary by CodeRabbit