mogular / powerquery-formatter-examples

9 stars 1 forks source link

String literals are altered on paste #15

Closed AmeliaSZK closed 4 years ago

AmeliaSZK commented 4 years ago

Description In the web formatter, when pasting code to format, string literals with leading spaces (plural) are altered to leave only 1 leading space.

Power Query- / M-Code Copied:

let
    Source = "Start the description with an action verb and a 1-sentence description of what the function does. " &
            "<p>" &
            "Some HTML tags can be used. <br>Notably, these work: " &
            "<ul>" &
            "<li> <b>bold</b>" &
            "<li> <i>italics</i>" &
            "<li> <code>code</code>" &
            "</ul>" &
            "These do not work:" &
            "<ul>" &
            "<li> " &
                "<dl>" &
                "    <dt>Definition List</dt>" &
                "    <dd>A list of terms to define.</dd>" &
                "" &
                "    <dt>Definition Term</dt>" &
                "    <dd>Definition Definition.</dd>" &
                "</dl>" &
            "<li> <u>underlined</u>" &
            "<li> <strong>strong</strong>" &
            "<li> <em>emphasis</em>" &
            "<li> <mark>mark</mark>" &
            "<li> <small>small</small>" &
            "<li> <del>deleted</del>" &
            "<li> <ins>inserted</ins>" &
            "<li> <sub>subscript</sub>" &
            "<li> <sup>superscript</sup>" &
            "</ul>" &
            "<ol> <li>Ordered list</li></ol>" &
            "<br>" &
            "<h1>Headings</h1>" &
            "<br>" &
            "<hr>Horizontal rule</hr>" &
            "<br>" &
            "<q>Short quote</q>" &
            "<br>" &
            "<blockquote cite=""https://www.google.com"">Blockquote</blockquote>" &
            "<p>" &
            "Tables work, but not their headers:" &
            "<table>" &
            "  <tr>" &
            "    <th>Game</th>" &
            "    <th>Year of Release</th>" &
            "  </tr>" &
            "  <tr>" &
            "    <td>Three Kingdoms</td>" &
            "    <td>2019</td>" &
            "  </tr>" &
            "  <tr>" &
            "    <td>Thrones of Britannia</td>" &
            "    <td>2019</td>" &
            "  </tr>" &
            "</table>" &
            "<p>" &
            "Neither do tbody and thead:" &
            "<table>" &
            " <thead>" &
            "  <tr>" &
            "    <th>Game</th>" &
            "    <th>Year of Release</th>" &
            "  </tr>" &
            " </thead>" &
            " <tbody>" &
            "  <tr>" &
            "    <td>Three Kingdoms</td>" &
            "    <td>2019</td>" &
            "  </tr>" &
            "  <tr>" &
            "    <td>Thrones of Britannia</td>" &
            "    <td>2019</td>" &
            "  </tr>" &
            " </tbody>" &
            "</table>"
in
    Source

Pasted:

let
Source = "Start the description with an action verb and a 1-sentence description of what the function does. " &
"<p>" &
"Some HTML tags can be used. <br>Notably, these work: " &
"<ul>" &
"<li> <b>bold</b>" &
"<li> <i>italics</i>" &
"<li> <code>code</code>" &
"</ul>" &
"These do not work:" &
"<ul>" &
"<li> " &
"<dl>" &
" <dt>Definition List</dt>" &
" <dd>A list of terms to define.</dd>" &
"" &
" <dt>Definition Term</dt>" &
" <dd>Definition Definition.</dd>" &
"</dl>" &
"<li> <u>underlined</u>" &
"<li> <strong>strong</strong>" &
"<li> <em>emphasis</em>" &
"<li> <mark>mark</mark>" &
"<li> <small>small</small>" &
"<li> <del>deleted</del>" &
"<li> <ins>inserted</ins>" &
"<li> <sub>subscript</sub>" &
"<li> <sup>superscript</sup>" &
"</ul>" &
"<ol> <li>Ordered list</li></ol>" &
"<br>" &
"<h1>Headings</h1>" &
"<br>" &
"<hr>Horizontal rule</hr>" &
"<br>" &
"<q>Short quote</q>" &
"<br>" &
"<blockquote cite=""https://www.google.com"">Blockquote</blockquote>" &
"<p>" &
"Tables work, but not their headers:" &
"<table>" &
" <tr>" &
" <th>Game</th>" &
" <th>Year of Release</th>" &
" </tr>" &
" <tr>" &
" <td>Three Kingdoms</td>" &
" <td>2019</td>" &
" </tr>" &
" <tr>" &
" <td>Thrones of Britannia</td>" &
" <td>2019</td>" &
" </tr>" &
"</table>" &
"<p>" &
"Neither do tbody and thead:" &
"<table>" &
" <thead>" &
" <tr>" &
" <th>Game</th>" &
" <th>Year of Release</th>" &
" </tr>" &
" </thead>" &
" <tbody>" &
" <tr>" &
" <td>Three Kingdoms</td>" &
" <td>2019</td>" &
" </tr>" &
" <tr>" &
" <td>Thrones of Britannia</td>" &
" <td>2019</td>" &
" </tr>" &
" </tbody>" &
"</table>"
in
Source

Formatted:

let
  Source
    = "Start the description with an action verb and a 1-sentence description of what the function does. "
      & "<p>"
      & "Some HTML tags can be used. <br>Notably, these work: "
      & "<ul>"
      & "<li> <b>bold</b>"
      & "<li> <i>italics</i>"
      & "<li> <code>code</code>"
      & "</ul>"
      & "These do not work:"
      & "<ul>"
      & "<li> "
      & "<dl>"
      & " <dt>Definition List</dt>"
      & " <dd>A list of terms to define.</dd>"
      & ""
      & " <dt>Definition Term</dt>"
      & " <dd>Definition Definition.</dd>"
      & "</dl>"
      & "<li> <u>underlined</u>"
      & "<li> <strong>strong</strong>"
      & "<li> <em>emphasis</em>"
      & "<li> <mark>mark</mark>"
      & "<li> <small>small</small>"
      & "<li> <del>deleted</del>"
      & "<li> <ins>inserted</ins>"
      & "<li> <sub>subscript</sub>"
      & "<li> <sup>superscript</sup>"
      & "</ul>"
      & "<ol> <li>Ordered list</li></ol>"
      & "<br>"
      & "<h1>Headings</h1>"
      & "<br>"
      & "<hr>Horizontal rule</hr>"
      & "<br>"
      & "<q>Short quote</q>"
      & "<br>"
      & "<blockquote cite=""https://www.google.com"">Blockquote</blockquote>"
      & "<p>"
      & "Tables work, but not their headers:"
      & "<table>"
      & " <tr>"
      & " <th>Game</th>"
      & " <th>Year of Release</th>"
      & " </tr>"
      & " <tr>"
      & " <td>Three Kingdoms</td>"
      & " <td>2019</td>"
      & " </tr>"
      & " <tr>"
      & " <td>Thrones of Britannia</td>"
      & " <td>2019</td>"
      & " </tr>"
      & "</table>"
      & "<p>"
      & "Neither do tbody and thead:"
      & "<table>"
      & " <thead>"
      & " <tr>"
      & " <th>Game</th>"
      & " <th>Year of Release</th>"
      & " </tr>"
      & " </thead>"
      & " <tbody>"
      & " <tr>"
      & " <td>Three Kingdoms</td>"
      & " <td>2019</td>"
      & " </tr>"
      & " <tr>"
      & " <td>Thrones of Britannia</td>"
      & " <td>2019</td>"
      & " </tr>"
      & " </tbody>"
      & "</table>"
in
  Source

Expected behavior String literals should never be altered by a code formatter. (Btw, I really like how you put the & in front of the line instead of at the end 👀)

Settings All defaults.

AmeliaSZK commented 4 years ago

Update: Embedded newlines in string literals are also removed during formatting (they are preserved during paste), and non-leading consecutive spaces are also removed during paste.

I didn't make a whole new issue because I suspect the fix will be the same for both.

Copied

let
  Result = 
"[Key]                       [Name]      [Differentiated]
wh2_main_lothern            Lothern     Lothern
wh2_dlc09_tomb_kings        Tomb Kings  Tomb Kings
wh2_dlc09_tomb_kings_qb1    Tomb Kings  Tomb Kings (Qb1)
wh2_dlc09_tomb_kings_qb2    Tomb Kings  Tomb Kings (Qb2)"
in
  Result

Pasted

let
Result =
"[Key] [Name] [Differentiated]
wh2_main_lothern Lothern Lothern
wh2_dlc09_tomb_kings Tomb Kings Tomb Kings
wh2_dlc09_tomb_kings_qb1 Tomb Kings Tomb Kings (Qb1)
wh2_dlc09_tomb_kings_qb2 Tomb Kings Tomb Kings (Qb2)"
in
Result

Formatted

let
  Result
    = "[Key] [Name] [Differentiated] wh2_main_lothern Lothern Lothern wh2_dlc09_tomb_kings Tomb Kings Tomb Kings wh2_dlc09_tomb_kings_qb1 Tomb Kings Tomb Kings (Qb1) wh2_dlc09_tomb_kings_qb2 Tomb Kings Tomb Kings (Qb2)"
in
  Result

Expected behavior Not sure what I should be expecting from a formatter beyond "don't alter string literals" in such an edge case. The funky formatting in the literal is because it's meant to be used in the Result field of a Documentation.Examples record.

UliPlabst commented 4 years ago

Thanks again for this report. I just deployed the fix.