Skip to content

Invalid scope argument needs error #177

Closed

Description

@krlmlr

styler::style_pkg(scope = "aasdf") starts to style my package...

Activity

  1. lorenzwalthert commented on Aug 31, 2017

    @lorenzwalthert
    Collaborator

    Right... I was wondering about assertive tests in general. I used checkmate but I can't really remember why not having choosed assertr, assertive or assertthat. Any preference on your side?

  2. krlmlr commented on Aug 31, 2017

    @krlmlr
    MemberAuthor

    A simple match.arg() would suffice here IMO.

  3. lorenzwalthert commented on Aug 31, 2017

    @lorenzwalthert
    Collaborator

    So just for scope or systematically for all arguments in all exported functions?

  4. krlmlr commented on Aug 31, 2017

    @krlmlr
    MemberAuthor

    We should apply stricter argument checking everywhere, but scope seems more urgent because it does the wrong thing if the value has a typo.

  5. lorenzwalthert commented on Sep 1, 2017

    @lorenzwalthert
    Collaborator

    There actually exists a check in tidyverse_style(scope = "...") when the ordered factor is created from scope.

    cat(styler::style_text("a", scope = "abc"), sep = "\n")
    #> Error in character_to_ordered(scope, c("none", "spaces", "indention", : all values in scope must be one of the following: none, spaces, indention, line_breaks, tokens

    Note that style_text() does use utf8::transform_lines_enc(), which itself implements some error handling.

    Styling one file also seems to work (at least outside the stylerRproj):

    > style_file("/Users/lorenz/Documents/short-term back-up/assertive.R", scope = "3")
    #> Styling 1 files:
    #> assertive.R. [DONE]
    #> No files changed.
    #> Warning message:
    #>" When processing assertive.R: all values in scope must be one of the following: none, spaces, 
    #> indention, line_breaks, tokens 

    But as you said, an error occurs with style_pkg() and also style_dir(). I don't understand why though... It also gives the "[...] all values in scope must be one of the following: none, spaces, indention, line_breaks, tokens [...]" warning, but it seems as execution is continued, which then produces these warnings: "In reduce_index(.x, .init, left = .left) :"

  6. lorenzwalthert commented on Sep 1, 2017

    @lorenzwalthert
    Collaborator

    Implementing the scope check at the point where we create the ordered factor, i.e. in tidyverse_style() seems to be the right place to me though.

  7. lorenzwalthert commented on Sep 2, 2017

    @lorenzwalthert
    Collaborator

    @krlmlr any ideas fro your side?

  8. krlmlr commented on Sep 2, 2017

    @krlmlr
    MemberAuthor

    Maybe construct the style guide object early on, before calling transform_files...()?

  9. lorenzwalthert commented on Sep 2, 2017

    @lorenzwalthert
    Collaborator

    Well it is already constructed before the body of the style_text() and friends is executed. However, we could use force(transformers) in the closure make_transformers() to solve the problem. Not sure whether there are more elegant ways but this approach seems to works.

  10. krlmlr commented on Sep 2, 2017

    @krlmlr
    MemberAuthor

    Yes, lazy evaluation bites sometimes. I'd suggest to force(style) in each interface function.

  11. lorenzwalthert commented on Sep 2, 2017

    @lorenzwalthert
    Collaborator

    I think in the end we need to force transformers, since style is only used to create transformers by default and you actually don't need to supply the argument. I thought about that too but isn't that a bit redundant? What's the advantage to call it in every style* function over calling it once?

  12. krlmlr commented on Sep 2, 2017

    @krlmlr
    MemberAuthor

    A force() call in make_transformer() seems sufficient too.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions