hclwrite: export LeadComments()/LineComments() - #807
Conversation
|
I got started writing tests for this and ran into a few things - let me know if any of these are just misunderstandings or testing wrong:
Just returns the first line ( I'm not sure how we should approach "bad" multi-line inline comments (the ones not using actual multi-line syntax). I don't know if it's realistic to expect hclwrite to tell a multi-line inline comment apart from a single line inline comment + the next attribute's lead comment - is the indentation sufficient? does it have to be exactly indented, or just "more than the attribute is"? Do we even have that info? I suspect it's sufficient to say that terraform's behavior is undefined if you use single-line comment indicators for multiline comments (as the comment may get lost or end up with the next attr), but we do need to be deliberate about the choice, and document (and test) the limits. If it would be easier, I can push the tests to your branch so you can see the test cases; I'll leave that up to you! |
|
FWIW For example, if a caller deletes an attribute with comments attached to it then The existing rules about which comments get attached and which ones don't were therefore aimed at being good heuristics for which comments an author might expect to be removed along with an item that's being deleted. Other uses for these comments might want slightly different heuristics, but changing the existing rules in-place would cause functions like For that "i am a rather" example, # long comment, and there's nothing else on this line
# so this line here will be returned as the lead line on the next attr, probably? or just get lost.
other_attr = bar...so the current heuristic isn't good for this situation even when focused on the intended use-case. I'm not sure whether authors actually write comments line this in practice. |
Description
This change exports functions from the
hclwritepackage to read comments.