Help with formatting Lua code

Hi everyone,

I have been “programming” in Lua for some time and Atom became quite a nice tool for that. I am looking for advice on tools to keep my code formatting consistent. This problem emerged since I have been asked to stick to certain styles in code formatting while applying Pull Requests to other projects on GitHub.

I am confused about how to configure Atom. What would be your advice on tools to use? By formatting, I mean these things:

  • keep 2 spaces for indentations
  • remove trailing spaces
  • remove extra trailing new lines on saving
  • format code as you type
  • format code as you paste
  • some additional things like space after commas in comma-separated arguments inside functions
  • spaces between special characters, etc.

I have been advised on different third-party modules on the top of those provided by Atom, two of which seems very popular:

  • EditorConfig (with .editorconfig), and
  • atom-beauty (with .jsbeautifyrc)

So far, EditotConfig does the work well but there is a conflict with the Whitespace module which I had to disable. atom-beautify also works as a function on demand, e.g. to reformat old files. Then EditorConfig takes over to format code in new files during typing.

The problem I have with atom-beautify is it “beautifies” things I don’t want it to beautify and I have no idea how to configure it. For instance, it adds extra spaces between mathematical operands, such as “*” or “/”, which is annoying. I want spaces between + not * or /. How can I do that?

I guess the final question is what would be your advice on tools to use? Atom is an open-source application with open source tools ready to install but while we have the freedom to choose from, it is also overwhelming :slight_smile:

Thanks

I will give a starter for one. I have installed a command “Run Lua” but I admit that I am not using Lua at the moment. I added it to experiment with Pandoc and Lua filters.
The one important package I would recommend is process-palette which allows definition of a library of commands with arguments and the command can bind to a menu item. Thus you can build a library of Lua commands and see them in your top menu or context menu.
Another point I would add is to consider going up the ladder to install HaXe and from HaXe you can compile into HaXe/Lua. This means that the same common code you write can be “transpiled” into Lua, Javascript, Python and so on. There is a package language-haxe in Atom for HaXe code.

[Adding further notes for comparison]
Below I have copied for reference my run Lua command from process-palette custom setting …

Namespace: process-palette
Action Name: run-lua
Shell Command: lua {fileAbsPath}
Working Directory: blank
Keystroke: blank
Menu: Run,Lua

and in Patterns, select default

The Menu setting places Run > Lua > Run Lua
in top menu bar.

and in file highlight > right click > Run With > Run Lua

Checking on language packages installed …

apm list | grep language

I have language-lua-plus@1.7.0