Commit Graph

542 Commits

Author SHA1 Message Date
Paul Hinze
d7400db714 Merge pull request #125 from hashicorp/b-escapes
strconv: Fix escaped backslashes \\ in braces ${}
2016-06-06 19:19:40 -05:00
Paul Hinze
8e05f061d6
strconv: Fix escaped backslashes \\ in braces ${}
Fixes https://github.com/hashicorp/terraform/issues/6359 and several
related issues by unescaping a double backslash within braces to a
single backslash.

This bumps into the bit of HIL that still hangs out in HCL - for values
that aren't interpolated, like Terraform's variable defaults - users
were unable to get a backslash to show up within `${}`.

That's because `${}` is handled specially to allow for, e.g., double
quotes inside of braces.

Here, we add `\\` as a special cased escape (along with `\"`) so users
can get backslashes in these scenarios by doubling them up.
2016-06-06 19:05:05 -05:00
vishalnayak
b5065874bc Skip a nil item during filtering 2016-05-10 20:33:58 -04:00
Merlin Gaillard
6ffac0df10 ignore fields with "-" tag name when decoding struct 2016-05-05 17:14:34 +02:00
Dan Carley
1793ae0f56 hcl/fmtcmd: Clarify docs for Options.Diff
This description was originally copied straight from gofmt[0]. But as noted
in hashicorp/terraform#6343, the "instead of rewriting" suggests that it
disables the `Write` option, whereas it is possible to enable both.

[0]: https://golang.org/src/cmd/gofmt/gofmt.go#L31
2016-04-28 18:03:01 +01:00
Paul Hinze
9a905a34e6 Merge pull request #115 from hashicorp/phinze/fmtcmd-remove-extra-newline
fmtcmd: Remove extra newline
2016-04-26 17:13:00 -05:00
Paul Hinze
2f980537dd
fmtcmd: Remove extra newline
The fmtcmd tests weren't running before due to the same build tag
problem as #112, so didn't catch the fact that there was an extra
newline being added here, which is now doubled thanks to #112.

Fixing up the build tag reveals failing tests - removing the extra
newline fixes the tests.
2016-04-26 16:06:22 -05:00
James Nugent
27a57f2605 Merge pull request #112 from hashicorp/phinze/print-trailing-newline-at-eof
printer: output EOF newline in formatted hcl
2016-04-13 10:25:42 -07:00
Paul Hinze
2eb00dcf94 printer: output EOF newline in formatted hcl
Noticed that the `hclfmt` tool (which uses hcl/printer) was chomping
the trailing newline from config files.

Here we switch to the more conventional newline-at-EOF output.

In the process of changing this, I realized that:

 * The printer_test.go build tag was wrong, so it wasn't running
 * The format() test helper was not exercising Format

So both of those fixes are included here
2016-04-06 09:09:04 -05:00
James Nugent
2604f3bda7 Merge pull request #91 from hashicorp/f-indented-heredocs
Add support for indented HEREDOC terminators
2016-03-21 14:46:21 +00:00
James Nugent
2584e26c89 Fix tests on Windows line endings 2016-03-21 14:33:19 +00:00
James Nugent
f5480db646 Remove hanging indent on HEREDOCs with <<- prefix
This commit adds support for removing a hanging indent from HEREDOC
token contents if the marker is prefixed with <<-. For example, given
the HCL definition:

my_long_var_name = <<-EOF
                   {
                       "key": "value"
                   }
                   EOF

The value of the HEREDOC will be:

{
    "key": "value"
}

This is useful for use cases where indentation or leading whitespace
is important.

The rule applied is that the prefix on the terminating marker will be
removed from each each line in the HEREDOC, providing all the lines have
that prefix (i.e. every line is at least as indented as the terminating
marker, and using the same mechanism of tabs vs spaces).
2016-03-21 14:12:20 +00:00
James Nugent
3ad5dd62fd Add support for indented HEREDOC terminators
This PR adds support for the style of HEREDOC often used in Ruby which
allows the terminating marker to be indented if the HEREDOC is started
with the sequence "<<-" rather than the usual "<<". This allows users to
express documents with more natural indentation:

resource "template_file" "test" {
    template = <<-HEREDOC
        First Line
        Second Line
    HEREDOC
}

Note that this does not attempt to add any semantics around removing
hanging indent from the actual text of the document, so extra
indentation would still be present. We could make use of the canonical
style for HCL herre to remove the hanging indent in the style of Ruby
which would probably be more predictable for users.
2016-03-21 14:12:20 +00:00
James Nugent
d27ef81edb Merge pull request #106 from hashicorp/windows-ignore-tests
Temporarily ignore printer and fmt tests on Windows
2016-03-21 14:09:04 +00:00
James Nugent
597882917a Temporarily gnore printer and fmt tests on Windows
The red CI build on Windows is making it harder to process actual bugs -
neither printer or fmt are used in any HC projects currently so
ignoring the tests on AppVeyor/Windows seems reasonable for now. At some
point they need fixing to account for line endings.
2016-03-21 13:56:16 +00:00
James Nugent
35d2bfae4f Merge pull request #105 from hashicorp/b-terraform-5470
Return an error if object keys are not strings
2016-03-21 13:53:07 +00:00
James Nugent
d41432d951 Return an error if object keys are not strings
This now gives an error instead of a panic when encountering
configuration such as described in hashicorp/terraform#5740:

```
resource "aws" "web" {
  provider = "aws" {
    region = "us-west-2"
  }
}
```

We now return an error message - "hcl object keys must be a string"
instead of crashing.

Fixes hashicorp/terraform#5740.
2016-03-21 13:32:31 +00:00
Mitchell Hashimoto
32f2911ca2 Merge pull request #104 from hashicorp/b-windows-scanner-tests
Fix scanner tests on Windows
2016-03-20 22:34:57 -05:00
James Nugent
9832b69cfd Fix line endings in hclfmt test 2016-03-21 00:17:10 +00:00
James Nugent
1e8f2d1561 Fix the appveyor build script 2016-03-21 00:09:29 +00:00
James Nugent
4b7727828a Fix scanner tests on Windows
This is necessary because of the effects of autocrlf on Windows.
2016-03-20 23:14:42 +00:00
James Nugent
fdad785730 Merge pull request #93 from drewwells/feature/appveyor
first pass at appveyor build
2016-03-19 23:46:01 +00:00
Seth Vargo
defa3a4c5e Merge pull request #103 from ebaratte/patch-3
added missing word
2016-03-18 11:40:51 -04:00
Etienne Baratte
f01aaf78c1 added missing word 2016-03-18 09:56:42 +01:00
Mitchell Hashimoto
567a5d1c48 Merge pull request #102 from hashicorp/b-bare-keys
Parse error on keys without values
2016-03-14 22:09:37 +01:00
Mitchell Hashimoto
99c4d58691 hcl/parser: better comments 2016-03-14 20:56:27 +01:00
Mitchell Hashimoto
faa2fba9b8 hcl/parser: error on bare object keys in object 2016-03-14 20:54:33 +01:00
Mitchell Hashimoto
7df3f8587e hcl/parser: test for bare key at top level 2016-03-14 20:44:57 +01:00
Mitchell Hashimoto
c84febd4c1 Merge pull request #101 from mssola/printer-empty-node
printer: don't write a newline on empty objects
2016-03-14 15:48:00 +01:00
Miquel Sabaté Solà
0c3742819f printer: don't write a newline on empty objects
This is to match the same criteria as in gofmt.

Fixes #94

Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
2016-03-14 15:38:41 +01:00
Seth Vargo
78101eb3cb Merge pull request #97 from hashicorp/pr-92
Add encoding API functions
2016-03-11 11:58:29 -05:00
Drew Wells
2799afc14b adds std encoding API fixes #4
The std encoding format is Unmarshal([]byte, interface{}) error.
This naturally lends itself well to being passed readfile or exhausted
reader/buffer.
2016-03-10 15:36:44 -05:00
Seth Vargo
5b00661d05 Merge pull request #96 from hashicorp/sethvargo/top_level
Ensure top-level object literals are arrays
2016-03-10 14:14:02 -05:00
Seth Vargo
bebd6ba7ff Ensure top-level object literals are arrays
Fixes GH-60
2016-03-10 14:04:52 -05:00
Mitchell Hashimoto
71c7409f1a hcl/parser: add test case from TF issue 2016-03-01 10:33:45 -08:00
Drew Wells
e2e76d3e53 fix appveyor build 2016-02-29 23:04:50 -06:00
Mitchell Hashimoto
1c284ec98f Parser enforces closing RBRACE [GH-88] 2016-02-10 10:31:11 -08:00
Mitchell Hashimoto
8cc8107682 hcl/parser: more negative number tests 2016-02-07 12:08:28 -08:00
Mitchell Hashimoto
4cae6d33fa hcl/scanner: add test for negative number 2016-02-07 12:07:40 -08:00
Mitchell Hashimoto
a01f759c89 Merge pull request #85 from VladRassokhin/fix-list-comments-indent
Fix indent of list item comments
2016-02-07 10:45:49 -08:00
Mitchell Hashimoto
aa4dbbc2b7 hcl/printer: style change 2016-02-07 10:40:21 -08:00
Mitchell Hashimoto
e692f814c2 Merge pull request #84 from VladRassokhin/remote-tailing-spaces-in-lists
Printer should not produce tailing spaces in lists
2016-02-07 10:37:16 -08:00
Vladislav Rassokhin
d8e433406e Fix indent of list item comments 2016-02-07 18:20:06 +03:00
Vladislav Rassokhin
63e2043a82 Printer should not produce tailing spaces in lists 2016-02-07 17:29:06 +03:00
Mitchell Hashimoto
e96d23138c Merge pull request #80 from dcarley/fmtcmd
Add new fmtcmd package (linting)
2016-01-30 16:51:29 +01:00
Mitchell Hashimoto
90fb5b22fa Merge pull request #83 from rhencke/patch-3
Document multi-line strings (here documents)
2016-01-30 14:55:26 +01:00
Robert Hencke
71f9cca07c Document multi-line strings (here documents) 2016-01-24 09:05:04 -05:00
Mitchell Hashimoto
578dd97468 hcl/ast: just adding a GoSTringer impl 2016-01-19 12:27:37 -08:00
Dan Carley
aee8c49b75 Add new fmtcmd package
This uses the `printer` package to normalise HCL files. It's inspired by
github.com/fatih/hclfmt - but it differs in that it's intended to be more
generic, re-usable, and follow the semantics of `gofmt` or `go fmt`.

I intend to utilise this in Terraform by implementing `terraform fmt`
sub-command which will normalise all files in the current working directory
(like `go fmt ./..`) or contents over STDIN (with `terraform fmt -` that
could be used by editor plugins). So that Terraform users can benefit from
linting without installing another package/binary.

I hope that by placing most of the logic in the HCL package it should be
easy to implement sub-commands in other projects that also use HCL.

Some notes about the implementation:

- the significant difference from `gofmt` is that STDIN/STDOUT are passed in
  and errors aren't logged/written directly to STDERR, which gives consumers
  (e.g. Terraform) the ability to set appropriate exit codes
- I chose to use inline fixtures instead of files because there were a
  number of times where I needed to reference the contents and group them
  together with diff output
- it seemed simplest to construct the expected outputs by looping over the
  relevant fixtures and building up a string/byte slice, hope it isn't too
  confusing to read
- the test failure reporting is kind of rough because the outputs are so
  large, but I didn't want to add another diff function
- I chose to have a separate test for sub-directories rather than making it
  the default in the fixtures so that I didn't need to add additional logic
  to the fixture rendering
- the fixtures are sorted by filename before any of the tests runs so that
  they match the order that they are read from disk by `filepath.Walk()`
2016-01-06 21:53:58 +00:00
Paul Hinze
197e8d3cf4 Merge pull request #77 from hashicorp/phinze/poserror
add position to all decoder errors
2015-12-18 11:53:00 -06:00