|
1 | 1 | # No Multiline Comments |
| 2 | + |
| 3 | +Disallows usage of multiline comments |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +Name | Default | Value |
| 8 | +--- | --- | --- |
| 9 | +enabled | true | Boolean |
| 10 | +single_line_only | false | Boolean |
| 11 | + |
| 12 | +```hcl |
| 13 | +rule "no_multiline_comments" { |
| 14 | + enabled = true |
| 15 | +
|
| 16 | + single_line_only = false |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +## Example |
| 21 | + |
| 22 | +Disallows usage of multi-line comments. |
| 23 | + |
| 24 | +```hcl |
| 25 | +# Good |
| 26 | +/* |
| 27 | +Bad |
| 28 | +*/ |
| 29 | +``` |
| 30 | + |
| 31 | +``` |
| 32 | +Warning: Multiline comments are not allowed. Replace the comment with single-line comment(s) (no_multiline_comments) |
| 33 | +
|
| 34 | + on t.tf line 2: |
| 35 | + 2: /* |
| 36 | + 3: Bad |
| 37 | + 4: */ |
| 38 | +
|
| 39 | +Reference: https://github.com/AleksaC/tflint-ruleset-misc |
| 40 | +``` |
| 41 | + |
| 42 | +### single_line_only = false |
| 43 | + |
| 44 | +Disallows usage of multi-line comments for single-line comments only. |
| 45 | + |
| 46 | +```hcl |
| 47 | +/* |
| 48 | +Good |
| 49 | +*/ |
| 50 | +/* Bad */ |
| 51 | +``` |
| 52 | + |
| 53 | +``` |
| 54 | +Warning: Using multiline comment syntax for single-line comments is not allowed. Use `#` instead. (no_multiline_comments) |
| 55 | +
|
| 56 | + on t.tf line 4: |
| 57 | + 4: /* Bad */ |
| 58 | +
|
| 59 | +Reference: https://github.com/AleksaC/tflint-ruleset-misc |
| 60 | +``` |
| 61 | + |
| 62 | +## Why |
| 63 | + |
| 64 | +Terraform supports multiline comments using `/*` and `*/` as delimiters. In practice |
| 65 | +multiline comments are rarely needed and can be replaced by multiple single-line ones. |
| 66 | +Unline single-line comments, multiline comments can be placed in the middle of |
| 67 | +expressions. However, I have yet to see a case where putting a comment inside the |
| 68 | +expression has any benefit over putting it on the line above or at the end of the line, |
| 69 | +but I can easily think of cases where that would hurt readability as well as make |
| 70 | +it harder to build tools that parse expressions as they need to be aware that a multiline |
| 71 | +comment can pop up pretty much everywhere. |
| 72 | + |
| 73 | +So banning multiline comments prevents putting them in weird places, makes the code |
| 74 | +more consistent and subjectively more aesthetically pleasing. |
| 75 | + |
| 76 | +If you still want to use multiline comments, this rule provides an option to ban them |
| 77 | +for comments that don't span multiple lines, allowing their usage only for actual |
| 78 | +multiline comments. |
| 79 | + |
| 80 | +## How To Fix |
| 81 | + |
| 82 | +Replace multi-line comment with single-line comment(s). |
0 commit comments