-
-
Notifications
You must be signed in to change notification settings - Fork 800
refactor(linter): Add an is_inside convenience method
#18561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
connorshea
wants to merge
11
commits into
main
Choose a base branch
from
claude-is-inside-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
…ontext` Add two convenience methods to `LintContext` for the common pattern of checking if a node is inside a particular kind of AST node: - `is_inside(node_id, types)`: Check if any ancestor matches any of the provided `AstType`s - `is_inside_where(node_id, predicate)`: Check if any ancestor satisfies a custom predicate Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor `prefer_await_to_then` and `prefer_await_to_callbacks` rules to use the new `ctx.is_inside()` helper method, removing the local `is_inside_yield_or_await` helper functions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor rules to use the new `ctx.is_inside_where()` helper method for cleaner ancestor checking with custom predicates: - `no_var`, `vars_on_top`, `no_namespace`: Check for TypeScript ambient declarations - `state_in_constructor`: Check for ES6 components - `no_unsafe`: Check for ES5 components - `no_return_wrap`, `no_promise_in_callback`, `no_nesting`: Check for promise callbacks Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- `prefer_each`: Refactor `is_in_test` function - `no_conditional_in_test`: Refactor inline ancestor check - `require_local_test_context_for_concurrent_snapshots`: Refactor inline ancestor check Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…patterns - `no_unassigned_vars`: Use `is_inside` with parent_id instead of `.skip(1).any()` - `jsx_key`: Use `is_inside_where` with parent_id instead of `.skip(1).filter_map().any()` Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- `no_explicit_any`: Simplify `is_in_rest` function - `consistent_type_definitions`: Simplify `is_within_declare_global_block` function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…re instead. `is_inside` is the better name, and the list of types pattern wasn't really that useful in many places. So we can simplify it down to just the one method.
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.
This started as an exploration of adding an
is_insidemethod using Claude Code to see how much simpler it makes some of the linter code.is_insidetakes an AST node ID and a closure and then returns true or false based on the closure. The goal is to simplify a common pattern across the linter codebase for checking the ancestors of a given AST node.I think there are still more places where we could apply this pattern, but I had Claude go through a decent number of iterations already.
cc: @Boshen
AI Disclosure: Most of the exploration was done using Claude Code, obviously :) Then cleaned up by me afterward.