Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Conversation

lmt-swallow
Copy link
Member

Description

This PR changes the behaviour of constraints as follows:

  • Each constraint can take a pattern and other constraints.
  • A rewrite option can use metavariables inside a constraint pattern

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

  • I opened a draft PR or added the [WIP] to the title if my PR is not ready for review.
  • I have reviewed the code by myself.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • I have added tests enough to show how your code behaves and that your code works as expected.

Additional Notes

N/A

Signed-off-by: Takashi Yoneuchi <takashi.yoneuchi@shift-js.info>
Signed-off-by: Takashi Yoneuchi <takashi.yoneuchi@shift-js.info>
Signed-off-by: Takashi Yoneuchi <takashi.yoneuchi@shift-js.info>
Signed-off-by: Takashi Yoneuchi <takashi.yoneuchi@shift-js.info>
Signed-off-by: Takashi Yoneuchi <takashi.yoneuchi@shift-js.info>
@lmt-swallow lmt-swallow self-assigned this Oct 12, 2021
@lmt-swallow lmt-swallow merged commit f6e8b4c into main Oct 12, 2021
@lmt-swallow lmt-swallow deleted the feature/generic-constraints branch October 12, 2021 19:22
@netlify
Copy link

netlify bot commented Oct 12, 2021

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

🔨 Explore the source changes: 70b65df

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant