-
Notifications
You must be signed in to change notification settings - Fork 73
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
Detect alignment #258
Comments
Related: #317 |
May want to check overlap with https://github.com/seasmith/AlignAssign and learn from it. |
I think we should take a different path. I see two important cases now: Multi-line function calls with named argumentsThey should be classified as aligned if argument values are left-aligned, argument values are right-aligned and commas match position. call(
x = 1, kdd = 2,
xy = 2, n = 33,
) We first detect if the arguments are aligned. This is the case when they match the above layout. We can implement this as follows:
These checks, however, would classify the following as aligned call(
x = 1, kdd = 2,
xy = 22, n = 33,
) Because the argument values are not in the same nest as the argument name and Multi-line function calls with unnamed argumentsThey should be classified as aligned if the first column is left-aligned (to respect indention rules), the remaining columns are right-aligned and all commas but those in the first column match position. call(
1111, 2,
2, 33,
) This would involve a similar procedure, namely:
Mixed function callscall(
x = 2, 4, c = f(a, b),
1, 44, de = ffk(a, b, c)
) Hence, in the most general form:
Checks must be performed for any multi-line function call (with or without call(1,
another = 3,
text = f(a, b = 33, x == 3)
) The mixed case is the general case and hence, the pure other cases were only developed here because we can resolve them in a unified manner (a one-stop solution). It is not clear what happens with multi-line calls that have multi-line calls within them, but arguably the rules should not depend on that: call(
first, second___ = call(
x = 3, a = f(g), ggh
), third_row_of_first_column,
col1., col2_l = 9
) Assignmenta <- 3
ab <- 3 This is a case I have not looked at because it was not so common. We can have a look later. What do you think? cc: @pat-s CommentsNot looked at ab # here
a # here |
Sounds good. Would fit good into the "strict" idea of styler then. There might be even more problems to tackle for R6 notation. Supporting custom alignment of dictionaries is an important one and a good one to start with :) (I guess it applies more often to R6 than to S3) |
@pat-s @krlmlr are you interested in reviewing the vignette on alignment detection? https://styler.r-lib.org/articles/detect-alignment.html? It was hard for me to write it such that it's easy to understand, yet most of it should be pretty intuitive. But I feel the text is complicated. It would be nice if we could get that right before styler v1.2.0. |
UPDATE: Alignment detection was implemented for function calls: https://styler.r-lib.org/articles/detect-alignment.html
~
in function calls likecase_when()
and friends.Rough outline:
The text was updated successfully, but these errors were encountered: