Skip to content

✨ HTML #51

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

Merged
merged 3 commits into from
Apr 5, 2025
Merged

✨ HTML #51

merged 3 commits into from
Apr 5, 2025

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a new package @ast-grep/lang-html for HTML language support and parsing.
    • Added a LanguageRegistration type and a registration constant for dynamic language registration.
  • Documentation
    • Included a README file with detailed installation and usage instructions for the @ast-grep/lang-html package.
  • Tests
    • Set up a testing environment for HTML parsing, validating functionality through sample HTML tests.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request introduces a new package, @ast-grep/lang-html, to support HTML in the ast-grep framework. A changeset entry documents the update, and a README provides installation and usage instructions. The package implementation includes type definitions, a module exporting language registration details, a testing setup using the nursery framework, package metadata in a package.json file, and a post-installation script that invokes setup routines.

Changes

File(s) Change Summary
.changeset/quick-pillows-find.md Added a patch entry for package @ast-grep/lang-html.
packages/html/README.md Introduced README with installation commands and usage instructions for HTML language support.
packages/html/index.d.ts, packages/html/index.js Added type definition and module exporting language registration details (e.g., libraryPath, etc.).
packages/html/nursery.js, packages/html/package.json, packages/html/postinstall.js Added testing setup, package metadata, and a post-install script to configure the HTML parser.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as "CLI Install"
  participant PI as "postinstall.js"
  participant Setup as "@ast-grep/setup-lang"
  participant HG as "@ast-grep/lang-html"

  CLI->>PI: Execute installation
  PI->>Setup: Call postinstall({ dirname })
  Setup->>HG: Register HTML language
Loading
sequenceDiagram
  participant Tester
  participant Nursery as "nursery.js"
  participant Parser as "HTML Parser"

  Tester->>Nursery: Run HTML parsing test
  Nursery->>Parser: Parse sample HTML string
  Parser-->>Nursery: Return syntax tree
  Nursery->>Tester: Confirm 'element' node found
Loading

Suggested reviewers

  • HerringtonDarkholme

Poem

I'm a rabbit darting through code trails bright,
Hoping through changes with agile delight.
New HTML paths, registrations, and tests align,
Byte by byte, each change sings like fine wine.
With leaps and bounds, our code takes flight! 🐇
Cheers to the magic in every commit light!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b965bca and b8579fa.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/quick-pillows-find.md (1 hunks)
  • packages/html/README.md (1 hunks)
  • packages/html/index.d.ts (1 hunks)
  • packages/html/index.js (1 hunks)
  • packages/html/nursery.js (1 hunks)
  • packages/html/package.json (1 hunks)
  • packages/html/postinstall.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • .changeset/quick-pillows-find.md
  • packages/html/postinstall.js
  • packages/html/index.d.ts
  • packages/html/README.md
  • packages/html/index.js
  • packages/html/package.json
  • packages/html/nursery.js

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (6)
.changeset/quick-pillows-find.md (1)

5-5: Enhance the changeset description

The current description "Add @ast-grep/lang-html" is minimal. Consider providing more context about what this HTML language support enables for ast-grep users.

-Add @ast-grep/lang-html
+Add @ast-grep/lang-html package for HTML language parsing and pattern matching support
packages/html/README.md (3)

7-12: Consider adding instructions for npm and yarn users

The installation instructions currently only mention pnpm. Consider adding equivalent commands for npm and yarn users to make the package more accessible.

 ```bash
+# Using pnpm
 pnpm install @ast-grep/lang-html
 pnpm install @ast-grep/napi
 # install the tree-sitter-cli if no prebuild is available
 pnpm install @tree-sitter/cli --save-dev
+
+# Using npm
+npm install @ast-grep/lang-html
+npm install @ast-grep/napi
+# install the tree-sitter-cli if no prebuild is available
+npm install @tree-sitter/cli --save-dev
+
+# Using yarn
+yarn add @ast-grep/lang-html
+yarn add @ast-grep/napi
+# install the tree-sitter-cli if no prebuild is available
+yarn add @tree-sitter/cli --dev

---

`16-24`: **Enhance usage example with a realistic HTML snippet**

The current example uses a placeholder string (`"your code"`) for parsing. Consider using a simple but realistic HTML snippet to demonstrate the parser's capabilities and what users can expect from the output.

```diff
 ```js
 import html from '@ast-grep/lang-html'
 import { registerDynamicLanguage, parse } from '@ast-grep/napi'

 registerDynamicLanguage({ html })

-const sg = parse('html', `your code`)
-sg.root().kind()
+// Parse a simple HTML snippet
+const sg = parse('html', `<div class="container"><p>Hello World</p></div>`)
+
+// Get the root node kind
+const rootKind = sg.root().kind()
+console.log('Root node kind:', rootKind)
+
+// Example of traversing the HTML structure
+const paragraphs = sg.root().findAll('tag_name: p')
+console.log('Found paragraphs:', paragraphs.length)

---

`1-25`: **Add explanation about tree-sitter integration**

The README doesn't explain the relationship with tree-sitter or why the CLI might be needed. Consider adding a brief explanation about how ast-grep uses tree-sitter for parsing HTML.


Add a section after the Installation section:

```markdown
## About

This package provides HTML language support for ast-grep using tree-sitter. The tree-sitter parser allows ast-grep to understand and query HTML syntax trees, enabling powerful pattern matching and code transformation capabilities for HTML files.

If no prebuilt binaries are available for your platform, the `@tree-sitter/cli` package is required to build the parser locally during installation.
packages/html/package.json (2)

4-4: Add a descriptive package description.

The description field is currently empty. Adding a clear description will help users understand the purpose of this package when viewing it on npm or GitHub.

-  "description": "",
+  "description": "HTML language support for ast-grep",

22-23:

❓ Verification inconclusive

Consider adding author information and using a more specific license.

The author field is empty, and ISC license is used. Consider:

  1. Adding author information (e.g., "ast-grep team" or individual contributors)
  2. Using the same license as other ast-grep packages for consistency
-  "author": "",
-  "license": "ISC",
+  "author": "ast-grep team",
+  "license": "MIT",

🏁 Script executed:

#!/bin/bash
# Check what license other ast-grep packages use
fd "package.json" --type f --path packages | xargs grep -l "\"license\":" | xargs grep "\"license\":"

Length of output: 331


Below is a new shell script to verify the license and author fields in all package.json files under the packages directory. The previous command failed due to an invalid flag; this version omits the problematic argument:

Action:
The review comment recommends updating packages/html/package.json by adding an author (e.g., "ast-grep team") and switching from the ISC license to MIT (to match other ast-grep packages). Please run the above script manually to verify the values used in the other packages. Once you confirm whether those files indeed use "author": "ast-grep team" and "license": "MIT", we can finalize the update.


🏁 Script executed:

#!/bin/bash
# Check license and author entries in all package.json files under the packages directory
fd "package.json" --type f packages | while read file; do
  echo "==> $file"
  grep '"author":' "$file"
  grep '"license":' "$file"
done

Length of output: 2077


Action Required: Confirm Consistent Package Metadata Updates
In packages/html/package.json, the author field is empty and the license is set to "ISC", which is consistent with all other packages (see output from Angular, C, C++, C#, Go, Python, SQL, and TOML packages). The original suggestion to change these values to "ast-grep team" and "MIT" would introduce inconsistency unless the entire repository is updated.

  • Recommendation:
    • Either update all package.json files across the repository to use:

      • "author": "ast-grep team"
      • "license": "MIT"

      Diff snippet (if updating all):

      -  "author": "",
      -  "license": "ISC",
      +  "author": "ast-grep team",
      +  "license": "MIT",
    • Or retain the current settings for consistency, and consider addressing author information in a separate, comprehensive update.

Please verify the intended repository-wide metadata strategy and update accordingly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7a802d and 812f14a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/quick-pillows-find.md (1 hunks)
  • packages/html/README.md (1 hunks)
  • packages/html/index.d.ts (1 hunks)
  • packages/html/index.js (1 hunks)
  • packages/html/nursery.js (1 hunks)
  • packages/html/package.json (1 hunks)
  • packages/html/postinstall.js (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/html/postinstall.js (1)
packages/html/nursery.js (1)
  • require (1-1)
🔇 Additional comments (8)
packages/html/postinstall.js (1)

1-4: LGTM! Post-installation script follows package conventions

The post-installation script correctly imports and calls the postinstall function from the @ast-grep/setup-lang package, passing the current directory.

packages/html/index.d.ts (2)

1-7: LGTM! Type definition is well-structured

The LanguageRegistration type is well-defined with appropriate property types and optional flags.


9-10: LGTM! Export follows TypeScript best practices

The declaration and export of the registration constant follows TypeScript best practices.

packages/html/index.js (1)

1-9: LGTM! Well-structured module for HTML language registration.

The implementation correctly exports the required properties for HTML language registration in ast-grep:

  • Uses the proper path resolution for the parser library
  • Includes appropriate file extensions (html, htm, xhtml)
  • Sets the correct language symbol and expando character

This aligns with the standard pattern for language packages in the ast-grep ecosystem.

packages/html/nursery.js (1)

1-16: LGTM! Good test setup for HTML parsing verification.

The test case appropriately validates that:

  1. The HTML parser can correctly parse a simple HTML element
  2. The pattern matching functionality works with HTML syntax
  3. The node identification is accurate (checking that 'element' kind is recognized)

This is a solid minimal test to ensure the HTML language support works correctly.

packages/html/package.json (3)

1-47: LGTM overall! Package configuration follows the project's patterns.

The package.json is well-structured with:

  • Appropriate scripts for build, test, and publishing
  • Correct dependencies and peer dependencies
  • Proper file inclusion list
  • Publishing configuration

Minor suggestions noted in separate comments.


10-10:

❓ Verification inconclusive

Verify that postinstall.js exists.

The postinstall script references postinstall.js, which is included in the files array but not provided in the PR.


🏁 Script executed:

#!/bin/bash
# Check if postinstall.js exists in the PR
fd --type f --exact-path "packages/html/postinstall.js"

# If it doesn't exist, check if it's in the repo but not in the PR
if [ $? -ne 0 ]; then
  echo "postinstall.js not found in the PR, checking if it exists in other packages:"
  fd "postinstall.js" --type f --path packages
fi

Length of output: 745


Verify that postinstall.js exists in the packages/html folder.

  • The postinstall script in packages/html/package.json references postinstall.js, but our initial automated check didn’t produce conclusive results.
  • The original fd command failed due to incorrect flags (--exact-path and --path), so the file wasn’t reliably located.
  • Action Required: Please verify manually (or with a corrected script, e.g., using find packages/html -type f -name "postinstall.js") that postinstall.js exists in the intended location or is intentionally omitted.

44-46:

❓ Verification inconclusive

Verify the pnpm.onlyBuiltDependencies config is correct.

The config includes both @ast-grep/lang-html (the package itself) and tree-sitter-cli. Make sure that including the package itself in onlyBuiltDependencies follows the pattern used in other language packages.


🏁 Script executed:

#!/bin/bash
# Check what other language packages include in onlyBuiltDependencies
echo "Checking onlyBuiltDependencies in other language packages:"
fd "package.json" --type f --path packages | xargs grep -l "onlyBuiltDependencies" | xargs grep -A3 "onlyBuiltDependencies"

Length of output: 480


Action: Verify the pnpm.onlyBuiltDependencies configuration

The configuration in packages/html/package.json currently lists both @ast-grep/lang-html and tree-sitter-cli. An initial attempt to check how similar language packages use this configuration ran into an error (the --path flag isn’t valid for the fd command), so we couldn’t automatically confirm whether including the package itself follows the established pattern.

Please manually verify that:

  • Including the package itself (i.e. @ast-grep/lang-html) in onlyBuiltDependencies is intentional.
  • The configuration is consistent with how dependencies are handled in similar language packages.

If this pattern is unique or incorrect compared to other language packages, adjust the configuration accordingly.

@HerringtonDarkholme HerringtonDarkholme merged commit ec3fa13 into ast-grep:main Apr 5, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/html branch April 6, 2025 03:29
This was referenced Apr 6, 2025
@coderabbitai coderabbitai bot mentioned this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants