Repository: fredrikekre/Runic.jl
Pull request #94 (2024-11-06 12:03:55)

Fix edge case with multiline lists with only a comment and no items

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/fredrikekre/Runic.jl/pull/94?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre) Report
Attention: Patch coverage is `33.33333%` with `2 lines` in your changes missing coverage. Please review.
> Project coverage is 56.05%. Comparing base [(`36ac679`)](https://app.codecov.io/gh/fredrikekre/Runic.jl/commit/36ac679362683aa2e0b1e1669a94efd83e9bf037?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre) to head [(`74988b1`)](https://app.codecov.io/gh/fredrikekre/Runic.jl/commit/74988b13df2dfacf59279b2989476c1d32f2ff24?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre).

| [Files with missing lines](https://app.codecov.io/gh/fredrikekre/Runic.jl/pull/94?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre) | Patch % | Lines |
|---|---|---|
| [src/runestone.jl](https://app.codecov.io/gh/fredrikekre/Runic.jl/pull/94?src=pr&el=tree&filepath=src%2Frunestone.jl&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre#diff-c3JjL3J1bmVzdG9uZS5qbA==) | 33.33% | [2 Missing :warning: ](https://app.codecov.io/gh/fredrikekre/Runic.jl/pull/94?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre) |

> :exclamation:  There is a different number of reports uploaded between BASE (36ac679) and HEAD (74988b1). Click for more details.
> 
> <details><summary>HEAD has 5 uploads less than BASE</summary>
>
>| Flag | BASE (36ac679) | HEAD (74988b1) |
>|------|------|------|
>||8|3|
></details>

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##           master      #94       +/-   ##
===========================================
- Coverage   90.76%   56.05%   -34.71%     
===========================================
  Files           8        8               
  Lines        3682     3682               
===========================================
- Hits         3342     2064     -1278     
- Misses        340     1618     +1278     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/fredrikekre/Runic.jl/pull/94?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fredrik+Ekre).


Patch:
diff --git a/src/runestone.jl b/src/runestone.jl
index 2d4b6d6..16bb83e 100644
--- a/src/runestone.jl
+++ b/src/runestone.jl
@@ -2485,13 +2485,16 @@ function indent_listlike(
     end
     # Kid just before the closing token should be a newline and it should be tagged with
     # pre-dedent.
-    if close_idx - 1 == open_idx + 1
+    if idx_after_leading_nl == close_idx
         # Just a single kid which should then have both leading and trailing newline
         if any_kid_changed
-            # Modify this kid again by popping from the list and backtrack the stream
+            # Modify this kid again by popping from the list
             kid = pop!(kids′)
-            seek(ctx.fmt_io, position(ctx.fmt_io) - span(kid))
+        else
+            kid = kids[close_idx - 1]
         end
+        # Backtrack the stream
+        seek(ctx.fmt_io, position(ctx.fmt_io) - span(kid))
     else
         kid = kids[close_idx - 1]
     end


Test patch:
diff --git a/test/runtests.jl b/test/runtests.jl
index 66d7d8e..a6559d8 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -397,6 +397,9 @@ end
     # Non space whitespace (TODO: Not sure if a JuliaSyntax bug or not?)
     @test format_string(String(UInt8[0x61, 0x20, 0x3d, 0x3d, 0x20, 0xc2, 0xa0, 0x62, 0x3a, 0x63])) ==
         "a == b:c"
+    # Edge case with comment and no items
+    @test format_string("[# a\n]") == "[# a\n]"
+    @test format_string("[ # a\n]") == "[ # a\n]"
 end
 
 @testset "whitespace around ->" begin