MCAD icon indicating copy to clipboard operation
MCAD copied to clipboard

Implement and apply openscad-format

Open Maxattax97 opened this issue 5 years ago • 5 comments

This automates the task of code formatting for the whole repo. Simply execute ./format.py

Maxattax97 avatar Mar 13 '19 17:03 Maxattax97

I think we probably want to discuss the formats before doing this. While I haven't done much thinking yet (except indent should be 2 chars), I noticed this: Capture format Whitespace in the path is not good. I don't think fiddling with the order (or position) of include & use is a good idea.

MichaelAtOz avatar Mar 13 '19 22:03 MichaelAtOz

Looks like a bug due to the dashes, I'll fix that, bump the NPM version, and update the results here. I'll also add some options for custom formatting... it uses some hacks with Clang to format it.

On order and position: the only edge case I can think if that would be beneficial is when you have an include/use inside of a module, e.g. for testing... is that right? The other issue I'm seeing is keeping them after header comments (at the top of files), but that's a relatively easy fix.

I just made the formatter the other day and thought I'd poke you folks for interest since it's a bigger repo.

EDIT: Also, from the README...

I'd prefer to have all included code nicely indented, at least at the block level, and no extraneous whitespace. I'm used to *indent with four spaces as opposed to tabs* or other mixes of whitespace, but at least try to choose a style and stick to it.

But I don't really know who manages the repo anymore.

Maxattax97 avatar Mar 14 '19 03:03 Maxattax97

MCAD repo is 'managed' by the same main OpenSCAD community, it gets little love, as changing it opens up a can of worms. Two spaces is my personal preference, I mentioned it to poke some debate. Order is critical any include<> or use<> could depend on one-another, position relative to comments less so, I agree header comments should go first. Position relative to other code is critical, see here, also include<> can be used to bring in arbitrary text not just whole modules/functions etc & either could be in another scope (e.g module as you say). So I wouldn't be moving anything.

MichaelAtOz avatar Mar 14 '19 04:03 MichaelAtOz

Since you bring the difficulty with changing MCAD, I'll bring up a repo I've been building this formatter (and also a language server based on pygls) for. My hope is to keep the convention very strict, the code base very stable, and offer a wide array of well documented modules/functions including HTML docs. I'm working on creating the other tools first, but some sample code is in the util folder.

But back on topic, what you've explained makes sense. The main issue with hacking Clang is the include/use syntax must be converted before it's parsed, however I think I have an idea. Fixes coming soon. :+1:

Maxattax97 avatar Mar 14 '19 04:03 Maxattax97

That should fix the includes, and the indentation is now to your preference. Whatever you folks decide on, it can be changed via the .openscad-format configuration file, which follows clang-format's format which you can find here.

Maxattax97 avatar Mar 15 '19 05:03 Maxattax97