-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use an automatic code formatter #517
Comments
I experimented with JuliaFormatter a bit and results are a bit underwhelming. The default is to break lines after math signs (+, -, *, /, etc), not before as we want it. Same applies to |
I posted an issue in JuliaFormatter: domluna/JuliaFormatter.jl#683 (comment) |
Yes, I remember there being some slightly annoying styling differences that took a while to get used to. I never bothered to learn to tweak the formatter, and I'm not sure if it's worth it if its not straightforward to set up. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry @clizbe - we need this issue, the problem is we don't have the resources yet, but it should be possible to develop a custom SpineOpt style using JuliaFormatter.jl. |
This comment was marked as resolved.
This comment was marked as resolved.
@manuelma Although is it really In Progress or still a ToDo? I gave it a "Soon" priority and it'll be on our radar - but I like to reserve In Progress for things being actively programmed this week. |
From our CONTRIBUTING:
|
@abelsiqueira Can you help with setting all this up so we get everyone on one page and don't have conflicts? |
That list is not exhaustive though - there are other things. I guess the final test is to run the code formatter and find minimal changes with respect to the current formatting. |
Before setting the formatter, how do you want to run it? The traditional ways are:
If you use the pre-commit version, it can also be used to as a GitHub action to check that everything is working. PS. In Tulipa, we use pre-commit and we additionally format and lint other files (markdown, yaml, etc.), and do some other "fun" things (e.g., check broken links in markdown). |
A few of these required formatting options are not options in JuliaFormatter, but default. But since we also use some basic pre-commit options and EditorConfig, I am not sure. indent = 4
margin = 119 And then also add a EditorConfig config to enforce some of the others in the editor (below is copied from Tulipa)
|
I like pre-commit - we'll just need to set it up and have instructions for the group. |
In Toolbox each dev runs it manually. We considered the pre-commit at some point, not sure why we didn't go with it? @PekkaSavolainen @soininen do you recall? Or have any thoughts here? |
I do not recall any discussion or decisions on the topic. I thought it was left for the developer to turn it on of off but now I see we have the Personally, I like the pre-commit hook option. However, some developers may dislike it because it forces you to commit again if any code was formatted, or at least that is what I remember. Perhaps it just needs some getting-used-to? |
You can have the |
@abelsiqueira I'm messing with the formatter, trying to find settings that most closely match our current style, but have a problem. My Format on Save is ignoring my JuliaFormatter.toml. If I start a Julia session and run:
It uses JuliaFormatter.toml. If I change formatting in the file (like remove a space around an "=") and hit CTRL+S, it reformats it, but ignores the settings in JuliaFormatter.toml. -_- @datejada has been trying to help but we can't figure it out. |
Using ALT+SHIFT+F also ignores the JF.toml. |
What if you copy the make.jl from |
Same behavior. |
@manuelma Is this something we'd like? If a field is untyped then it auto-formats to specify ::Any. Then we can see easier when it's happening. |
I don't have any good suggestion. Monday we can check it. |
Maybe the person who is working on fixing the type unstabilities can use that locally, but I don't think it belongs in the official source code so to say. Or at least that's my preference (::Any doesn't add much to the code's readability). But it's very nice to know. |
@abelsiqueira I've gotten it almost "perfect" where it makes minimal changes to a sample. Any idea how to keep it from doing these? Don't waste your time if it'll take too much searching. @manuelma
Right now, these are both set to "nothing" meaning the Formatter leaves whatever the user chooses, but if we choose something for consistency, the Formatter can apply it everywhere. |
I think true is better (assuming we are talking of multiline lists of course). And yes, we haven't been really consistent on this one.
This I think we can leave it as nothing? I'm not sure, is it possible to see what changes in our code if one sets it to true? |
@clizbe, I don't know where the first one comes from, and I wish I did, because I'd like to change it too. The second happen because the |
@abelsiqueira I think I've figured out the settings and have reformatted src - but just remembered that my Format On Save is ignoring my JuliaFormatter.toml still. Do you have time to help me with this (maybe in a call?) and with next steps for implementing the formatter for everyone? |
I have the time. Just need ~5 min to setup. Send me a Teams invite pls. |
Waiting for domluna/JuliaFormatter.jl#739. The issue is that it pushes operators to separate lines. |
We discussed using a code formatter to unify our style, @Tasqu mentioned https://github.com/domluna/JuliaFormatter.jl ? It seems like it's the way to go. Any opinions?
The text was updated successfully, but these errors were encountered: