mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 04:48:33 +07:00
Always convert CRLF to LF for output description
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
This commit is contained in:
@@ -40,5 +40,8 @@ trim_trailing_whitespace = false
|
||||
[**/inputs-crlf/variables.tf]
|
||||
end_of_line = crlf
|
||||
|
||||
[**/outputs-crlf/outputs.tf]
|
||||
end_of_line = crlf
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
@@ -278,7 +278,8 @@ func loadOutputs(tfmodule *tfconfig.Module, config *print.Config) ([]*Output, er
|
||||
}
|
||||
}
|
||||
for _, o := range tfmodule.Outputs {
|
||||
description := o.Description
|
||||
// convert CRLF to LF early on (https://github.com/terraform-docs/terraform-docs/issues/584)
|
||||
description := strings.ReplaceAll(o.Description, "\r\n", "\n")
|
||||
if description == "" && config.Settings.ReadComments {
|
||||
description = loadComments(o.Pos.Filename, o.Pos.Line)
|
||||
}
|
||||
|
||||
@@ -618,6 +618,37 @@ func TestLoadOutputs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadOutputsLineEnding(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "load module outputs from file with lf line ending",
|
||||
path: "outputs-lf",
|
||||
expected: "The quick brown fox jumps\nover the lazy dog\n",
|
||||
},
|
||||
{
|
||||
name: "load module outputs from file with crlf line ending",
|
||||
path: "outputs-crlf",
|
||||
expected: "The quick brown fox jumps\nover the lazy dog\n",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
config := print.NewConfig()
|
||||
module, _ := loadModule(filepath.Join("testdata", tt.path))
|
||||
outputs, _ := loadOutputs(module, config)
|
||||
|
||||
assert.Equal(1, len(outputs))
|
||||
assert.Equal(tt.expected, string(outputs[0].Description))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadOutputsValues(t *testing.T) {
|
||||
type expected struct {
|
||||
outputs int
|
||||
|
||||
2
terraform/testdata/inputs-crlf/variables.tf
vendored
2
terraform/testdata/inputs-crlf/variables.tf
vendored
@@ -1,4 +1,4 @@
|
||||
variable "multi-line-lf" {
|
||||
variable "multi-line-crlf" {
|
||||
type = string
|
||||
description = <<-EOT
|
||||
The quick brown fox jumps
|
||||
|
||||
2
terraform/testdata/inputs-lf/variables.tf
vendored
2
terraform/testdata/inputs-lf/variables.tf
vendored
@@ -1,4 +1,4 @@
|
||||
variable "multi-line-crlf" {
|
||||
variable "multi-line-lf" {
|
||||
type = string
|
||||
description = <<-EOT
|
||||
The quick brown fox jumps
|
||||
|
||||
7
terraform/testdata/outputs-crlf/outputs.tf
vendored
Normal file
7
terraform/testdata/outputs-crlf/outputs.tf
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
output "multi-line-crlf" {
|
||||
value = "foo"
|
||||
description = <<-EOT
|
||||
The quick brown fox jumps
|
||||
over the lazy dog
|
||||
EOT
|
||||
}
|
||||
7
terraform/testdata/outputs-lf/outputs.tf
vendored
Normal file
7
terraform/testdata/outputs-lf/outputs.tf
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
output "multi-line-lf" {
|
||||
value = "foo"
|
||||
description = <<-EOT
|
||||
The quick brown fox jumps
|
||||
over the lazy dog
|
||||
EOT
|
||||
}
|
||||
Reference in New Issue
Block a user