stoeffel / elm-verify-examples

BSD 3-Clause "New" or "Revised" License
167 stars 14 forks source link

Generates invalid code when parsing backtics-separated code #93

Open malaire opened 4 years ago

malaire commented 4 years ago

When I run elm-verify-examples with following example:

{-|

  - some
  - list

```
Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
```
-}
someFunction : ...

it generates following invalid code which doesn't even compile:

spec1 : Test.Test
spec1 =
    Test.test "#someFunction: \n\n    |> Basics.toFloat\n    --> 124.0" <|
        \() ->
            Expect.equal
                (
                |> Basics.toFloat
                )
                (
                124.0
                )

If I indent same example with 4 spaces instead of using backticks it works, but since here I have example directly after a list, 4 spaces indentation can't be used as elm-format will mangle that.

stoeffel commented 4 years ago

Sorry that this isn't working for you as you'd expected. Does it also not work with newlines in between? Do the three backticks format nicely on package.elm-lang.org ?

malaire commented 4 years ago

Do the three backticks format nicely on package.elm-lang.org ?

It formats normally with elm-doc-preview. I'm not sure what you mean about newlines?

The problem seems to be that the unindented line within backtics-section is not detected by elm-verify-examples.

This doesn't work with elm-verify-examples, and generated code seems to imply that line Basics.ceiling 123.45 is ignored:

```
Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
```

This does work with elm-verify-examples, but adding that unneeded indentation within backtics looks bad in generated documentation:

```
    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0
```
stoeffel commented 4 years ago

I meant newlines here. There is no support for ``` in comments yet. Happy to accept a PR for adding support though.

{-|

  - some
  - list

   -- <-- I meant adding a newline here and no ```
    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0

-}
someFunction : ...
malaire commented 4 years ago

That syntax is not accepted by elm-format. If there are 2 or more empty lines between list and following indented code-block, elm-format will unindent the code-block and add backticks around it.

If there is only single newline then elm-format will mangle the list and the code-block.

So this example with two empty lines:

...
  - some
  - list

    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0
...

is changed by elm-format to this:

...
  - some
  - list

```
Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
```
...

And this example with single empty line:

...
  - some
  - list

    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0
...

is changed by elm-format to this:

...
  - some

  - list

    Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
...
stoeffel commented 4 years ago

Got it. Thanks for clarifying. Don't know when I'll get to this, but I definitelly think that we should start to support ```.