@typescript-eslint/init-declarations#467
@typescript-eslint/init-declarations#467ScriptedAlchemy wants to merge 3 commits intoweb-infra-dev:mainfrom
Conversation
Co-authored-by: Zack Jackson <ScriptedAlchemy@users.noreply.github.com>
Co-authored-by: Zack Jackson <ScriptedAlchemy@users.noreply.github.com>
Co-authored-by: Zack Jackson <ScriptedAlchemy@users.noreply.github.com>
Summary of ChangesHello @ScriptedAlchemy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully ports the @typescript-eslint/init-declarations rule. The implementation in Go is clean and covers the necessary logic, including handling different modes (always/never), const declarations, for-loop initializers, and ambient contexts. The accompanying Go and TypeScript-based tests are comprehensive and validate the rule's behavior correctly.
I have one suggestion regarding unrelated changes included in this PR to keep the commit history clean. Overall, great work on this feature.
| { | ||
| "name": "no-extra-non-null-assertion", | ||
| "group": "@typescript-eslint", | ||
| "status": "full", | ||
| "failing_case": [] | ||
| }, |
There was a problem hiding this comment.
This change, along with the additions for no-non-null-asserted-nullish-coalescing, no-non-null-asserted-optional-chain, and no-non-null-assertion later in the file, appear to be unrelated to the implementation of the init-declarations rule. To keep pull requests focused on a single concern and maintain a clean commit history, it would be best to move these manifest updates to a separate PR.
There was a problem hiding this comment.
Pull request overview
Ports the @typescript-eslint/init-declarations rule into the TypeScript plugin and wires it into the existing TypeScript ESLint compatibility test harness.
Changes:
- Added the
init-declarationsrule implementation and a Go unit test suite. - Enabled the TypeScript ESLint rule-tester test for
init-declarationsand added the corresponding snapshot output. - Registered the rule in the global registry and updated the test-tools rule manifest (including some additional rule status updates).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
internal/plugins/typescript/rules/init_declarations/init_declarations.go |
New rule implementation, option parsing, ambient-context handling, and for-loop behaviors. |
internal/plugins/typescript/rules/init_declarations/init_declarations_test.go |
Adds a basic Go rule_tester suite for the new rule. |
internal/config/config.go |
Registers @typescript-eslint/init-declarations in the global registry. |
packages/rslint-test-tools/rstest.config.mts |
Enables the TypeScript ESLint compatibility test for init-declarations. |
packages/rslint-test-tools/tests/typescript-eslint/rules/__snapshots__/init-declarations.test.ts.snap |
Adds snapshot assertions for the rule-tester output. |
packages/rslint-test-tools/rule-manifest.json |
Marks init-declarations as full + updates statuses for several other TS-ESLint rules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| "name": "no-extra-non-null-assertion", | ||
| "group": "@typescript-eslint", | ||
| "status": "full", | ||
| "failing_case": [] | ||
| }, |
There was a problem hiding this comment.
The PR metadata/title/description are focused on porting init-declarations, but this manifest change also marks several non-null-assertion rules as full. If these status updates are intended, they should be called out in the PR description (or moved to a separate PR) to avoid surprising reviewers and to keep the change scoped.
| opts.IgnoreForLoopInit = ignore | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
parseOptions accepts any non-empty string for Mode. If a user misconfigures the rule (e.g. typo), the switch opts.Mode has no default branch, so the rule silently becomes a no-op. Consider validating Mode to only allow "always"/"never" and falling back to the default (or returning the default options) when an unsupported value is provided.
| // Validate Mode and fall back to the default when an unsupported value is provided. | |
| if opts.Mode != "always" && opts.Mode != "never" { | |
| opts.Mode = "always" | |
| } |
Summary
Ports the
@typescript-eslint/init-declarationsrule. This rule enforces or disallows initialization of variables in their declaration.Key features implemented:
alwaysandnevermodes.ignoreForLoopInitoption to bypass checks for variables declared inforloops.constdeclarations (exempted innevermode).declarestatements, declaration files).Related Links
Checklist
Made with Cursor