tree-sitter-bash

repository·master·Indexed 43 days ago

https://github.com/tree-sitter/tree-sitter-bash

A tree-sitter grammar for the Bash shell language version 0.25.1, providing high-performance incremental parsing for syntax highlighting, code navigation, and structural analysis.

Tokens
637
Snippets
5
Records
6
Agent score
56%

What's inside tree-sitter-bash

  1. Build and run tests

    master

    Use the following commands to build the project and execute the test suite. To maintain a continuous development workflow, you can also run tests in watch mode.

    # Build and run tests once
    npm run build
    npm run test
    
    # Run build and tests in watch mode
    npm run test:watch
  2. Use eslint-config-treesitter for linting bash grammars

    master

    To lint files using the tree-sitter-bash grammar with ESLint, import eslint-config-treesitter and spread its configuration into your eslint.config.mjs (Flat Config) array. This provides the necessary rules and parser settings for tree-sitter based linting.

    import treesitter from 'eslint-config-treesitter';
    
    export default [
      ...treesitter,
    ];
  3. Use tree-sitter-bash Node.js bindings

    master

    The tree-sitter-bash package provides Node.js bindings for the Bash grammar. It is designed to be compatible with both standard Node.js environments (via node-gyp-build) and Bun (via prebuilt .node files).

    When imported, the module exports the compiled tree-sitter grammar object. Additionally, it may export a nodeTypeInfo property containing metadata about node types from src/node-types.json if available.

    const Bash = require('tree-sitter-bash');
    
    // The exported object is the tree-sitter grammar
    // You can use it with the main 'tree-sitter' library
  4. Access Bash node type information via nodeTypeInfo

    master

    The bindings export a nodeTypeInfo property which contains a mapping of node types defined in the Bash grammar. This is useful for programmatic inspection of the grammar's structure.

    const Bash = require('tree-sitter-bash');
    
    if (Bash.nodeTypeInfo) {
      console.log(Bash.nodeTypeInfo);
    }