Mafia source code formatting

heeheehee

Developer
Staff member
If you’re using IntelliJ, there’s a syntax file on the wiki. There may be files for other IDEs. Otherwise, I agree with heeheehee. I would be happy to add an ANT target to format modified source pages if I had a tool with that feature.
Splitting this discussion off from https://kolmafia.us/threads/25944.

So, there's an existing util/format.xml in the repo, although that isn't perfect (I tried running it on a few sample files, and the diff was... large). Poking around on the wiki has https://wiki.kolmafia.us/index.php/File:KoLMafia_Style.xml so I've copied that into util/ to see if it works any better.

I've installed IntelliJ, accepted its terms of service, and run the following command:

Bash:
$ idea format -s util/intellij.xml -m '*.java' src/net/sourceforge/kolmafia/request

That was... a bit too optimistic. I think there's some amount of work to get it to match our current coding style.

But that said, I don't know that anyone's particularly attached to the current style. What if we just... switched to some established standard?
 

heeheehee

Developer
Staff member
(I think for some reason, the CLI command didn't use the xml file at all. Which is also weird.)

Some initial differences I'm noting from using the GUI:
- spaces instead of tabs.
- no spaces in brackets (e.g. arr[ 0 ] -> arr[0])
- preference for Very Long lines (admittedly, we never had a line limit, but maybe we should...)
 

MCroft

Developer
Staff member
I put that IJ file on the wiki, based on Veracity sending me her first pass at it and me documenting how to install it. It's totally updatable and I'd be happy to take a new version if you want to make and publish it
 

heeheehee

Developer
Staff member
My first pass (attached). I'm still not totally happy with some things it does with respect to current style (alignment for else-if statements, among other things), but yeah, my general preference is to accept the formatting that a tool provides so we don't quibble over minor details like this.

And tools usually have better support for more common use cases.
 

Attachments

  • intellij.xml
    3.8 KB · Views: 4

heeheehee

Developer
Staff member
That said, it seems like the way to go for IntelliJ is to include an .editorconfig file at the root of the repo. I think.
 

MCroft

Developer
Staff member
I think we determined that editorconfig was good in that it was cross-tool, but not very good because it didn't support very much.

IIRC, the main thing people used to care about was cuddling curly braces.
 

fronobulax

Developer
Staff member
When it has come up before this is the KoLmafia coding and formatting standard, with exceptions. We can change but it would be interesting to see if the new standard is as complete.

The exception I remember because it would not have been my choice is where an opening curly bracket goes.

I just accepted what everyone else said on tabs vs spaces.

I pretty much don't care about formatting. Give me a configuration file and an IDE command to apply it and I'm fine. But don't include the configuration file in a way that forces me to use it for non-KolMafia projects :)
 
Top