Skip to content

Commit e2a763f

Browse files
Added YAML Rule Example (#635)
* Create find-key-value.md * Create index.md * fix: update playground link * Update find-key-value.md --------- Co-authored-by: Herrington Darkholme <[email protected]>
1 parent d15934d commit e2a763f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Find key/value and show message using those key/vals
2+
3+
* [Playground Link](/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6InlhbWwiLCJxdWVyeSI6IiIsInJld3JpdGUiOiIiLCJzdHJpY3RuZXNzIjoic21hcnQiLCJzZWxlY3RvciI6IiIsImNvbmZpZyI6ImlkOiBkZXRlY3QtaG9zdC1wb3J0XG5tZXNzYWdlOiBZb3UgYXJlIHVzaW5nICRIT1NUIG9uIFBvcnQgJFBPUlQsIHBsZWFzZSBjaGFuZ2UgaXQgdG8gODAwMFxuc2V2ZXJpdHk6IGVycm9yXG5ydWxlOlxuICBhbnk6XG4gIC0gcGF0dGVybjogfFxuICAgICBwb3J0OiAkUE9SVFxuICAtIHBhdHRlcm46IHxcbiAgICAgaG9zdDogJEhPU1QiLCJzb3VyY2UiOiJkYjpcbiAgIHVzZXJuYW1lOiByb290XG4gICBwYXNzd29yZDogcm9vdFxuXG5zZXJ2ZXI6XG4gIGhvc3Q6IDEyNy4wLjAuMVxuICBwb3J0OiA4MDAxIn0=)
4+
5+
### Description
6+
7+
This YAML rule helps detect specific host and port configurations in your code. For example, it checks if the port is set to something other than 8000 or if a particular host is used. It provides an error message prompting you to update the configuration.
8+
9+
### YAML
10+
11+
```yaml
12+
id: detect-host-port
13+
message: You are using $HOST on Port $PORT, please change it to 8000
14+
severity: error
15+
rule:
16+
any:
17+
- pattern: |
18+
port: $PORT
19+
- pattern: |
20+
host: $HOST
21+
```
22+
23+
### Example
24+
25+
<!-- highlight matched code in curly-brace {lineNum} -->
26+
```yaml {5,6}
27+
db:
28+
username: root
29+
password: root
30+
server:
31+
host: 127.0.0.1
32+
port: 8001
33+
```
34+
35+
### Contributed by
36+
[rohitcoder](https://twitter.com/rohitcoder) on [Discord](https://discord.com/invite/4YZjf6htSQ).

website/catalog/yaml/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# YAML
2+
3+
This page curates a list of example ast-grep rules to check and to rewrite YAML code.
4+
5+
<!--@include: ./find-key-value.md-->

0 commit comments

Comments
 (0)