E40D [feature] allow digits in `kind` (like in `pattern.selector`) · Issue #2387 · ast-grep/ast-grep · GitHub
[go: up one dir, main page]

Skip to content

[feature] allow digits in kind (like in pattern.selector) #2387

@your-diary

Description

@your-diary

⭐ Suggestion

Currently, it seems kind doesn't support digits.

For example,

id: test-rule
language: markdown
rule:
    kind: atx_h1_marker

gives

$ ast-grep scan
Error: Cannot parse rule /path/to/rules/foo.yml
Help: The file is not a valid ast-grep rule. Please refer to doc and fix the error.
See also: https://ast-grep.github.io/guide/rule-config.html

✖ Caused by
╰▻ Fail to parse yaml as Rule.
╰▻ `rule` is not configured correctly.
╰▻ Rule contains invalid kind matcher.
╰▻ Invalid Kind
╰▻ Kind `atx_h` is invalid.

The last line implies kind: atx_h1_marker is regarded as kind: atx_h, ignoring the first digit and afterwards.

💻 Use Cases

I'm trying to use ast-grep for linting markdown files.

tree-sitter support is provided by tree-sitter-markdown, and I succeeded to setup the parser:

$ cat 1.md

# section
$ tree-sitter parse 1.md

(document [0, 0] - [2, 0]
  (section [0, 0] - [2, 0]
    (atx_heading [0, 0] - [1, 0]
      (atx_h1_marker [0, 0] - [0, 1])
      heading_content: (inline [0, 2] - [0, 9]))))

I want to match atx_h1_marker.

The current workaround is this:

id: test-rule
language: markdown
rule:
    pattern:
        context: "# hello"
        selector: atx_h1_marker

Surprisingly, digits are supported in selector. (I thought selector was the same as kind.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0