refactor: simplify callee name checks and remove getPropertyName - #1905
Merged
Conversation
- Remove `Extract.getPropertyName`; member expression properties and object keys are now only matched when they are non-computed identifiers, so computed string/template-literal keys are no longer statically resolved. - Add `Extract.getCalleeName` and use it to unify `isHookCall`, `isUseEffectLikeCall` and `isUseStateLikeCall` in `@eslint-react/core`, replacing the duplicated local helper in the react-x `refs` rule. - Update affected rule tests and regenerate `@eslint-react/ast` docs.
Replace hand-rolled identifier/member-expression callee name checks with the new `Extract.getCalleeName` helper across packages and plugins. - Collapse duplicated Identifier/MemberExpression branches where the call form does not matter: `isJsxLike` in `@eslint-react/core`, `no-find-dom-node`, `no-flush-sync`, the `getCallKind` helpers of all six `no-leaked-*` rules in react-web-api, and `isHookDecl` in react-x `set-state-in-effect`. - Keep structural constraints (member call, receiver object) and simplify only the property name check: `isThisSetStateCall` and array `map`/`flatMap` callback detection in `@eslint-react/core`, static factory methods in `@eslint-react/var`, `ReactDOM.*` calls in `no-hydrate`/`no-render`/`no-render-return-value`/`no-use-form-state`, and `globals`, `immutability`, `no-array-index-key`, `no-duplicate-key`, `set-state-in-effect`/`set-state-in-render` in react-x. - `no-find-dom-node` and `no-flush-sync` now unwrap the callee, so calls wrapped in type assertions (e.g. `(findDOMNode as any)()`) are also detected. - `unsupported-syntax` (needs the `!computed` constraint), `require` detection, and `new (Intersection|Resize)Observer` checks are intentionally left unchanged since their semantics differ from `getCalleeName`. - Remove now-unused `AST_NODE_TYPES` imports.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract.getPropertyName; member expression properties and object keys are now only matched when they are non-computed identifiers, so computed string/template-literal keys are no longer statically resolved.Extract.getCalleeNameand use it to unifyisHookCall,isUseEffectLikeCallandisUseStateLikeCallin@eslint-react/core, replacing the duplicated local helper in the react-xrefsrule.@eslint-react/astdocs.Update "[ ]" to "[x]" to check a boxWhat kind of change does this PR introduce?
Check at least one. If you are introducing a new binding, you must reference an issue where this binding has been proposed, discussed and approved by the maintainers.
Does this PR introduce a breaking change?
If yes, please describe the impact and migration path for existing applications in an attached issue.
Checklist
fix: remove a typo, closes #___, #___)Other information