Skip to content

feat: port 4 @typescript-eslint non-null assertion rules#459

Merged
fansenze merged 7 commits intomainfrom
feat/port-rules-batch-20260205
Feb 6, 2026
Merged

feat: port 4 @typescript-eslint non-null assertion rules#459
fansenze merged 7 commits intomainfrom
feat/port-rules-batch-20260205

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Feb 5, 2026

Summary

Port 4 TypeScript-ESLint non-null assertion rules to rslint.

Rules ported

Rule Description Doc
@typescript-eslint/no-extra-non-null-assertion Disallow extra non-null assertions (auto-fixable) link
@typescript-eslint/no-non-null-asserted-nullish-coalescing Disallow non-null assertions in the left operand of ?? (with suggestions) link
@typescript-eslint/no-non-null-asserted-optional-chain Disallow non-null assertions after optional chain expressions (with suggestions) link
@typescript-eslint/no-non-null-assertion Disallow non-null assertions using ! (with optional chain suggestions) link

References

Checklist

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

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @fansenze, 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 significantly expands rslint's TypeScript linting capabilities by integrating four crucial rules from TypeScript-ESLint. These additions aim to improve the reliability and clarity of TypeScript codebases by identifying and discouraging potentially unsafe or redundant uses of non-null assertions. The new rules help developers write more idiomatic and type-safe TypeScript, reducing the likelihood of runtime errors related to null or undefined values.

Highlights

  • New Linting Rules Added: Four new TypeScript-ESLint non-null assertion rules have been ported to rslint to enhance code quality and type safety.
  • no-extra-non-null-assertion: This rule disallows redundant non-null assertions (e.g., foo!! or bar!?.n) and includes an auto-fix to remove the unnecessary ! operator.
  • no-non-null-asserted-nullish-coalescing: This rule flags non-null assertions used on the left-hand side of a nullish coalescing operator (??), as they are redundant and defeat the purpose of the operator. It provides suggestions for removal.
  • no-non-null-asserted-optional-chain: This rule prevents non-null assertions immediately following an optional chain expression (e.g., foo?.bar!), as optional chains are designed to return undefined and the assertion negates this safety. Suggestions are provided to remove the assertion.
  • no-non-null-assertion: This rule generally disallows the use of the ! non-null assertion operator, promoting more robust type-safe code. It offers suggestions to replace assertions with optional chaining (?.) where appropriate.
  • Comprehensive Testing and Documentation: Each new rule comes with dedicated Go implementation, Markdown documentation, and extensive test cases, including snapshot tests, to ensure correctness and provide clear usage guidelines.
Changelog
  • internal/config/config.go
    • Added imports for the four new TypeScript-ESLint rules.
    • Registered the new rules (no-extra-non-null-assertion, no-non-null-asserted-nullish-coalescing, no-non-null-asserted-optional-chain, no-non-null-assertion) in the global rule registry.
  • internal/plugins/typescript/rules/no_extra_non_null_assertion/no_extra_non_null_assertion.go
    • New file: Implemented the no-extra-non-null-assertion rule, which detects and provides auto-fixes for redundant non-null assertions.
  • internal/plugins/typescript/rules/no_extra_non_null_assertion/no_extra_non_null_assertion.md
    • New file: Added documentation for the no-extra-non-null-assertion rule, including examples of correct and incorrect usage.
  • internal/plugins/typescript/rules/no_extra_non_null_assertion/no_extra_non_null_assertion_test.go
    • New file: Added comprehensive test cases for the no-extra-non-null-assertion rule.
  • internal/plugins/typescript/rules/no_non_null_asserted_nullish_coalescing/no_non_null_asserted_nullish_coalescing.go
    • New file: Implemented the no-non-null-asserted-nullish-coalescing rule, which identifies and suggests removing non-null assertions before nullish coalescing operators.
  • internal/plugins/typescript/rules/no_non_null_asserted_nullish_coalescing/no_non_null_asserted_nullish_coalescing.md
    • New file: Added documentation for the no-non-null-asserted-nullish-coalescing rule, including examples.
  • internal/plugins/typescript/rules/no_non_null_asserted_nullish_coalescing/no_non_null_asserted_nullish_coalescing_test.go
    • New file: Added comprehensive test cases for the no-non-null-asserted-nullish-coalescing rule.
  • internal/plugins/typescript/rules/no_non_null_asserted_optional_chain/no_non_null_asserted_optional_chain.go
    • New file: Implemented the no-non-null-asserted-optional-chain rule, which detects and suggests removing non-null assertions after optional chain expressions.
  • internal/plugins/typescript/rules/no_non_null_asserted_optional_chain/no_non_null_asserted_optional_chain.md
    • New file: Added documentation for the no-non-null-asserted-optional_chain rule, including examples.
  • internal/plugins/typescript/rules/no_non_null_asserted_optional_chain/no_non_null_asserted_optional_chain_test.go
    • New file: Added comprehensive test cases for the no-non-null-asserted-optional_chain rule.
  • internal/plugins/typescript/rules/no_non_null_assertion/no_non_null_assertion.go
    • New file: Implemented the no-non-null-assertion rule, which disallows the use of the non-null assertion operator and provides optional chaining suggestions.
  • internal/plugins/typescript/rules/no_non_null_assertion/no_non_null_assertion.md
    • New file: Added documentation for the no-non-null-assertion rule, including examples.
  • internal/plugins/typescript/rules/no_non_null_assertion/no_non_null_assertion_test.go
    • New file: Added comprehensive test cases for the no-non-null-assertion rule.
  • packages/rslint-test-tools/rstest.config.mts
    • Enabled test files for the newly added TypeScript-ESLint rules.
  • packages/rslint-test-tools/tests/typescript-eslint/rules/snapshots/no-extra-non-null-assertion.test.ts.snap
    • New file: Added snapshot tests for no-extra-non-null-assertion.
  • packages/rslint-test-tools/tests/typescript-eslint/rules/snapshots/no-non-null-asserted-nullish-coalescing.test.ts.snap
    • New file: Added snapshot tests for no-non-null-asserted-nullish-coalescing.
  • packages/rslint-test-tools/tests/typescript-eslint/rules/snapshots/no-non-null-asserted-optional-chain.test.ts.snap
    • New file: Added snapshot tests for no-non-null-asserted-optional-chain.
  • packages/rslint-test-tools/tests/typescript-eslint/rules/snapshots/no-non-null-assertion.test.ts.snap
    • New file: Added snapshot tests for no-non-null-assertion.
Activity
  • The author has implemented four new TypeScript-ESLint rules related to non-null assertions.
  • New Go files were created for each rule's implementation, along with corresponding Markdown documentation and Go test files.
  • Snapshot test files were generated for each new rule to capture expected diagnostic outputs.
  • The rstest.config.mts file was updated to include the new test suites, ensuring they are run as part of the project's testing process.
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

@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 four non-null assertion related rules from TypeScript-ESLint to rslint. The implementation for each rule (no-extra-non-null-assertion, no-non-null-asserted-nullish-coalescing, no-non-null-asserted-optional-chain, no-non-null-assertion) is well-structured, including rule logic, documentation, and comprehensive test cases. The code is clear and seems to correctly implement the behavior of the original ESLint rules, including handling complex cases like control flow for unassigned variables and providing helpful suggestions for fixes. I've made one suggestion to refactor a small part of the code for better readability and maintainability. Overall, this is a great contribution.

@fansenze fansenze changed the title feat: port rules no-extra-non-null-assertion, no-non-null-asserted-nullish-coalescing, no-non-null-asserted-optional-chain, no-non-null-assertion feat: port 4 @typescript-eslint non-null assertion rules Feb 5, 2026
@fansenze fansenze force-pushed the feat/port-rules-batch-20260205 branch from 32aef7a to b79a695 Compare February 5, 2026 08:45
@fansenze fansenze force-pushed the feat/port-rules-batch-20260205 branch from b79a695 to a3b9a97 Compare February 5, 2026 08:59
@fansenze fansenze force-pushed the feat/port-rules-batch-20260205 branch from 5b014d4 to 20635c3 Compare February 5, 2026 09:38
@fansenze fansenze requested a review from hardfist February 6, 2026 02:30
@fansenze fansenze merged commit 8e76688 into main Feb 6, 2026
14 checks passed
@fansenze fansenze deleted the feat/port-rules-batch-20260205 branch February 6, 2026 03:26
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