-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Style package with new {mlr.styler} package #626
Conversation
R/BenchmarkResult.R
Outdated
} | ||
), | ||
|
||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC we discussed about this pattern/change the last time already and agreed to allow both options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this on another repo and in our old mlr-style this was not changed by {styler} -> @lorenzwalthert can we remove this styling? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, there was a transformer for that,but for some reason, it was commented out in the revision of your fork I used when c/p the transformers. Adressed in mlr-org/styler.mlr#7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a possible misunderstanding?
I meant to say that we want to allow the
}
)
pattern. And avoid a styling into })
.
I think this is why I commented out this transformer at some point.
I see that in the pull you explicitly commented it in again.
Assuming that it was commented out in this current draft - why did this styling happen then? 🤔
Or am I on the wrong path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, there was a misunderstanding (and also merge conflicts). We want to activate the rule that adds a line break if there is none and remove the rule that removes the line break. Force pushed to mlr-org/styler.mlr#7 after rebasing on main.
R/LearnerClassifDebug.R
Outdated
error_predict = p_dbl(0, 1, default = 0, tags = "predict"), | ||
error_train = p_dbl(0, 1, default = 0, tags = "train"), | ||
message_predict = p_dbl(0, 1, default = 0, tags = "predict"), | ||
message_train = p_dbl(0, 1, default = 0, tags = "train"), | ||
predict_missing = p_dbl(0, 1, default = 0, tags = "predict"), | ||
error_predict = p_dbl(0, 1, default = 0, tags = "predict"), | ||
error_train = p_dbl(0, 1, default = 0, tags = "train"), | ||
message_predict = p_dbl(0, 1, default = 0, tags = "predict"), | ||
message_train = p_dbl(0, 1, default = 0, tags = "train"), | ||
predict_missing = p_dbl(0, 1, default = 0, tags = "predict"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC we had support for this in the old fork - was there a specific transformer or did we do a hacky island solution here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment is supported in general with {styler}, but only with right-alignment:
styler.mlr::style_text(
'call(
x = 2,
uz = 333
)
'
)
#> call(
#> x = 2,
#> uz = 333
#> )
Created on 2021-04-13 by the reprex package (v1.0.0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to manually align them to one of the supported alignments in https://styler.r-lib.org/articles/detect-alignment.html to make sure styler does not destroy the formatting of deliberately aligned code. Of course, we could also work on supporting the above alignment style. PRs to styler welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left alignment support on the way: r-lib/styler#774
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I force pushed a full pkg styling with the most recent status of {mlr.styler}.
I assume we need to import the recent changes from upstream styler to get the left alignment working?
Other than that, it looks pretty good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to have the devel version of styler with 9f9bdff
at least yes. I am adding a minimal version requirement to {styler.mlr} aud bump the devel version in {styler}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I suggest to re-style git reset
and re-style and force push (re-style won't restore previous alignment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
resetted and restyled - some more alignment takes it seems :)
@pat-s thanks, will look into it tomorrow. Alternatively, you could make one PR per scope, starting with |
R/BenchmarkResult.R
Outdated
@@ -215,6 +218,7 @@ BenchmarkResult = R6Class("BenchmarkResult", | |||
#' | |||
#' @return [data.table::data.table()]. | |||
aggregate = function(measures = NULL, ids = TRUE, uhashes = FALSE, params = FALSE, conditions = FALSE) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of enforcing a newline here. Any reason to keep this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find a reference anymore in the style guide but at some point the idea was to leave a blank line when the function declaration is long. Assuming you have a function declaration somewhere that has a blank line at the top, would you want to remove it or simply not touch it? If we don't touch it, we also can't touch
{
# code
}
easily (because of the inner workings of styler). A compromise would be to allow up either one or zero blank lines in any of these two curly brace expressions, but not more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find a reference anymore in the style guide
The style guide might also not be 100% up-to-date 😅
I think being deliberate here is probably best - i.e. allowing both.
A compromise would be to allow up either one or zero blank lines in any of these two curly brace expressions, but not more.
Sounds like a good compromise to me (if that is easier for {styler} also). @mllg?
I think we never want to have two blank lines anywhere and any of zero or one is fine?
Just a short comment for now. Points 11 and 17 in the mlr style guide seem to have evolved to the opposite so |
Yeah, the guide is probably not up-to-date or followed fully in practice. The same goes for explicit namespacing I think - this is probably also not trivial and would require quite some magic to infer this from the function name. But yeah, we should probably adjust this in the guide. |
3451a84
to
d63c553
Compare
new = c("bill_length", "bill_depth", "flipper_length", "body_mass") | ||
new = c("bill_length", "bill_depth", "flipper_length", "body_mass") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lorenzwalthert DO you have an idea why this alignment is not honoured?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because spacing is only honoured one level deep. This is two level deep (function call in function call). Sorry, styler can't do this. Use strict = FALSE
if you want to preserve one more more space here (but it comes with other implications as shown in the dedicated vignette).
R/mlr_reflections.R
Outdated
~type, ~package, ~task, ~learner, ~prediction, ~measure, | ||
"regr", "mlr3", "TaskRegr", "LearnerRegr", "PredictionRegr", "MeasureRegr", | ||
"classif", "mlr3", "TaskClassif", "LearnerClassif", "PredictionClassif", "MeasureClassif" | ||
~type, ~package, ~task, ~learner, ~prediction, ~measure, | ||
"regr", "mlr3", "TaskRegr", "LearnerRegr", "PredictionRegr", "MeasureRegr", | ||
"classif", "mlr3", "TaskClassif", "LearnerClassif", "PredictionClassif", "MeasureClassif" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lorenzwalthert DO you have an idea why this alignment is not honoured?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because left alignment only works with =
, not with ~
. You must right align here. See lorenzwalthert#2 (comment).
Edit: this should be resolved with latest styler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would adding support for ~
be lots of work? I don't do these alignments personally but I think it would be import for @mllg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried for a few hours and I did not get to work it easily... Maybe I can look into it again since we are on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really niche so really think about if you want to do this :)
Would be great and appreciated of course though 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I found a way to do it and merged it into master: r-lib/styler#785. After the other alignment things were implemented properly, it seemed much easier than I thought initially. Are you happy now? 😀 Please try it out in your example and let me know, I think it should work. I also bumped min version req for {styler} in {styler.mlr} to avoid future destruction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just restyled but it seems it not yet working 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you have an extra wurst with .key = '...'
-.-. Fix on the way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try again xD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems resolved with latest styling, right?
R/mlr_reflections.R
Outdated
~type, ~package, ~task, ~learner, ~prediction, ~measure, | ||
"regr", "mlr3", "TaskRegr", "LearnerRegr", "PredictionRegr", "MeasureRegr", | ||
"classif", "mlr3", "TaskClassif", "LearnerClassif", "PredictionClassif", "MeasureClassif" | ||
~type, ~package, ~task, ~learner, ~prediction, ~measure, | ||
"regr", "mlr3", "TaskRegr", "LearnerRegr", "PredictionRegr", "MeasureRegr", | ||
"classif", "mlr3", "TaskClassif", "LearnerClassif", "PredictionClassif", "MeasureClassif" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because left alignment only works with =
, not with ~
. You must right align here. See lorenzwalthert#2 (comment).
Edit: this should be resolved with latest styler.
@lorenzwalthert The latest diff looks good to me! Thanks a lot for your help and persistence here 🙏 @mllg Are you fine with the diff and hence the style guide? If so, we can merge and I would update the documentation and inform all devs. |
What’s failing here @pat-s ? From a styling point of view, it seems fine now, agree? |
Some git checkout issues, seems random. I think we can ignore it. Styling is fine 👍 |
I think it was a GitHub outage. And now we have a merge conflict. I suggest to resolve it, retrigger styling and then get this merged before more merge conflicts accumulate. |
I'd like to have (at least) an approval by @mllg |
Looks good to me. Thanks @pat-s and @lorenzwalthert for all the work you've put into this. |
Thanks. Given that the errors in CI are also appearing in the main branch and hence are unrelated to this PR, I'll merge this. |
This is a first diff of the new {mlr.styler} package (still private) by @lorenzwalthert.
Lorenz put a lot of time into our mlr-style, not only by creating this new package but also in the past.
It should make updating + maintenance more easy and should also serve as an exemplary package for additional styles next to the
tidyverse_style
.Beforehand we used a fork of mine.
@mllg I am not sure if you use {styler} in practice for {mlr3} but your input on specific re-occurring patterns which are changed in the diff is appreciated.
Remember that we can create the style guide to be passive/non-invasive so that in some cases multiple solutions are allowed / not force styled.
Some years have passed since we evaluated the initial guide. If some of your coding patterns have changed since there, it would now be a good time to discuss these here.
Also cc @berndbischl @mb706 @be-marc @pfistfl @jakob-r @RaphaelS1 (your input is appreciated/desired as well of course as the style applies to all mlr-org repos. {mlr3} is just the demo-repo for now.).
@lorenzwalthert
If there are any new transformers that you know of which would be possibly helpful here, just suggest them :)