terraform/internal/command/format
Martin Atkins 70bc432f85 command/views/json: Never generate invalid diagnostic snippet offsets
Because our snippet generator is trying to select whole lines to include
in the snippet, it has some edge cases for odd situations where the
relevant source range starts or ends directly at a newline, which were
previously causing this logic to return out-of-bounds offsets into the
code snippet string.

Although arguably it'd be better for the original diagnostics to report
more reasonable source ranges, it's better for us to report a
slightly-inaccurate snippet than to crash altogether, and so we'll extend
our existing range checks to check both bounds of the string and thus
avoid downstreams having to deal with out-of-bounds indices.

For completeness here I also added some similar logic to the
human-oriented diagnostic formatter, which consumes the result of the
JSON diagnostic builder. That's not really needed with the additional
checks in the JSON diagnostic builder, but it's nice to reinforce that
this code can't panic (in this way, at least) even if its input isn't
valid.
2021-06-28 13:42:28 -07:00
..
diagnostic.go command/views/json: Never generate invalid diagnostic snippet offsets 2021-06-28 13:42:28 -07:00
diagnostic_test.go update to use typed sensitive marks 2021-06-25 12:49:07 -04:00
diff.go remove IsMarked and ContainsMarked calls 2021-06-25 14:17:06 -04:00
diff_test.go update to use typed sensitive marks 2021-06-25 12:49:07 -04:00
format.go Move command/ to internal/command/ 2021-05-17 14:09:07 -07:00
object_id.go Move command/ to internal/command/ 2021-05-17 14:09:07 -07:00
object_id_test.go Move command/ to internal/command/ 2021-05-17 14:09:07 -07:00
state.go Move terraform/ to internal/terraform/ 2021-05-17 14:09:07 -07:00
state_test.go Move terraform/ to internal/terraform/ 2021-05-17 14:09:07 -07:00
trivia.go Move command/ to internal/command/ 2021-05-17 14:09:07 -07:00