Skip to content
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

[feature] TypeScript types for Rules in NAPI #1038

Open
Eric162 opened this issue Apr 4, 2024 · 0 comments
Open

[feature] TypeScript types for Rules in NAPI #1038

Eric162 opened this issue Apr 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Eric162
Copy link

Eric162 commented Apr 4, 2024

⭐ Suggestion

It would be awesome to have either autogenerated or manually created types for the Rule type. The current type of rule in the napi package is any:

Locally, I have defined a set of typescript types that work very well to guide rule creation. I translated the Python classes to JS types here like so:

interface Pattern {
  selector?: string;
  context?: string;
}

export interface Rule {
  // atomic rules
  pattern?: string | Pattern;
  kind?: string;
  regex?: string;

  // relational rules
  inside?: Relation;
  has?: Relation;
  precedes?: Relation;
  follows?: Relation;

  // composite rules
  all?: Rule[];
  any?: Rule[];
  not?: Rule;
  matches?: string;
}

type StopBy = 'neighbor' | 'end' | Rule;

interface Relation extends Rule {
  stopBy?: StopBy;
  field?: string;
}

💻 Use Cases

Anyone who uses the @ast-grep/napi package would benefit from type-checked rules!

Thank you for this package - it's awesome!

@Eric162 Eric162 added the enhancement New feature or request label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant