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

Rewrite in Empty Blocks in HCL #112

Open y-matsutomo opened 3 years ago

y-matsutomo commented 3 years ago

Description of the bug

rewrite does not overwrite the target block when it implements in empty blocks.

Steps to Reproduce

target code

resource "google_container_cluster" "bad_example" {
  example_policy {

  }
}

rule

version: '1'
rules:
  - id: 'exapmle'
    title: exapmle
    language: hcl
    message: example
    patterns:
      - pattern: |
          resource  "google_container_cluster" :[NAME] {
            :[...SETTINGS]
          }
        constraints:
          - target: SETTINGS
            should: not-match-any-of
            patterns: 
              - pattern: example_policy = {}
              - pattern: |
                  example_policy {
                    :[...]
                  }
    rewrite: |
          resource "google_container_cluster" :[NAME] {
          :[SETTINGS]
          example_policy = {}
        }

Expected Behaviour

It should be overwritten as:

resource "google_container_cluster" "bad_example" {
:[SETTINGS]
example_policy = {}
}

But it returns as:

resource "google_container_cluster" :[NAME] {
  :[SETTINGS]
  example_policy {

  }
  example_policy = {}
}

Additional Materials

N/A