flatt-security / shisho

Lightweight static analyzer for several programming languages
https://docs.shisho.dev
GNU Affero General Public License v3.0
372 stars 15 forks source link

Allow nested constraints & capturing inside constraints #100

Closed lmt-swallow closed 3 years ago

lmt-swallow commented 3 years ago

Description

This PR changes the behaviour of constraints as follows:

Here's an example rule that defines nested constraints and a rewrite option with a metavariable inside a constraint pattern:

version: "1"
rules:
  - id: "test"
    language: hcl
    message: |
      test
    pattern: |
      resource "block" :[NAME] {        
        :[...X]
      }
    constraints:
      - target: X
        should: match
        pattern: |
          inner {
            :[...Z]
          }
        constraints:
          - target: Z
            should: match
            pattern: |
              test = :[HOO]
    rewrite_options:
      - |
        resource "block" :[NAME] {        
          test = :[HOO]
        }

Checklist

Additional Notes

N/A

netlify[bot] commented 3 years ago

✔️ Deploy Preview for cranky-fermi-e6c846 canceled.

🔨 Explore the source changes: 70b65df9090d766028dc79a836ed0e13ecff64e2

🔍 Inspect the deploy log: https://app.netlify.com/sites/cranky-fermi-e6c846/deploys/6165e04560d33d000708e294