Skip to content

feat: port rule no-import-assign#536

Merged
fansenze merged 1 commit intomainfrom
feat/port-rule-no-import-assign-20260317
Apr 1, 2026
Merged

feat: port rule no-import-assign#536
fansenze merged 1 commit intomainfrom
feat/port-rule-no-import-assign-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

Port the no-import-assign rule from ESLint to rslint.

Disallow assigning to imported bindings

Related Links

Checklist

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

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 a new static analysis rule to enforce the immutability of imported module bindings. By preventing reassignments to imports, it helps developers avoid common pitfalls and ensures code adheres to module semantics, leading to more predictable and maintainable JavaScript/TypeScript codebases. The addition enhances rslint's capability to catch potential runtime errors related to module imports.

Highlights

  • New Linting Rule: no-import-assign: A new linting rule, no-import-assign, has been ported from ESLint to rslint. This rule prevents accidental reassignments to imported bindings, ensuring that imports remain read-only as per ECMAScript module specifications.
  • Comprehensive Write Reference Detection: The implementation includes robust utility functions to detect various forms of write references, such as direct assignments, compound assignments, increment/decrement operations, destructuring assignments, and delete operations on namespace import members.
  • Full Test Coverage and Documentation: The new rule comes with dedicated Go-based unit tests and TypeScript-based integration tests, along with clear documentation explaining its purpose, rule details, and examples of correct and incorrect code usage.
Changelog
  • internal/config/config.go
    • Imported the new no_import_assign rule package.
    • Registered the no-import-assign rule within the global rule registry.
  • internal/rules/no_import_assign/no_import_assign.go
    • Added the core implementation for the no-import-assign rule.
    • Defined logic to identify default, named, and namespace imports.
    • Implemented AST traversal to detect write references to imported bindings, including direct assignments and member writes for namespace imports.
  • internal/rules/no_import_assign/no_import_assign.md
    • Created documentation for the no-import-assign rule.
    • Provided rule details, examples of incorrect and correct code, and a link to the original ESLint documentation.
  • internal/rules/no_import_assign/no_import_assign_test.go
    • Added Go-based unit tests for the no-import-assign rule.
    • Included test cases for valid and invalid scenarios covering different import types and assignment patterns.
  • internal/utils/write_reference.go
    • Introduced new utility functions IsWriteReference, IsBindingPatternInAssignment, and IsInDestructuringAssignment.
    • These functions provide comprehensive checks for various types of write operations on AST nodes, supporting the no-import-assign rule and potentially other future rules.
  • packages/rslint-test-tools/rstest.config.mts
    • Updated the test configuration to include the new no-import-assign.test.ts file.
  • packages/rslint-test-tools/tests/eslint/rules/snapshots/no-import-assign.test.ts.snap
    • Generated snapshot tests for the no-import-assign rule, capturing expected diagnostic outputs for invalid code examples.
  • packages/rslint-test-tools/tests/eslint/rules/no-import-assign.test.ts
    • Added TypeScript-based integration tests for the no-import-assign rule using RuleTester.
Activity
  • The pull request was created by fansenze.
  • No specific review comments or activity have been recorded yet.
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
Copy Markdown
Contributor

@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 ports the no-import-assign rule from ESLint, which is a great addition. The implementation is mostly solid, including a new write_reference utility that seems quite robust. However, I've identified a few areas for improvement. The core rule logic in isMemberWrite is missing some checks from the original ESLint rule, there's some code duplication that could be refactored, and the test suite could be more comprehensive to cover all edge cases. Please see my detailed comments.

Comment thread internal/rules/no_import_assign/no_import_assign.go Outdated
Comment thread internal/rules/no_import_assign/no_import_assign.go
Comment thread internal/rules/no_import_assign/no_import_assign_test.go
@fansenze fansenze force-pushed the feat/port-rule-no-import-assign-20260317 branch 2 times, most recently from 46750a4 to 7bad4e1 Compare March 17, 2026 11:34
@fansenze fansenze force-pushed the feat/port-rule-no-import-assign-20260317 branch 3 times, most recently from 93b5dc1 to e7496b3 Compare March 18, 2026 03:47
@fansenze fansenze force-pushed the feat/port-rule-no-import-assign-20260317 branch from e7496b3 to a81d97e Compare April 1, 2026 07:36
@fansenze fansenze force-pushed the feat/port-rule-no-import-assign-20260317 branch from a81d97e to 6184d37 Compare April 1, 2026 07:41
@fansenze fansenze merged commit d7cf187 into main Apr 1, 2026
10 checks passed
@fansenze fansenze deleted the feat/port-rule-no-import-assign-20260317 branch April 1, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants