Script Auto Format On Save/Close

Studio should have an option to auto0format (fix spaces around operators / commas, fix indentation, etc) upon save / script close.

All real coding IDEs have this feature because it highlights mistakes and avoids style discrepancies. This would significantly help out learners, who would no longer be left with misleading indentation. It would also help manage larger pieces of code and refactoring without having to worry as much.

2 Likes

But then how would classics such as Person299’s code come into existence?

I like this idea, but the only issue is everyone formats their code differently. Personally, I prefer spaces after commas and between code and comment sections, but maybe some people don’t. Also do you propose a way to handle whitespace? If you would want that to be included, there would be a lot of difficulty with decided upon what restrictions to follow as everyone spaces out their code differently.

These settings are configurable in most IDEs.

A handful of toggles/numbers in Studio Settings would cover the large majority of styles in use.

This would be most of them:

  • trailing comma in table literals (allow | always | multi-line | never)
  • spaces after comma (0, 1, 2, …)
  • indent size (1, 2, 3, 4, …)
  • soft / hard indents [it seems ROBLOX wants us to use hard indents though]
  • spaces around operators (never | always | low-precedence only | one-per-precedence)
  • spaces around assignment (either | always | never)
  • no newline after do/repeat/then (allow | don’t allow)
  • spaces inside curly braces (allow | always | never)
  • spaces inside square braces (allow | always | never)
  • spaces for table calls (allow | always | never)
  • spaces for string calls (allow | always | never)
  • spaces before comments (allow | always)
  • comments on same line as statement (allow | never)
  • max number of blank lines in a row (1, 2, 3, …)
  • blank lines at beginning of block (allow | never)
  • blank lines at end of block (allow | never)
  • trailing parenthesis (same line | new line | either)
  • trailing curly brace (same line | new line | either)
  • trailing operation (previous line | next line | either)
  • continue statement indent (align | 1, 2, 3, …)
  • trailing blank lines (0, 1, 2, …)
5 Likes

Eclipse has a lot of nice things where you can specify a lot in a specific way, although that’s mostly for Java.

This code is the one of the major reasons I didn’t indent my code for about a year after learning Lua, then for another year or so after that I developed my own indent style which was terrible :frowning:

I remember reading this comment and thinking that it was a cool style, fortunately I never used it myself though.

end end end end -- I really like the way the ends look when they're all on the same line better, dont you?
6 Likes

I found it basically unreadable when they were all on the same line, so I never did that, luckily, but I remember not indenting my code for the same reason. :confused:

1 Like

Obviously we need to have support for unconventional code styles.

https://pbs.twimg.com/media/CvH9gfFWcAA2knK.jpg:large

This was me. If you looked at my old code… it’s cringe and rage worthy. I don’t even put my mouse on my archive file anymore.

I once submitted an assignment like that, my lecturer loved it :joy:

Since there’s such variance to code styles, I think this would be better implemented as a plugin. But we can’t do that because we need the following:


An event that fires before the place file saves and another that fires when it finishes saving. This would allow us to write plugins that make modifications before saving or only to the saved file. This could be used to automatically format scripts, or to do other things like automatically manage the location of server/client modulescripts, search, find, and create remote* objects to be saved with the place, update model properties, increment version numbers, and more.

I think this would be a much more useful feature overall, and allows for implementing auto-format in a way that any developer can modify for their needs.

3 Likes

Welcome to ROBLOX, where we can achieve a lot by haxing things together.
Done by only using the commandline: https://www.youtube.com/watch?v=zu64yFR25fw
(if script.Source wasn’t protected, even a regular (local)script would’ve been able to do that)

2 Likes