fix: fix rule behavior differences and refactor control flow analysis#495
fix: fix rule behavior differences and refactor control flow analysis#495
Conversation
Summary of ChangesHello, 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 resolves three distinct behavioral inconsistencies between Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces several fixes to align rule behaviors with ESLint, which is a great improvement. The changes for no-invalid-void-type and no-empty-function seem correct and well-tested. The control flow analysis for getter-return is a significant and much-needed rewrite.
I've left a couple of suggestions for minor refactoring to improve maintainability and correctness by reducing code duplication and using more specific AST helper methods. Overall, this is a solid contribution.
1781e0b to
3b0a81c
Compare
3b0a81c to
cb3f5b4
Compare
cb3f5b4 to
9ea1fca
Compare
- getter-return / array-callback-return / constructor-super: replace manual AST-based control flow analysis with shared utility using binder's NodeFlagsHasImplicitReturn, fixing try-catch false negatives - getter-return: skip arrow functions with expression bodies in property descriptors (e.g. `get: () => value`), matching ESLint's BlockStatement check - array-callback-return: fix false negative for mixed return-with-value and empty-return when allowImplicit is false (e.g. `if (a) return 1; else return;`) - no-unnecessary-boolean-literal-compare: fix options parsing from JSON config, fix isNullableBoolean to reject unions with non-boolean/non-nullable members - Add shared FunctionReturnAnalysis utility with tests - Update rule documentation with missing options - Enable no-unnecessary-boolean-literal-compare TS test suite
9ea1fca to
d507bc9
Compare
Summary
Fix rule behavior differences between rslint and ESLint/typescript-eslint, and refactor control flow analysis into a shared utility.
Rule Fixes
1.
no-invalid-void-type— callable/construct signaturesvoidas return type in callable and construct signatures was incorrectly flagged. AddedCallSignatureandConstructSignatureto the valid context whitelist, matching typescript-eslint behavior.2.
no-empty-function— functions with commentsFunctions containing only comments (e.g.
function foo() { /* TODO */ }) were incorrectly reported as empty. Added comment detection to check for//and/*in function bodies.3.
getter-return— throw statements, control flow, and arrow expression bodiesfinally { return; }overriding try block returns was not detected.get: () => value) were incorrectly flagged as missing a return. ESLint only checks getters withBlockStatementbodies.rule.CreateRule()incorrectly prepending@typescript-eslint/prefix to core ESLint rule names.4.
array-callback-return— mixed return-with-value and empty-returnWhen
allowImplicitis false (default), callbacks mixingreturn value;andreturn;on different branches (e.g.if (a) return 1; else return;) were not flagged. FixedallPathsReturnlogic to require all return statements to have values whenallowImplicitis disabled.5.
no-unnecessary-boolean-literal-compare— options parsing and type checking[]interface{}/map[string]interface{}). Added JSON marshal/unmarshal fallback.isNullableBooleandid not verify that a union type contains only boolean and nullable members, causing false positives for types likeboolean | string | null. Fixed to reject unions with non-boolean/non-nullable members.Control Flow Refactor
Replaced ~500 lines of hand-written control flow analysis across
getter-return,array-callback-return, andconstructor-superwith a shared utility (internal/utils/flow.go) that leverages the binder'sNodeFlagsHasImplicitReturnflag andForEachReturnStatement.AnalyzeFunctionReturns(node)— returnsEndReachable,HasReturnWithValue,HasEmptyReturnIsFunctionEndReachable(node)— checks if function end is reachableThis also fixes
array-callback-returnincorrectly treatingtry { return x; } catch(e) {}as valid (catch falls through without returning).Related Links
getter-return: https://eslint.org/docs/latest/rules/getter-returnarray-callback-return: https://eslint.org/docs/latest/rules/array-callback-returnno-invalid-void-type: https://typescript-eslint.io/rules/no-invalid-void-typeno-empty-function: https://typescript-eslint.io/rules/no-empty-functionno-unnecessary-boolean-literal-compare: https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compareChecklist