-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add .JuliaFormatter.toml for contributers #723
base: main
Are you sure you want to change the base?
Conversation
oof I don't like this formatting style at all... I like only 1 normal additional identitation level when having open functions such as name(
arg1, arg2;
kwarg1, kwarg2
) I guess I would need to study the julia formatter docs to see how to achieve this. |
Also, let's put the format check CI here as well, as shown here: https://github.com/SciML/SciMLStyle#juliaformatter |
I added the file to CI and changed its triggers to be the same as the current |
I've read the Jula formatter but I don't know which option corresponds to this: #723 (comment) :( if you know please let me know? |
Honestly, I don't know myself. Might be best to ask the JuliaFormatter team themselves |
Ok so Blue style is closer to what you prefer, from what I can tell. It's also my preferred one over SciML by far. What do you think? |
Btw, in the case of hard formatting, maybe it's best to just enforce it in |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #723 +/- ##
==========================================
- Coverage 92.27% 88.58% -3.69%
==========================================
Files 33 30 -3
Lines 2277 1963 -314
==========================================
- Hits 2101 1739 -362
- Misses 176 224 +48 ☔ View full report in Codecov by Sentry. |
oh yeah we really have to do finish this but I haven't had the time yet. I don't like current style at all though. I don't like that it enforces a line break after every single argument, I find it super pointless... |
Ok, so this new style I made by altering
Personally, I'd prefer if Finally, before this is merged (if it is), there might be a better way to describe the formatting than what we have i.e. if we can specify |
This will become a style for JuliaDyunamics which I'll apply to all repos. So I'll do a PR to the Julia formatter package to add this style. |
I'm not 100% sure if this is what you mean but check out YAS style guide which is inspired by the one used in JuMP. Specifically, see here, is this what you're after? After looking at my preferred compared to YAS style, they are actually very close: YAS is slightly more strict as it additionally imposes
If you want to try out YAS,
|
Grrrrr this is so annoying. here is what I want: funccall(
arg1,
arg2,
arg3,
)
x = 2 # operations
end to instead be funccall(
a, b, c, # same row unless they exceed margin
d, e, g, # notice that this is twice idented, one more from original
)
x = 2 # operations
end but I have no idea how to achieve this based on the current documentation of the formatter. These are the only changes that I care about implementing. For everything else I'm happy to follow the blue style. |
Wait, this is exactly what SciML recommends... I wonder what doesn't work here. |
Yes but SciML indents on the function opening parenthesis, which is bad if functions have long names. I want to ident one level more than the funtion's natural identation :D Maybe I am asking for too much and we should just go with blue style... :( |
Wait but Blue says to do exactly that (scroll down a bit), it just treats kwargs differently. Maybe Blue is the one true style? |
I'm not sure blue style is correct. Here is what I want: function f(
a, b, c, # same row unless they exceed margin
d, e, g, # notice that this is twice idented, one more from original
)
x = 2 # operations
end here is what Blue style does, at least when used with JuliaFormatter.jl: function f(
a,
b,
c,
d,
e,
f,
)
x = 2 # operations
end so there are two differnces: first that I don't want a line break after every single argument, only when they exceed the 92 chars, and second that I prefer a second level of identation when writing the function arguments, so that the function closing parenthesis has 1 level of identation, just like the function code. I can live with second thing being unsatisfied. I can live with this: function f(
a, b, c, # same row until 92 chars
e, f, g,
)
x = 2
end but what I cannot live with, 100%, is enforcing a line break after every single function argument. |
with everything else in the blue style I am completely fine with btw. Let's just try to see if we can address this issue and if not, we give up and go with blue style... :( |
I like not to have line breaks after each argument too, fortunately if I read correctly actually the SciML format should be okay? From the docs:
|
The example given to this point: # Yes
function my_large_function(argument1, argument2,
argument3, argument4,
argument5, x, y, z)
# No
function my_large_function(argument1,
argument2,
argument3,
argument4,
argument5,
x,
y,
z)
This is exactly what @Datseris wrote in his example above. |
yes the only difference is that this: function my_large_function(
argument1, argument2, argument3,
argument4, argument5, x, y, z)
s = 3
end in SciMLStyle will be converted to function my_large_function(argument1, argument2, argument3,
argument4, argument5, x, y, z)
s = 3
end but even these sintaxes are allowed: function my_large_function(argument1,
argument2, argument3, argument4,
argument5, x, y, z)
s = 3
end
function my_large_function(argument1,
argument2, argument3,
argument4, argument5,
x, y, z)
s = 3
end the difference is then that it wants to put at least one argument at the name of the function level. it doesn't sound bad to me. But It isn't very enforcing since one can choose one or the other way and it will be allowed. Maybe this is a weak point though |
Last option: make a new function definition setting an option :D Maybe it is not that hard to create a new setting like this in JuliaFormatter, who knows |
I think this is the option to consider. If not possible, we just go with:
which is what the SCimlStyle will do (I think). p.s. notice that this PR needs to be re0opened due to the huge amount of code changes that have happened in the meantime. |
Actually 3 weeks ago the SciML style changed enforcing the double-indent style so now it is usable as it is! See domluna/JuliaFormatter.jl#776 |
I think we should keep it on the same PR for discoverability, but yes throw away the changes, pull from main, and add a formatting merge commit. |
ok, can you do that with the new SciML formatter? |
a4b302c
to
37d3a13
Compare
Strangely, when I run Can anyone else try checking out main, adding the newest version of JuliaFormatter to their base env and running Additionally precompiling I get the following error: (Agents) pkg> precompile
Precompiling project...
✗ Agents
0 dependencies successfully precompiled in 6 seconds. 104 already precompiled.
ERROR: The following 1 direct dependency failed to precompile:
Agents [46ada45e-f475-11e8-01d0-f70cc89e6671]
Failed to precompile Agents [46ada45e-f475-11e8-01d0-f70cc89e6671] to "/Users/smit/.julia/compiled/v1.9/Agents/jl_d8Uy3I".
ERROR: LoadError: MethodError: no method matching namify(::Nothing) |
Already tried...same error as you, it is probably a bug in the formatter...
this makes me think that enforcing it on CI could be just too much struggle for contributors. If you try |
Judging from |
That's a shame :/ |
I think that for this chapter of the saga we should just merge a formatting refactoring + a .juliaformatter.toml file and in the sequel add the CI work :D |
Sure, but first |
Found the bug with model_standard.jl and opened an issue here domluna/JuliaFormatter.jl#779 It is on line 229:
to overcome use:
|
The other macro bug is probably domluna/JuliaFormatter.jl#669 |
Thanks for the efforts! I'm trying to keep track of this. Where are we now? We need to make the change of #723 (comment) in the code. Regarding the |
I don't think there's a "disable macro formatting" option, but it seems to be being worked on in some form. Perhaps the outcome will be that we disable formatting for all of our own macros via the options, that seems reasonable. |
If you want more control over nesting, such as avoiding 1 argument per line I suggest turning on join_lines_based_on_source https://domluna.github.io/JuliaFormatter.jl/dev/#join_lines_based_on_source |
I found out a way to make automatic formatting recommendations in PRs. Because it is just suggestions in the form of GitHub comments, it is not a barrier to new contributors. So what's left now is to finish a formatter. @jacobusmmsmit do you perhaps have any time to help me? We can chat on Slack and see realtime the formatting that comes out . I don't know the JuliaFormatter yet but you have already lots of experience. It won't take long time, if we can't find the optimal options I want, we'll settle to whatever is closer and already available. |
This pull request adds a configuration file to be used with JuliaFormatter.jl, the built-in formatter of Julia for VSCode and the most popular one in general.
This will allow a consistent style to be enforced throughout the repository and make the code more similar to related packages in the Julia ecosystem.