YAML
This page curates a list of example ast-grep rules to check and to rewrite YAML code.
Find key/value and show message using those key/vals
Description
This YAML rule helps detecting 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.
YAML
yaml
id: detect-host-port
message: You are using $HOST on Port $PORT, please change it to 8000
severity: error
rule:
any:
- pattern: |
port: $PORT
- pattern: |
host: $HOST
Example
yaml
db:
username: root
password: root
server:
host: 127.0.0.1
port: 8001
Contributed by
rohitcoder on Discord.