-
Notifications
You must be signed in to change notification settings - Fork 73
Indention based on square brackets #207
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
Conversation
Replace style_curly and style_round with style_brace that can also style square braces
@dracodoc does that look better? At least for now, I think we can't easily support token-dependent indention unfortunately. |
@dracodoc you can also use the option |
Indentation is a complex issue. I think Of course you may want to prioritize your tasks for now, so I think it's OK for now. |
Right. Token-dependent indention is explicitly not encouraged in the style guide we aim to support, see section 2.5 in the tidyverse style guide, so that's why it was/is not of high priority. I note though that many people use it and I hope we can support it in the future. |
The style guide 2.5 seemed to be more about keep code within 80 characters for me, not how much indentation. The "bad" example is bad not because it indent to token, but it's over 80 characters. For statement within 80 characters, this usage should be perfectly fine. do_something("that", requires, many, arguments,
"some of which may be long") The tidyverse style guide didn't give details for indentation (ony do_something_very_complicated(
"that",
requires = many,
arguments = "some of which may be long"
)
do_something("that", requires, many, arguments,
"some of which may be long") |
Well, one might argue. But it says
To me, this is unambiguous (although the examples are not, I agree). So we just felt we are going to implement this in a strict way, which is also the easiest thing to do anyway. I think this line of argument is supported when looking at the next example: # Good
paste0(
"Requirement: ", requires, "\n",
"Result: ", result, "\n"
) This call is much shorter but the line is still broken after |
I read it again, yes you are right about the function call style. There is no mention about abjdsl[
abc,
2
] instead of this. abjdsl[abc,
2] Right? |
Right, thanks. I have not thought about this much actually since I hardly ever put an expression between a[first_long_expression_here,
second_long_expression_down_nere] Or a[
first_long_expression_here,
second_long_expression_down_nere
] I think the latter is preferred since consistent with the other brace expression rules we have. |
I also prefer the second variant. |
- Hotfix: utf8 should not be verbose (#245). - Allow styling of Rmd files(#233). - Remove duplicate @family (#244). - Fixing token insertion (#242). - Capitalize Addin titles (#241). - Explicit `NULL` creation to make styler compatible with R3.2.0 (#237). - Improve vignettes (#232). - Allow exclusion of files with `style_pkg()` and `style_dir()`. - Correct styling with long strings (#230). - Add tools for re-indenting tokens (#217). - Math token spacing (#221). - Remove outdated line and col information (#218). - Empty input for styling does not cause an error (#227, #228). - Tools to insert tokens + application on `if`-`else` clauses (#212). - Improve example in documentation (#222). - Fix spacing around in (#214). - Maintenance: renaming functions / files, extend helper, documentation, if_else etc. (#204). - Disallow line break after ( for function calls (#210). - Preserve space between `!` and bang (#209). - Simplify RStudio Addin (#208, #211). - Indention based on square brackets (#207). - Add vignette on introducing styler (#203). - Indent function declaration without curly braces correctly (#202). - Fix indention in if-else statement (#200). - Sorting key (#196). - Use safe sequences (#197). - Fix space between two commas (#195). - Keep single-line pipes on one line (#74). - Remove tidyr and dplyr dependency (#182, #183, @jimhester). - Fix parsing inconsistency (#188). - Substitute create filler (#190). - Introducing class vertical (#189). - Adapt line break rules (#172). - Fix `R CMD check` (#185). - Force argument evaluation for proper error handling (#179). - Add nonstrict version of set_space_before_comment (#174). - Add installation instructions to README (#175). - Addin to style highlighted region (#143). - Improve spelling (#168). - Add coverage badge - Change badge from WIP to active - Add the number of files to message (#166). - Improve documentation (#164). - Add informative messages while styling files (#165). - More examples in help file (#161). - No line breaks after pipe if comment is next token (#160). - Fixing spacing around `!` (non-bang-bang) (#157). - Finalize function documentation (#154). - Review vignette (#158). - Update bang-bang rule (#156).
Closes #206. Note that in the wake of this PR, I merged
indent_curly()
andindent_round()
toindent_braces()
to reduce code duplication, which in addition, indents based on[
also.Note that the indention is not token-dependent (=constant), so
becomes
And not