Skip to content

feat: port rule no-unreachable#517

Open
fansenze wants to merge 1 commit intomainfrom
feat/port-rule-no-unreachable-20260317
Open

feat: port rule no-unreachable#517
fansenze wants to merge 1 commit intomainfrom
feat/port-rule-no-unreachable-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

Port the no-unreachable rule from ESLint to rslint.

Disallow unreachable code after return, throw, continue, and break statements

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, no-unreachable, to the rslint project. This rule aims to improve code quality by identifying and flagging code segments that are logically impossible to reach during execution. By preventing dead code, it helps developers maintain cleaner, more efficient, and less error-prone codebases, aligning rslint's capabilities with established best practices from ESLint.

Highlights

  • New Linting Rule: Introduced the no-unreachable rule, ported from ESLint, to detect and disallow code that cannot be executed after terminal statements.
  • Unreachable Code Detection: The rule identifies code following return, throw, break, and continue statements as unreachable.
  • Hoisting and Exceptions: Implemented logic to correctly account for JavaScript hoisting, allowing function declarations and var declarations without initializers after terminal statements, while reporting let, const, and class declarations.
  • Comprehensive Testing: Added extensive unit tests and ESLint-style test cases, including snapshot tests, to ensure the rule's accuracy and coverage.
Changelog
  • internal/config/config.go
    • Imported and registered the new no-unreachable rule within the rslint configuration.
  • internal/rules/no_unreachable/no_unreachable.go
    • Implemented the core logic for the no-unreachable rule, including functions to identify terminal statements and handle hoisted or empty statements.
  • internal/rules/no_unreachable/no_unreachable.md
    • Added detailed documentation for the no-unreachable rule, including examples of correct and incorrect code.
  • internal/rules/no_unreachable/no_unreachable_test.go
    • Added comprehensive Go unit tests for the no-unreachable rule, covering various valid and invalid code scenarios.
  • packages/rslint-test-tools/rstest.config.mts
    • Updated the test configuration to include the new no-unreachable rule's test files.
  • packages/rslint-test-tools/tests/eslint/rules/snapshots/no-unreachable.test.ts.snap
    • Generated snapshot test results for the no-unreachable rule's ESLint-style tests.
  • packages/rslint-test-tools/tests/eslint/rules/no-unreachable.test.ts
    • Added ESLint-style test cases for the no-unreachable rule.
Activity
  • The author, fansenze, created the pull request to port the no-unreachable rule.
  • The author marked the tests and documentation as updated/not required in the checklist.
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-unreachable rule from ESLint to rslint. The implementation is solid, with good test coverage and documentation. I've found a couple of areas for improvement: one is to refactor some duplicated code in the rule implementation for better maintainability, and the other is to remove a redundant test file entry in the configuration to avoid running tests twice. Overall, great work on porting the rule.

@fansenze fansenze force-pushed the feat/port-rule-no-unreachable-20260317 branch 2 times, most recently from 1f020ad to c073be5 Compare March 17, 2026 10:29
@fansenze fansenze force-pushed the feat/port-rule-no-unreachable-20260317 branch 4 times, most recently from 033a328 to 9181cd9 Compare March 18, 2026 02:44
@fansenze fansenze force-pushed the feat/port-rule-no-unreachable-20260317 branch from 9181cd9 to 6557a98 Compare March 18, 2026 02:58
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.

1 participant