Commit Graph

548 Commits

Author SHA1 Message Date
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
Paul Hinze
d1e666a42d add position to all decoder errors
Several of the esoteric syntax errors we encounter in Terraform have
bubbled up errors from the decoder. Since all these errors have a Node
in context, they can report their position which makes them _much_ more
helpful to the user, even if the error message itself is confusing.

I tried to move around PosError somewhere but got stuck finding a good
spot for it that doesn't have either a silly name or an import cycle, so
for now I'm just cross referencing into the parser package to reference
the error type.
2015-12-18 10:54:32 -06:00
Paul Hinze
5af5025c48 Merge pull request #76 from hashicorp/phinze/fix-missing-braces-crash
Fix crash on missing braces
2015-12-16 18:36:51 -06:00
Paul Hinze
3a2d43b647 Fix crash on missing braces
Fixes crash reported here https://github.com/hashicorp/terraform/issues/4350
2015-12-16 18:21:22 -06:00
Mitchell Hashimoto
e3dcd7fc89 Merge pull request #72 from savaki/master
adds facility for deferred Decode similar to how json.RawMessage enables deferred Unmarshal
2015-12-16 11:10:53 -08:00
Seth Vargo
17c5c97b5a Merge pull request #74 from balexander-ot/patch-1
Update README.MD
2015-12-11 15:54:49 -05:00
balexander-ot
9900506682 Update README.MD
For the love of God and all that is holy.
2015-12-11 12:49:44 -08:00
Matt
1793d02c0e - decoded structs may now use the ast.Node type to save the raw ast.Node; conceptually similar to how json.RawMessage works and is useful in situations where you would like to either (a) defer decoding or (b) require additional meta-data like #Pos 2015-12-06 21:31:48 -08:00
Paul Hinze
c40ec20b12 Merge pull request #71 from hashicorp/b-dos-line-endings
Fix scanner for Windows line endings and add tests
2015-12-01 12:18:49 -06:00
James Nugent
665d74b45d Fix scanner for Windows line endings and add tests 2015-12-01 12:53:50 -05:00
James Nugent
cc4142e424 Merge pull request #70 from hashicorp/phinze/heredoc-ids-with-numbers
support heredoc identifiers with numbers
2015-12-01 12:13:28 -05:00
Paul Hinze
e2c26b8e6f support heredoc identifiers with numbers
fixes https://github.com/hashicorp/terraform/issues/4079
2015-12-01 10:22:31 -06:00
James Nugent
8a65681ce2 Merge pull request #66 from hashicorp/b-heredoc-lists
Support HEREDOCs in lists
2015-11-29 11:28:44 +00:00
Mitchell Hashimoto
5bd8787dc9 Merge pull request #68 from Buzer/lastline_comment
Fixed hang when comment is on the last line of the file
2015-11-28 14:43:01 -08:00
Eljas Alakulppi
2ec27b6be2 Fixed hang when comment was on the last line of the file 2015-11-29 00:20:41 +02:00
James Nugent
f0ca992551 Merge pull request #67 from hashicorp/f-package-comment
Use Go convention of docs with "Package" prefix
2015-11-26 20:19:33 +00:00
James Nugent
6cf355fb61 Use Go convention of docs with "Package" prefix 2015-11-26 14:57:49 +02:00
James Nugent
eb77c8f861 Support HEREDOCs in lists
This fixes a regression in Terraform where HEREDOCS were previously
supported in lists, reported in hashicorp/terraform#4065.
2015-11-26 14:52:16 +02:00
James Nugent
692d016087 Merge pull request #65 from hashicorp/b-map-identifiers
Fix scanning of identifiers of the form 'map.key'
2015-11-24 17:42:28 +02:00
James Nugent
c190e41403 Fix scanning of identifiers of the form 'map.key'
This is used in `.tfvars` files for Terraform in order to allow
overriding values in maps, for example:

    map.key1 = "Value"
    map.key2 = "OtherValue"
2015-11-24 15:13:07 +02:00
Mitchell Hashimoto
1688f22977 Merge pull request #64 from svanharmelen/b-fix-flattening-empty-objects
Fix flattening of empty objects
2015-11-20 09:26:51 -08:00
Sander van Harmelen
cf83c24abf Fix flattening of empty objects 2015-11-20 17:56:37 +01:00
Paul Hinze
5f90c29834 Merge pull request #63 from hashicorp/phinze/handle-multiple-interpolations-in-string
Handle multiple interpolations in string.
2015-11-19 14:08:33 -06:00
Paul Hinze
5612ebd968 Handle multiple interpolations in string.
A user testing an RC release of Terraform 0.6.7 found the following
string unexpectedly caused a syntax error:

    "echo ${var.region}${element(split(",",var.zones),0)}"

This fixes the error and covers it with a test.
2015-11-19 13:56:32 -06:00
Paul Hinze
da2740d4c5 Merge pull request #62 from hashicorp/phinze/handle-escaped-quotes-within-interpolations
Restore old behavior for \" within interpolations
2015-11-19 12:05:59 -06:00
Paul Hinze
feb701804f Restore old behavior for \" within interpolations
Before the parser rewrite, HCL would silently convert `\"` within
interpolation braces to `"`.

After the conversion, this became a syntax error.

We've found several instances of Terraform configs in the wild using
this syntax. It results in a hard "syntax error" message during config
parsing. While avoiding the extra escape on double quotes within
interpolations is definitely preferred, the UX of the syntax error feels
harsh enough to be worth inserting this backwards compatibility for now,
leaving us the option of deprecating it with a warning down the line.
2015-11-19 12:04:02 -06:00
James Nugent
6f3c2b512d Merge pull request #61 from svanharmelen/b-fix-object-flattening
Fix a bug in the flattener so that objects are flattened correctly
2015-11-19 18:49:26 +02:00
Sander van Harmelen
2f117c801c This fixes a bug in the flattener so that objects are flattened as one list object 2015-11-19 17:42:55 +01:00
Fatih Arslan
2deb1d1db2 Merge pull request #58 from derekdowling/patch-2
Travis Test/Build Status Badge
2015-11-18 00:53:55 +02:00
Derek Dowling
230ee45693 Travis Test/Build Status Badge
Always a good indicator when debugging, and good social pressure as well.
2015-11-17 14:51:24 -08:00
Mitchell Hashimoto
cc08d3d56a Merge pull request #56 from derekdowling/patch-1
Adding Godoc link
2015-11-16 14:12:51 -08:00
Derek Dowling
66088e3d0c Adding Godoc link
Makes understanding the consumable API much simpler rather than digging through source code.
2015-11-16 14:05:31 -08:00
Mitchell Hashimoto
2a326381fd Merge pull request #55 from hashicorp/f-error-pos
hcl/parser: store position on every parse err [GH-54]
2015-11-15 15:08:40 -08:00
Mitchell Hashimoto
201420aad0 hcl/parser: store position on every parse err [GH-54] 2015-11-15 15:03:31 -08:00
Mitchell Hashimoto
fbd0456768 Merge pull request #53 from hashicorp/add-rewrite
ast: add Rewrite() to rewrite AST
2015-11-14 17:38:20 -08:00
Fatih Arslan
d45f5d133c ast: change signature of Walk() to allow rewriting AST
With the previous Walk function it's not easy to rewrite the node as we
don't have any kind of reference to the parent. If we want to rewrite a
given AST, we have to manually traverse it as Walk is not usable. To
allow us rewriting the AST we change the signature of the function
passed to Walk. It'll allow us to rewrite the AST and return back.
Internally Walk() overrides the returned AST.

This idea was also talked here:
https://groups.google.com/forum/#!topic/golang-nuts/cRZQV36IckM
extensively.
2015-11-14 21:58:31 +02:00
Mitchell Hashimoto
8ec7833c13 Merge pull request #51 from hashicorp/fix-comma
parser: fix syntax error on missing comma
2015-11-12 08:17:48 -08:00
Mitchell Hashimoto
21da63e4d5 Merge pull request #52 from hashicorp/add-travis
Add travis.yml file
2015-11-12 08:16:43 -08:00
Fatih Arslan
285f30bf10 Add travis.yml file
We have many tests, having this would simplify contributing also easier
because Github would show us the CI result on PR's.
2015-11-12 17:56:38 +02:00
Fatih Arslan
99ce7c7e2c parser: fix syntax error on missing comma
Fixes hashicorp/terraform#3877
2015-11-12 15:26:23 +02:00
Mitchell Hashimoto
fa160f1206 Merge pull request #49 from hashicorp/b-heredoc
Heredoc support
2015-11-10 15:09:49 -08:00
Mitchell Hashimoto
aed824cf55 add more heredoc tests 2015-11-10 15:08:59 -08:00
Mitchell Hashimoto
616214bb2e hcl/printer: cleanup how we handle heredocs 2015-11-10 15:06:32 -08:00
Mitchell Hashimoto
7b107c7b54 hcl/printer: clear trailing newline from heredoc 2015-11-10 15:02:21 -08:00
Mitchell Hashimoto
16dcdb88fa hcl/printer: unindent for heredocs 2015-11-10 14:54:46 -08:00