-
Notifications
You must be signed in to change notification settings - Fork 15
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
add 012 upgrade option #6
Conversation
a669b57
to
9379608
Compare
lib/upgrade012/fmtverbs.go
Outdated
) | ||
|
||
//todo list of them? | ||
const fmtVerbCompatibilityDelimiter = "@@_@@ TFMT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmtVerbCompatibilityDelimiter
is unused (from deadcode
)
lib/upgrade012/upgrade.go
Outdated
|
||
if err != nil { | ||
if stdout != nil { | ||
fmt.Println(stdout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of fmt.Println
is not checked (from errcheck
)
cli/cmds.go
Outdated
return err | ||
} | ||
|
||
br.Writer.Write([]byte(fb)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of br.Writer.Write
is not checked (from errcheck
)
lib/upgrade012/fmtverbs.go
Outdated
|
||
// handle bare %s | ||
// figure out why the * doesn't match both later | ||
b = string(regexp.MustCompile(`(?m:^%[sdfgtqv]$)`).ReplaceAllString(b, `#@@_@@ TFMT:$0`)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary conversion (from unconvert
)
lib/upgrade012/upgrade.go
Outdated
// strip it here | ||
fb := strings.TrimSuffix(string(raw), "\n") | ||
|
||
return string(fb), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary conversion (from unconvert
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @megan07, just left a couple minor comments inline
cli/cmds.go
Outdated
_, err = br.Writer.Write([]byte(fb)) | ||
|
||
if err == nil && fb != b { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines could be merged:
if _, err = br.Writer.Write([]byte(fb)); err == nil && fb != b {
cli/cmds.go
Outdated
// nolint staticcheck | ||
fmt.Fprintf(os.Stderr, c.Sprintf("<%s>%s</>: <cyan>%d</> lines & formatted <yellow>%d</>/<yellow>%d</> blocks!\n", fc, br.FileName, br.LineCount, blocksFormatted, br.BlockCount)) | ||
} | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be after br.DoTheThing(filename)
?
if err != nil { | ||
return err | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we add the new check for the diff function here were it does an os.exit(-1) if there are any blocks with error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @megan07! LGTM 🚀
./terrafmt upgrade012 path/to/test_files.go
Because
terraform 0.12upgrade
needs to be run on a directory and doesn't have astdin
option, it will write the blocks to a buffer, create a temp directory, write the buffer to a temp file there, runterraform 0.12upgrade
on the temp directory, read the temp file back to the format block before it writes it to the real file.I didn't implement the
fmtcompat
option into this. I didn't entirely understand the use case, but I can add it in if you need me to.