Skip to content

Code style - #663

Merged
krlmlr merged 7 commits into
r-lib:masterfrom
krlmlr:f-styler
Oct 25, 2017
Merged

krlmlr merged 7 commits into
r-lib:masterfrom
krlmlr:f-styler

Conversation

@krlmlr
krlmlr requested a review from hadley October 24, 2017 11:44

@hadley hadley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall. I added a few comments

Comment thread R/expect-equality.R
#' @param ... other values passed to [all.equal()]
expect_equal <- function(object, expected, ..., info = NULL, label = NULL,
expected.label = NULL) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally styler wouldn't strip this new line. It doesn't matter here, but in general it seems like a bad idea

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define a rule when to add/keep a newline after an opening brace? Is this just for top-level functions or for blocks in general?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I generally prefer a newline if the function def span multiple lines as it more clearly distinguishes the body from the args.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we

  • Add a section to the tidyverse style guide to leave one line blank after a multi-line function declaration and
  • make styler in general preserving line breaks
    ?

Not sure whether for the second bullet, we could also make some blank line formatting optional, but I could not think of anything particularly meaningful. Maybe one can choose to either to not touch blank lines, or to reduce the amount of blank lines to one if there is at least two blank lines next to each other.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how consistently I adhere to this style. There's also the question of wrapping multiline formals - we should probably be consistent with other calls, and if all arguments don't fit on one line, each argument gets it's own line.

Comment thread R/expect-self-test.R Outdated
expect_known_failure <- function(path, expr) {
FailureReporter <- R6::R6Class("FailureReporter", inherit = CheckReporter,
FailureReporter <- R6::R6Class(
"FailureReporter", inherit = CheckReporter,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't "FailureReporter" stay on the first line? (Given that it's an unnamed argument that fits)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that is not yet implemented in styler. See https://github.com/krlmlr/styler/issues/246. For now, the line is broken after the first parenthesis with strict = TRUE if the whole call does not fit on one line.

Comment thread R/reporter-junit.R Outdated
timer = NULL,
doc = NULL,
errors = NULL,
results = NULL,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way that styler could detect if the = were aligned, and if so, leave as is

Comment thread R/stack.R
),

private = list(
stack = NULL, # A list that holds the items

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserving this alignment would also be nice

Comment thread tests/testthat/test-test-that.R Outdated
test_that('simple', { # line 2
expect_true(FALSE) # line 3
}) # line 4
context("testing testFile") # line 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you manually revert the changes to this file? The indenting of the comments is particularly important here

@krlmlr krlmlr mentioned this pull request Oct 25, 2017
1 of 4 tasks
@krlmlr

krlmlr commented Oct 25, 2017

Copy link
Copy Markdown
Member Author

Thanks. I've changed alignment and applied a few more tweaks. The code of this PR doesn't change when running styler:::style_pkg(scope = "tokens") except in situations for which I have created issues in the styler repo.

@krlmlr
krlmlr merged commit 1faa32f into r-lib:master Oct 25, 2017
@krlmlr
krlmlr deleted the f-styler branch October 25, 2017 07:14
@lorenzwalthert

Copy link
Copy Markdown

Reference: r-lib/styler#240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants