Skip to content

feat: port rule no-func-assign#533

Merged
chenjiahan merged 1 commit intomainfrom
feat/port-rule-no-func-assign-20260317
Apr 2, 2026
Merged

feat: port rule no-func-assign#533
chenjiahan merged 1 commit intomainfrom
feat/port-rule-no-func-assign-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

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

Disallow reassigning function declarations

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 the no-func-assign linting rule, ported from ESLint, to rslint. This rule helps maintain code integrity by preventing the reassignment of function declarations, which can lead to unexpected behavior and bugs. The implementation includes robust AST traversal and symbol resolution to correctly identify and flag such reassignments, while also accounting for legitimate shadowing cases. This addition enhances rslint's ability to catch common JavaScript programming errors related to function declarations.

Highlights

  • New Linting Rule: Implemented the no-func-assign rule, which disallows reassigning function declarations to prevent unexpected behavior and bugs.
  • Robust Reassignment Detection: Developed comprehensive logic to identify various forms of reassignment, including direct assignments, compound assignments, increment/decrement operations, and destructuring assignments, while correctly handling variable shadowing.
  • Core Integration and Utilities: Integrated the new rule into the rslint configuration and introduced new utility functions in internal/utils/write_reference.go to accurately determine if an Abstract Syntax Tree (AST) node represents a write reference.
  • Documentation and Testing: Provided dedicated documentation (no_func_assign.md) with examples and comprehensive Go-based unit tests (no_func_assign_test.go), along with RuleTester based tests and snapshots, to ensure the rule's correctness and coverage.
Changelog
  • internal/config/config.go
    • Imported the no_func_assign rule package.
    • Registered the no-func-assign rule with the global rule registry.
  • internal/rules/no_func_assign/no_func_assign.go
    • Added a new rule implementation for no-func-assign.
    • Included helper functions for identifier name extraction, symbol resolution, shadowing checks, and reassignment detection.
    • Defined the NoFuncAssignRule with listeners for ast.KindFunctionDeclaration and ast.KindFunctionExpression to detect reassignments.
  • internal/rules/no_func_assign/no_func_assign.md
    • Added documentation for the no-func-assign rule, including its purpose, incorrect, and correct code examples.
    • Provided a link to the original ESLint documentation.
  • internal/rules/no_func_assign/no_func_assign_test.go
    • Added Go-based unit tests for the no-func-assign rule, covering both valid and invalid code scenarios.
  • internal/utils/write_reference.go
    • Added a new utility file containing IsWriteReference, IsBindingPatternInAssignment, and IsInDestructuringAssignment functions to identify various types of write operations on AST nodes.
  • packages/rslint-test-tools/rstest.config.mts
    • Updated the test configuration to include the new no-func-assign.test.ts file.
  • packages/rslint-test-tools/tests/eslint/rules/snapshots/no-func-assign.test.ts.snap
    • Added snapshot test results for the no-func-assign rule's invalid cases.
  • packages/rslint-test-tools/tests/eslint/rules/no-func-assign.test.ts
    • Added a new JavaScript/TypeScript test file for the no-func-assign rule using the RuleTester framework.
Activity
  • The author has completed the implementation, documentation, and testing for the new rule, as indicated by the checklist in the pull request description.
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 successfully ports the no-func-assign rule from ESLint. The implementation is comprehensive, covering function declarations and named function expressions, and correctly handling shadowing. The addition of the IsWriteReference utility is a good, reusable component. The tests and documentation are also well-written. I've made a couple of suggestions to improve code readability and maintainability in the rule implementation. Overall, this is a solid contribution.

Comment thread internal/rules/no_func_assign/no_func_assign.go Outdated
Comment thread internal/rules/no_func_assign/no_func_assign.go Outdated
@fansenze fansenze force-pushed the feat/port-rule-no-func-assign-20260317 branch from 0e27473 to 47c28ba Compare March 17, 2026 11:33
@fansenze fansenze force-pushed the feat/port-rule-no-func-assign-20260317 branch 2 times, most recently from 199bee2 to 0316060 Compare March 18, 2026 03:02
@fansenze fansenze force-pushed the feat/port-rule-no-func-assign-20260317 branch from 0316060 to 1ede901 Compare April 2, 2026 05:41
@fansenze fansenze force-pushed the feat/port-rule-no-func-assign-20260317 branch from 1ede901 to 09d5101 Compare April 2, 2026 05:43
@chenjiahan chenjiahan merged commit a3be846 into main Apr 2, 2026
10 checks passed
@chenjiahan chenjiahan deleted the feat/port-rule-no-func-assign-20260317 branch April 2, 2026 07:38
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