Skip to content

feat: port rule no-inner-declarations#535

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

feat: port rule no-inner-declarations#535
chenjiahan merged 1 commit intomainfrom
feat/port-rule-no-inner-declarations-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

Port the no-inner-declarations rule from ESLint to rslint.

Disallow variable or function declarations in nested blocks

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 integrates the no-inner-declarations rule into rslint, enhancing its static analysis capabilities. The rule aims to improve code clarity and prevent common scoping pitfalls by flagging function and optionally var declarations that appear within nested blocks, ensuring they are declared at appropriate root levels.

Highlights

  • New Rule: no-inner-declarations: The no-inner-declarations rule has been ported from ESLint to rslint. This rule disallows function declarations in nested blocks by default.
  • Configurable var declaration checks: An option has been added to also disallow var declarations in nested blocks, aligning with the original ESLint rule's functionality.
  • Comprehensive Testing and Documentation: The new rule includes dedicated Go unit tests, TypeScript-based rule tester examples, snapshot tests, and detailed markdown documentation.
Changelog
  • internal/config/config.go
    • Imported the no_inner_declarations package.
    • Registered the no-inner-declarations rule in the global rule registry.
  • internal/rules/no_inner_declarations/no_inner_declarations.go
    • Implemented the core logic for the no-inner-declarations rule.
    • Added functions to parse rule options, validate parent nodes, and determine the nearest function scope.
    • Defined the rule to report function declarations in invalid nested contexts and optionally var declarations.
  • internal/rules/no_inner_declarations/no_inner_declarations.md
    • Added comprehensive documentation for the no-inner-declarations rule.
    • Included rule details, examples of correct and incorrect code, and descriptions of the available options ("functions" and "both").
  • internal/rules/no_inner_declarations/no_inner_declarations_test.go
    • Implemented Go-based unit tests for the no-inner-declarations rule.
    • Covered various valid and invalid test cases, including scenarios for both default ("functions") and "both" options.
  • packages/rslint-test-tools/rstest.config.mts
    • Updated the rslint test configuration to include the new no-inner-declarations.test.ts file.
  • packages/rslint-test-tools/tests/eslint/rules/snapshots/no-inner-declarations.test.ts.snap
    • Generated snapshot tests for the no-inner-declarations rule's diagnostic output.
  • packages/rslint-test-tools/tests/eslint/rules/no-inner-declarations.test.ts
    • Created a TypeScript-based rule tester file for the no-inner-declarations rule.
    • Defined valid and invalid code snippets to verify the rule's behavior.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request 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-inner-declarations rule from ESLint. The implementation is well-structured and includes comprehensive tests for both valid and invalid cases, covering different rule options. The documentation is also clear and provides good examples. I have one suggestion to simplify the option parsing logic for better maintainability, but overall this is a great contribution.

Comment thread internal/rules/no_inner_declarations/no_inner_declarations.go Outdated
@fansenze fansenze force-pushed the feat/port-rule-no-inner-declarations-20260317 branch from ad11e25 to 2e5635d Compare March 17, 2026 11:34
@fansenze fansenze force-pushed the feat/port-rule-no-inner-declarations-20260317 branch 3 times, most recently from abbf6ab to 2486736 Compare March 18, 2026 03:19
@fansenze fansenze force-pushed the feat/port-rule-no-inner-declarations-20260317 branch 4 times, most recently from 3f16f23 to a246092 Compare April 1, 2026 11:24
@fansenze fansenze force-pushed the feat/port-rule-no-inner-declarations-20260317 branch from a246092 to 67dc1de Compare April 1, 2026 11:43
@chenjiahan chenjiahan merged commit 593265e into main Apr 2, 2026
10 checks passed
@chenjiahan chenjiahan deleted the feat/port-rule-no-inner-declarations-20260317 branch April 2, 2026 02:40
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