Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indented code examples in markdown are not checked #3672

Closed
MateuszKubuszok opened this issue Oct 26, 2023 · 1 comment · Fixed by #3684
Closed

Indented code examples in markdown are not checked #3672

MateuszKubuszok opened this issue Oct 26, 2023 · 1 comment · Fixed by #3684

Comments

@MateuszKubuszok
Copy link

MateuszKubuszok commented Oct 26, 2023

I have markdown documentation with examples which I want to check for code formatting.

My examples are often indented, and it seems that this indentation makes them ignored.

Configuration

.scalafmt.conf reproducing the issue:

version = 3.7.15
#project.git = true
project.includePaths."+" = ["glob:**.md"]
maxColumn = 120
runner.dialect = Scala213Source3
fileOverride {
  "glob:**/src/main/scala-3/**" { runner.dialect = scala3 }
  "glob:**/src/test/scala-3/**" { runner.dialect = scala3 }
}

align.preset = some

rewrite.rules = [Imports, RedundantBraces, SortModifiers]
rewrite.imports.sort = scalastyle
rewrite.redundantBraces.stringInterpolation = true

rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.removeOptionalBraces = false

docstrings.blankFirstLine = no
docstrings.style = SpaceAsterisk
docstrings.wrap = no

newlines.sometimesBeforeColonInMethodReturnType = true
lineEndings=unix

Command-line parameters

scalafmt --check

Steps

I attempted to check formatting for:

```scala mdoc
//> using dep io.scalaland::chimney::{{ git.tag or local.tag }}
import io.scalaland.chimney.Transformer

case class Foo   (a    : String)
```

!!! example

    ```scala mdoc
    //> using dep io.scalaland::chimney::{{ git.tag or local.tag }}
    import io.scalaland.chimney.Transformer

    case class Foo   (a   : String)
    ```

While !!! example can be considered non-standard Markdown extension, the following is pretty standard but also doesn't work:

```scala mdoc
//> using dep io.scalaland::chimney::{{ git.tag or local.tag }}
import io.scalaland.chimney.Transformer

case class Foo   (a    : String)
```

  * example inside a bullet point list:

    ```scala mdoc
    //> using dep io.scalaland::chimney::{{ git.tag or local.tag }}
    import io.scalaland.chimney.Transformer

    case class Foo   (a   : String)
    ```

Problem

Output is:

--- a/Users/dev/Workspaces/GitHub/kanapeczka/test.md
+++ b/Users/dev/Workspaces/GitHub/kanapeczka/test.md
@@ -4,3 +4,3 @@

-case class Foo   (a    : String)
+case class Foo(a: String)
 ```
error: --test failed

It checks only non-indented code example, and skips the indented one.

Expectation

I would like the formatted output to look like this:

--- a/Users/dev/Workspaces/GitHub/kanapeczka/test.md
+++ b/Users/dev/Workspaces/GitHub/kanapeczka/test.md
@@ -4,3 +4,3 @@

-case class Foo   (a    : String)
+case class Foo(a: String)
 ```
--- a/Users/dev/Workspaces/GitHub/kanapeczka/test.md
+++ b/Users/dev/Workspaces/GitHub/kanapeczka/test.md
@@ -14,3 +14,3 @@
-    case class Foo   (a   : String)
+.   case class Foo(a: String)
 ```

error: --test failed

Workaround

I don't have one if I want to keep my current formatting (which would degrade the UX).

Note

I haven't checked, but probably the same situation would be with blockquites. This

example

> example
>
> ```scala mdoc
> type X = Foo Either Bar
> ```

would also be valid markdown.

@kitbellew
Copy link
Collaborator

@MateuszKubuszok i apologize, i read your submission several times and i don't think i understand what is supported, what is not, why you are talking about unsupported markdown extensions or blockquotes, and what you expect. could you please provide several explicit pairs?

i must say that we might need help from the original author of this functionality, @swoogles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants