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] ignore empty rules in rules.yaml - allow trailing rule separator #942

Closed
milahu opened this issue Feb 19, 2024 · 1 comment
Closed
Labels
wontfix This will not be worked on

Comments

@milahu
Copy link

milahu commented Feb 19, 2024

actual result with empty rule: error: missing field id

rules.yaml

id: rule_1
language: Python
rule:
  pattern: 'aaa'
fix: 'bbb'

---

id: rule_2
language: Python
rule:
  pattern: 'ccc'
fix: 'ddd'

---

similar: trailing commas in array declarations

allowing empty rules would be useful for generating rules.yaml in a for loop

#!/usr/bin/env bash

rules_yaml=""
rule_id=0

function r() {
  rules_yaml+=$(
    echo
    echo
    echo "id: rule_$rule_id"
    echo "language: javascript"
    echo "rule:"
    echo "  pattern: '$1'"
    echo "fix: '$2'"
    echo
    echo "---" # rule separator
  )
  rule_id=$((rule_id + 1))
}

r 'nt' sleep
r 'an' firebaseApiKey
r 'on' typesenseServer

# fix: error: missing field id
rules_yaml=${rules_yaml:0: -4}

# debug: print rules yaml
echo "rules_yaml:"; echo "$rules_yaml" | grep -n ''

ast-grep scan -U -r <(echo "$rules_yaml") src/patchme.js
@milahu milahu added the enhancement New feature or request label Feb 19, 2024
@HerringtonDarkholme
Copy link
Member

After some thoughts I think this feature should be supported by serde-yaml or yaml.rs, instead of ast-grep.

Feel free to open issue there~

@HerringtonDarkholme HerringtonDarkholme added wontfix This will not be worked on and removed enhancement New feature or request labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants