-
-
Notifications
You must be signed in to change notification settings - Fork 67
doc: add a JS example of find(napiConfig)
#647
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe pull request enhances the JavaScript API documentation for ast-grep, focusing on the Changes
Sequence DiagramsequenceDiagram
participant User
participant SgNode
participant Edit
User->>SgNode: find nodes
SgNode-->>User: return matching nodes
User->>SgNode: replace(text)
SgNode->>Edit: create Edit
User->>SgNode: commitEdits(edits)
SgNode-->>User: return modified code
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
website/guide/api-usage/js-api.md (2)
14-22: Consider adding yarn installation instructions.The installation section nicely uses code groups to show npm and pnpm commands. Consider adding yarn for completeness:
::: code-group ```bash[npm] npm install --save @ast-grep/napipnpm add @ast-grep/napi
+
bash[yarn] +yarn add @ast-grep/napi +:::
--- `139-148`: **Add explanation for the constraints object.** While the example demonstrates `NapiConfig` usage, it would be helpful to explain: 1. The purpose and structure of the `constraints` object 2. Available constraint types besides `regex` 3. How the constraint `{ regex: "hello" }` affects the pattern matching Consider adding a brief explanation before the example: ```diff +// The constraints object allows you to add additional matching criteria +// for meta variables. In this example, we ensure that the argument ($A) +// contains the word "hello" using a regex constraint. const node = root.find({ rule: { pattern: "console.log($A)", }, constraints: { A: { regex: "hello" } } });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
website/guide/api-usage/js-api.md(3 hunks)
🔇 Additional comments (1)
website/guide/api-usage/js-api.md (1)
30-30: Great addition of core concepts!The clear listing of main classes and the jQuery analogy make the API more approachable for JavaScript developers.
HerringtonDarkholme
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
based on the Python example
Summary by CodeRabbit
@ast-grep/napi.SgRootandSgNodeclasses.NapiConfig, node traversal, and code fixing techniques.replaceandcommitEdits.