LuaFormatter icon indicating copy to clipboard operation
LuaFormatter copied to clipboard

When --[[ style comments are used, the following line gets collapsed into the comment

Open TheCycoONE opened this issue 4 years ago • 5 comments

Using the default config (though I didn't see any config line that would change it), multiline comments using the --[[ --]] syntax get collapsed into the next instruction.

This is in spite of the empty line that was between the comment and the instruction.

diff --git a/CorsixTH/Lua/app.lua b/CorsixTH/Lua/app.lua
index f3d18e8b..a9599952 100644
--- a/CorsixTH/Lua/app.lua
+++ b/CorsixTH/Lua/app.lua
@@ -16,9 +16,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE. --]]
-
-local pathsep = package.config:sub(1, 1)
+SOFTWARE. --]] local pathsep = package.config:sub(1, 1)

TheCycoONE avatar Jul 04 '21 16:07 TheCycoONE

Same Problem

BillScott1024 avatar Aug 18 '21 04:08 BillScott1024

I found a similar case. Here's a diff showing that the formatter wants to awkwardly join a comment to the end of the previous line:

 -- Formatter Configuration
-
 require('format').setup {
   ['*'] = {
     {
       cmd = {
         -- Trim trailing spaces
-        [[sed -i 's/\s*$//']],
-
-        -- Trim extra trailing newlines (but not the final newline)
-        [[sed -i -e ':a' -e '/^\n*$/{$d; N}' -e '/\n$/ba']]
-      }
-    }
+        [[sed -i 's/\s*$//']], -- Trim extra trailing newlines (but not the final newline)
+        [[sed -i -e ':a' -e '/^\n*$/{$d; N}' -e '/\n$/ba']],
+      },
+    },

ZeroKnight avatar Oct 02 '21 09:10 ZeroKnight

Yep, same here

Nick-Mazuk avatar Mar 27 '22 19:03 Nick-Mazuk

here's a nice easy repo case

--[[ hello ]]
local foo = 1
print(foo)

turns into

--[[ hello ]] local foo = 1
print(foo)

I think the local foo = 1 should remain on its own line.

arkarkark avatar Sep 19 '23 09:09 arkarkark