Skip to content

✨ Bash #46

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 4 commits into from
Apr 4, 2025
Merged

✨ Bash #46

merged 4 commits into from
Apr 4, 2025

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 1, 2025

And so it begins...

I'll write a test in the other ones before opening them.

CI

CodeRabbit Metadata

Summary by CodeRabbit

  • New Features
    • Launched a new package offering Bash language support with dynamic registration and configurable parser options.
  • Documentation
    • Introduced a detailed README outlining installation, integration instructions, and usage examples.
  • Tests
    • Established an automated testing environment to validate Bash command parsing.
  • Chores
    • Implemented post-installation routines to streamline the package setup.
  • Package Management
    • Added a new package.json file for the @ast-grep/lang-bash package, specifying metadata and scripts for management.

Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

This pull request introduces a new Bash language package (@ast-grep/lang-bash). It adds documentation with installation and usage instructions, defines a LanguageRegistration type and corresponding configuration in the source files, and provides a post-install script to invoke language setup. A test environment is also established via a nursery script. Additionally, the package metadata, dependencies, and publishing configuration are defined for proper package management.

Changes

File(s) Change Summary
packages/bash/README.md Added documentation covering installation commands, usage examples, and integration steps for the Bash language package.
packages/bash/index.d.ts | packages/bash/index.js Introduced the LanguageRegistration type and a configuration object exporting language details (libraryPath, extensions, languageSymbol, expandoChar).
packages/bash/nursery.js Created a test script that sets up a testing environment using @ast-grep/nursery to parse Bash code and validate the syntax tree.
packages/bash/package.json Added package metadata, scripts for build/test tasks, dependency definitions, and publish configuration for the new Bash language package.
packages/bash/postinstall.js Added a post-installation script that calls the postinstall function from @ast-grep/setup-lang with the current directory information.
.changeset/brave-hairs-dress.md Added a changeset entry for the introduction of the @ast-grep/lang-bash package.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant PM as Package Manager
  participant PI as postinstall.js
  participant SL as @ast-grep/setup-lang

  U->>PM: Install @ast-grep/lang-bash
  PM->>PI: Execute postinstall script
  PI->>SL: Call setup({ dirname: __dirname })
  SL-->>PI: Confirm setup completion
Loading
sequenceDiagram
  participant TR as Test Runner
  participant NS as nursery.js
  participant LC as Language Config (index.js)
  participant P as Parser (Tree-sitter)

  TR->>NS: Start testing Bash language
  NS->>LC: Load registration configuration
  NS->>P: Parse "echo test" snippet
  P-->>NS: Return syntax tree
  NS->>TR: Assert node kind "command" exists
Loading

Suggested reviewers

  • HerringtonDarkholme

Poem

I hopped through lines of code so bright,
Adding Bash support with all my might.
New docs, new tests, and types in place,
A neat registration to embrace.
Hop along and code with glee—
A bunny's work is fun and free! 🐰✨


📜 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 acfc4df and 76a067e.

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

🪧 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: 2

🧹 Nitpick comments (5)
packages/bash/README.md (1)

14-24: Consider expanding usage examples.

The usage example demonstrates the basic functionality but could benefit from more complex examples showing different Bash constructs and how to query them.

Consider adding examples like:

  • Parsing conditional statements
  • Handling pipes
  • Working with variable assignments
  • Extracting specific nodes from more complex scripts

This would help users understand the full capabilities of the Bash language support.

packages/bash/index.d.ts (1)

1-7: Add JSDoc comments to improve documentation.

The type definition is clear but could benefit from JSDoc comments explaining the purpose of each field, especially for the optional properties like languageSymbol, metaVarChar, and expandoChar.

+/**
+ * Configuration for registering a language with ast-grep
+ */
type LanguageRegistration = {
+  /** Path to the language library file */
  libraryPath: string
+  /** File extensions associated with this language */
  extensions: string[]
+  /** Symbol used to identify the language */
  languageSymbol?: string
+  /** Character used for meta variables in patterns */
  metaVarChar?: string
+  /** Character used for expanding nodes in patterns */
  expandoChar?: string
}
packages/bash/index.js (1)

4-21: Well-structured language configuration with comprehensive file extensions.

The exported configuration object properly defines all necessary properties for Bash language support, with an extensive list of file extensions covering various Bash-related file types.

Consider adding a brief comment explaining the purpose of the expandoChar property for better code documentation.

 module.exports = {
   libraryPath: libPath,
   extensions: [
     'bash',
     'bats',
     'cgi',
     'command',
     'env',
     'fcgi',
     'ksh',
     'sh',
     'tmux',
     'tool',
     'zsh',
   ],
   languageSymbol: 'tree_sitter_bash',
+  // Character used for variable expansion in Bash
   expandoChar: '$',
 }
packages/bash/package.json (2)

1-5: Add package description for better discoverability.

The package metadata is generally correct with appropriate naming and versioning, but the description field is empty.

Add a meaningful description to provide context about the package purpose:

{
  "name": "@ast-grep/lang-bash",
  "version": "0.0.1",
-  "description": "",
+  "description": "Bash language support for ast-grep",
  "main": "index.js",

21-23: Complete the author field.

The author field is empty and should be filled with appropriate information.

  "keywords": ["ast-grep"],
-  "author": "",
+  "author": "NatoBoram",
  "license": "ISC",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 002639c and acfc4df.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/bash/README.md (1 hunks)
  • packages/bash/index.d.ts (1 hunks)
  • packages/bash/index.js (1 hunks)
  • packages/bash/nursery.js (1 hunks)
  • packages/bash/package.json (1 hunks)
  • packages/bash/postinstall.js (1 hunks)
🔇 Additional comments (8)
packages/bash/postinstall.js (1)

1-4: LGTM! Good implementation of the postinstall script.

The script correctly imports and calls the postinstall function from @ast-grep/setup-lang with the current directory, following the pattern used by other language packages.

packages/bash/nursery.js (1)

1-4: LGTM! Good setup of dependencies for the test environment.

The required dependencies are properly imported to set up the testing environment for the Bash language.

packages/bash/README.md (1)

1-13: LGTM! Clear installation instructions.

The installation section provides clear steps for setting up the Bash language support in a pnpm project, including the appropriate dependencies.

packages/bash/index.d.ts (1)

9-10: LGTM! Proper export of the language registration.

The constant declaration and default export are correctly implemented.

packages/bash/index.js (1)

1-3: LGTM: Module path handling is correctly implemented.

The use of the node: prefix for the built-in path module is a good practice, and the library path is correctly constructed using __dirname for cross-platform compatibility.

packages/bash/package.json (3)

6-12: LGTM: Build and test scripts are properly configured.

The scripts section defines appropriate commands for building, testing, and package lifecycle events.


24-39: LGTM: Dependencies are appropriately structured.

The dependency structure is well-organized with clear separation between runtime, peer, and development dependencies. The optional peer dependency for tree-sitter-cli is a good practice.


40-46: LGTM: Publishing and pnpm configurations are properly set.

The publishing configuration correctly sets public access, and the pnpm configuration for built dependencies is appropriate.

Comment on lines +13 to +20
"files": [
"index.js",
"index.d.ts",
"type.d.ts",
"postinstall.js",
"src",
"prebuilds"
],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the existence of type.d.ts and consider adding nursery.js to files.

The files list appears to include most necessary files, but has potential issues.


🏁 Script executed:

#!/bin/bash
# Check if type.d.ts exists and if nursery.js is needed in the files array

# Check for type.d.ts
echo "Checking for type.d.ts file..."
if [ -f "packages/bash/type.d.ts" ]; then
  echo "type.d.ts exists."
else
  echo "type.d.ts is listed in files array but does not exist."
fi

# Check for nursery.js
echo "Checking for nursery.js file..."
if [ -f "packages/bash/nursery.js" ]; then
  echo "nursery.js exists but is not included in the files array."
else
  echo "nursery.js does not exist."
fi

Length of output: 462


Action Required: Update Files Array in packages/bash/package.json

  • Missing File: The entry type.d.ts is listed but does not exist in the repository. Please either create this file if it's needed or remove the entry from the files array.
  • Omitted File: The file nursery.js exists in the repository but is not included in the files array. Please consider adding it if it’s meant to be part of the package distribution.

@HerringtonDarkholme
Copy link
Member

Hi! thanks for the language contribution. However, given that we will have more languages in the foreseeable future, I think changeset #31 should be first introduced to the repo.

I don't have time during the weekday but I will give it a try during the upcoming weekend. Thank you for your patience!

@NatoBoram
Copy link
Collaborator Author

That looks like difficult operation

I think I'll continue with adding the test and opening the PRs and later on I'll add all the changesets all at once after it's implemented

@HerringtonDarkholme
Copy link
Member

@NatoBoram changeset is added! you can update main branch and use pnpm changeset

It's not working locally, but I wonder if it's just a local issue. Let's see if it works in the CI.
@HerringtonDarkholme
Copy link
Member

Thanks!

@HerringtonDarkholme HerringtonDarkholme merged commit 4a54bcb into ast-grep:main Apr 4, 2025
3 checks passed
This was referenced Apr 4, 2025
@NatoBoram
Copy link
Collaborator Author

Alright, I should've added a changeset for every opened PR!

@NatoBoram NatoBoram deleted the feature/bash branch April 4, 2025 19:40
This was referenced Apr 4, 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