From 25b19e04618567c262263acaac36b8b2fce5c733 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Mon, 9 May 2022 17:37:32 -0700 Subject: [PATCH] Some `count` parameters take a bare `%s` string parameter instead of a `%d` --- lib/fmtverbs/fmtverbs.go | 8 ++++---- lib/fmtverbs/fmtverbs_test.go | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/fmtverbs/fmtverbs.go b/lib/fmtverbs/fmtverbs.go index 19a8a99a..ec777aa9 100644 --- a/lib/fmtverbs/fmtverbs.go +++ b/lib/fmtverbs/fmtverbs.go @@ -28,8 +28,8 @@ func Escape(b string) string { b = regexp.MustCompile(`(\bprovider\s+=\s+)+%\[(\d+)\]s`).ReplaceAllString(b, `${1}tfmtprovider.PROVIDER_${2}`) // count meta-argument - b = regexp.MustCompile(`(\bcount\s+=\s+)%(d)`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`) - b = regexp.MustCompile(`(\bcount\s+=\s+)+%(\[(\d+)\]d)`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`) + b = regexp.MustCompile(`(\bcount\s+=\s+)%([ds])`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`) + b = regexp.MustCompile(`(\bcount\s+=\s+)+%(\[(\d+)\][ds])`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`) // %[n]s b = regexp.MustCompile(`(?m:^%(\.[0-9])?\[[\d]+\][sdfgtq]$)`).ReplaceAllString(b, `#@@_@@ TFMT:$0:TMFT @@_@@#`) @@ -129,8 +129,8 @@ func Unscape(fb string) string { fb = regexp.MustCompile(`"TFMTRESNAME_q"`).ReplaceAllLiteralString(fb, `%q`) // count meta-argument - fb = regexp.MustCompile(`1\s+# tfmtcount_(\[\d+\]d)`).ReplaceAllString(fb, `%${1}`) - fb = regexp.MustCompile(`1\s+# tfmtcount_d`).ReplaceAllString(fb, `%d`) + fb = regexp.MustCompile(`1\s+# tfmtcount_(\[\d+\][ds])`).ReplaceAllString(fb, `%${1}`) + fb = regexp.MustCompile(`1\s+# tfmtcount_([ds])`).ReplaceAllString(fb, `%${1}`) // provider meta-argument fb = regexp.MustCompile(`tfmtprovider.PROVIDER_(\d+)`).ReplaceAllString(fb, `%[${1}]s`) diff --git a/lib/fmtverbs/fmtverbs_test.go b/lib/fmtverbs/fmtverbs_test.go index 091ede10..e865a99e 100644 --- a/lib/fmtverbs/fmtverbs_test.go +++ b/lib/fmtverbs/fmtverbs_test.go @@ -583,11 +583,19 @@ resource "resource" "test2" { count = %[2]d } -resource "other_resource" "test3" { +resource "resource" "test3" { + count = %s +} + +resource "resource" "test4" { + count = %[3]s +} + +resource "other_resource" "test5" { replica_count = %d } -resource "other_resource" "test4" { +resource "other_resource" "test6" { replica_count = %[2]d } `, @@ -600,11 +608,19 @@ resource "resource" "test2" { count = 1 # tfmtcount_[2]d } -resource "other_resource" "test3" { +resource "resource" "test3" { + count = 1 # tfmtcount_s +} + +resource "resource" "test4" { + count = 1 # tfmtcount_[3]s +} + +resource "other_resource" "test5" { replica_count = "@@_@@ TFMT:%d:TFMT @@_@@" } -resource "other_resource" "test4" { +resource "other_resource" "test6" { replica_count = "@@_@@ TFMT:%[2]d:TFMT @@_@@" } `,