Skip to content

@typescript-eslint/init-declarations#467

Open
ScriptedAlchemy wants to merge 3 commits intoweb-infra-dev:mainfrom
ScriptedAlchemy:cursor/typescript-init-declarations-65ef
Open

@typescript-eslint/init-declarations#467
ScriptedAlchemy wants to merge 3 commits intoweb-infra-dev:mainfrom
ScriptedAlchemy:cursor/typescript-init-declarations-65ef

Conversation

@ScriptedAlchemy
Copy link
Contributor

Summary

Ports the @typescript-eslint/init-declarations rule. This rule enforces or disallows initialization of variables in their declaration.

Key features implemented:

  • Supports always and never modes.
  • Includes the ignoreForLoopInit option to bypass checks for variables declared in for loops.
  • Correctly handles const declarations (exempted in never mode).
  • Accounts for ambient contexts (e.g., declare statements, declaration files).
  • Registers the rule and integrates with the existing TypeScript ESLint test suite.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

\"Open \"Open

Made with Cursor

cursoragent and others added 3 commits February 8, 2026 23:57
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>
Copilot AI review requested due to automatic review settings February 9, 2026 07:59
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 @typescript-eslint/init-declarations rule, enhancing code quality by enforcing consistent variable initialization practices. It provides flexible configuration options to suit different coding styles and correctly handles various TypeScript-specific contexts, ensuring robust linting behavior.

Highlights

  • New Rule Implementation: Ports the @typescript-eslint/init-declarations rule, which enforces or disallows initialization of variables in their declaration.
  • Configuration Options: Supports always and never modes, and includes an ignoreForLoopInit option to bypass checks for variables declared in for loops.
  • Contextual Handling: Correctly handles const declarations (exempted in never mode) and accounts for ambient contexts (e.g., declare statements, declaration files).
  • Integration: The new rule is registered and integrated with the existing TypeScript ESLint test suite.
Changelog
  • internal/config/config.go
    • Added import for the new init_declarations rule.
    • Registered the @typescript-eslint/init-declarations rule in the global rule registry.
  • internal/plugins/typescript/rules/init_declarations/init_declarations.go
    • Added a new file implementing the core logic for the init-declarations rule.
    • Implemented parseOptions to handle rule configuration, including mode (always/never) and ignoreForLoopInit.
    • Included helper functions for generating rule messages (buildInitializedMessage, buildNotInitializedMessage).
    • Developed utility functions to extract declaration names (getDeclarationNameText), check for const declarations (isConstDeclaration), identify for loop declarations (getForLoopKind), and determine ambient contexts (isInAmbientContext).
    • Defined the InitDeclarationsRule with a Run function that traverses AST nodes of type VariableDeclaration and applies the rule logic based on configured options.
  • internal/plugins/typescript/rules/init_declarations/init_declarations_test.go
    • Added a new file containing comprehensive unit tests for the init-declarations rule.
    • Included ValidTestCase examples for scenarios where the rule should not report errors (e.g., initialized variables in always mode, uninitialized in never mode, const in never mode, ignored for loops, ambient declarations).
    • Provided InvalidTestCase examples to verify that the rule correctly reports errors for uninitialized variables in always mode, initialized variables in never mode, and specific for loop cases.
  • packages/rslint-test-tools/rstest.config.mts
    • Enabled the init-declarations.test.ts entry in the test configuration to include it in the test suite.
  • packages/rslint-test-tools/rule-manifest.json
    • Added the init-declarations rule to the rule manifest with a 'full' status.
    • Added no-extra-non-null-assertion rule to the manifest with 'full' status.
    • Added no-non-null-asserted-nullish-coalescing rule to the manifest with 'full' status.
    • Added no-non-null-asserted-optional-chain rule to the manifest with 'full' status.
    • Added no-non-null-assertion rule to the manifest with 'full' status.
Activity
  • The pull request was created by ScriptedAlchemy.
  • The author provided a detailed summary of the rule's features and related links.
  • The author confirmed that tests were updated as part of the changes.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +246 to +251
{
"name": "no-extra-non-null-assertion",
"group": "@typescript-eslint",
"status": "full",
"failing_case": []
},

Choose a reason for hiding this comment

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

medium

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-declarations rule implementation and a Go unit test suite.
  • Enabled the TypeScript ESLint rule-tester test for init-declarations and 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.

Comment on lines +246 to +251
{
"name": "no-extra-non-null-assertion",
"group": "@typescript-eslint",
"status": "full",
"failing_case": []
},
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
opts.IgnoreForLoopInit = ignore
}
}

Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// Validate Mode and fall back to the default when an unsupported value is provided.
if opts.Mode != "always" && opts.Mode != "never" {
opts.Mode = "always"
}

Copilot uses AI. Check for mistakes.
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