Skip to content

Commit

Permalink
doc: add explanation for constraints
Browse files Browse the repository at this point in the history
fix #537
  • Loading branch information
HerringtonDarkholme committed Sep 17, 2024
1 parent a312cff commit 89bd3b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions website/guide/project/lint-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ So `console.log(name)` will match the above rule, but `console.log('Rem')` will

See [playground](https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImphdmFzY3JpcHQiLCJxdWVyeSI6ImNvbnNvbGUubG9nKCRNQVRDSCkiLCJjb25maWciOiIjIENvbmZpZ3VyZSBSdWxlIGluIFlBTUxcbnJ1bGU6XG4gIHBhdHRlcm46IGNvbnNvbGUubG9nKCRHUkVFVClcbmNvbnN0cmFpbnRzOlxuICBHUkVFVDpcbiAgICBraW5kOiBpZGVudGlmaWVyIiwic291cmNlIjoiY29uc29sZS5sb2coJ0hlbGxvIFdvcmxkJylcbmNvbnNvbGUubG9nKGdyZWV0aW5nKVxuIn0=) in action.

:::warning
Note, constraints only applies to the single meta variable like `$ARG`, not multiple meta variable like `$$$ARGS`.
:::

:::details `constraints` is applied after `rule` and does not work inside `not`
`constraints` is a filter to further refine the matched nodes and is applied after the `rule` is matched.
So the `constraints` field cannot be used inside `not`, for example
Expand Down
3 changes: 3 additions & 0 deletions website/reference/yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ rule:

Additional meta variables pattern to filter matches. The key is matched meta variable name without `$`. The value is a [rule object](/reference/rule.html).

**Note, constraints only applies to the single meta variable like `$ARG`,** not multiple meta variable like `$$$ARGS`.
So the key name must only refer to a single meta variable.

Example:

```yaml
Expand Down

0 comments on commit 89bd3b8

Please sign in to comment.