Skip to content

Tab conversion #213

Closed
Closed

Description

@lorenzwalthert

Tabs used to be converted to spaces, e.g. 10a3c68.

make_transformer_nested <- function(transformers) {
  function(text) {
    text <- gsub(" +$", "", text)
    text <- gsub("\t", "        ", text)

    pd_nested <- compute_parse_data_nested(text)
    transformed_pd_nested <- visit(pd_nested, transformers)
    # TODO verify_roundtrip
    new_text <- serialize_parse_data_nested(transformed_pd_nested)
    new_text
  }
}
  • The tidyverse style guide does encourage the use of spaces, not tabs.
  • We'd principally prefer an approach that operates on the parse table and not on the text input, so third-party style guides could leave tabs untouched.
  • There seems another bug in the parser that might be relevant for this.

Activity

  1. lorenzwalthert commented on Sep 21, 2017

    @lorenzwalthert
    CollaboratorAuthor

    Reference: #100.

  2. krlmlr commented on Sep 22, 2017

    @krlmlr
    Member

    This already works for me:

    styler::style_text("if (TRUE) {\n\tNULL\n}")
    #> if (TRUE) {
    #>   NULL
    #> }

    The code just made sure that the roundtrip check isn't fooled by the automatic conversion from tabs to spaces, because we can't distinguish them from the getParseData() output.

  3. changed the title [-]tab conversion[/-] [+]Tab conversion[/+] on Sep 23, 2017
  4. lorenzwalthert commented on Oct 29, 2017

    @lorenzwalthert
    CollaboratorAuthor

    Ok, and due to the way we serialise, the output will never contain tabs anymore, right? The parser bug remains:

    getParseData() counts 1 tab as a variable number of spaces instead of one

    That might get unexpected results with strict = FALSE, e.g. where spaces around operators are to be preserved and tabs are not interpreted as two spaces. Should we neglect that?

  5. krlmlr commented on Oct 31, 2017

    @krlmlr
    Member

    To support this we'd need to be able to tweak the number of spaces per tab. We might look into this if this turns out to be an important use case, but currently this seems rather low priority.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions