diffplug / spotless

Keep your code spotless
Apache License 2.0
4.57k stars 458 forks source link

spotless:check inconsistent with spotless:apply - flexmark over MD ending with double EOL #1455

Closed blacelle closed 1 year ago

blacelle commented 1 year ago

With the main branch, as reproducible in https://github.com/diffplug/spotless/pull/1454, one can see that:

With a markdown file ending with a codeBlock, flexmark would format the file with 2 trailing EOL. This looks dubious, but why not. However, if combined with a generic format with endsWithNewLine, it leads to spotlessApply and spotlessCheck to be inconsistent which is a pity.

Typical markdown (\ used to escape markdown in markdown):

\```
   someCode
\```

Typical mvn conf:

<configuration>
      <formats>
          <!-- you can define as many formats as you want, each is independent -->
          <format>
              <!-- define the files to apply to -->
              <includes>
                  <include>*.md</include>
              </includes>
              <endWithNewline/>
          </format>
      </formats>
      <markdown>
          <includes>
              <!-- You have to set the target manually -->
              <include>**/*.md</include>
          </includes>

          <flexmark/>
          <!-- has its own section below -->
      </markdown>
</configuration>
nedtwigg commented 1 year ago

<markdown> is a specialized <format>. Every tag you can use inside <format> is also available inside <markdown>. Also order matters (see #1459). The fix here is:

<configuration>
      <markdown>
          <includes>
              <include>**/*.md</include>
          </includes>
          <flexmark/>
              <endWithNewline/>
      </markdown>
</configuration>