Skip to content

Linter for space needed after right parenthesis of function symbol formals #809

Closed

Description

@renkun-ken

Just notice that there seems to be no linter that complains about the following code

function(x)x + 1

where a space is needed between function(x) and x + 1.

Activity

  1. kpagacz commented on Jul 7, 2021

    @kpagacz
    Contributor

    I don't know if there is any contribution guideline for lintr, therefore I am just going to ask - is it alright if I start working on this?

    Do you think it should be a new linter or be a part of an already existing linter?

  2. renkun-ken commented on Jul 7, 2021

    @renkun-ken
    CollaboratorAuthor

    The following linters might be related to this issue, but they are quite unique on their own.

    $ <text>:List of 8
      ..$ filename     : chr "<text>"
      ..$ line_number  : int 1
      ..$ column_number: int 15
      ..$ type         : chr "style"
      ..$ message      : chr "Remove spaces before the left parenthesis in a function call."
      ..$ line         : Named chr "f <- function (x){x + 1}"
      .. ..- attr(*, "names")= chr "1"
      ..$ ranges       : NULL
      ..$ linter       : chr "function_left_parentheses_linter"
      ..- attr(*, "class")= chr "lint"
     $ <text>:List of 8
      ..$ filename     : chr "<text>"
      ..$ line_number  : int 1
      ..$ column_number: int 18
      ..$ type         : chr "style"
      ..$ message      : chr "Opening curly braces should never go on their own line and should always be followed by a new line."
      ..$ line         : Named chr "f <- function (x){x + 1}"
      .. ..- attr(*, "names")= chr "1"
      ..$ ranges       : NULL
      ..$ linter       : chr "open_curly_linter"
      ..- attr(*, "class")= chr "lint"
     $ <text>:List of 8
      ..$ filename     : chr "<text>"
      ..$ line_number  : int 1
      ..$ column_number: int 18
      ..$ type         : chr "style"
      ..$ message      : chr "There should be a space between right parenthesis and an opening curly brace."
      ..$ line         : chr "f <- function (x){x + 1}"
      ..$ ranges       :List of 1
      .. ..$ : num [1:2] 18 18
      ..$ linter       : chr "paren_brace_linter"
      ..- attr(*, "class")= chr "lint"
     $ <text>:List of 8
      ..$ filename     : chr "<text>"
      ..$ line_number  : int 1
      ..$ column_number: int 24
      ..$ type         : chr "style"
      ..$ message      : chr "Closing curly-braces should always be on their own line, unless they are followed by an else."
      ..$ line         : Named chr "f <- function (x){x + 1}"
      .. ..- attr(*, "names")= chr "1"
      ..$ ranges       : NULL
      ..$ linter       : chr "closed_curly_linter"
      ..- attr(*, "class")= chr "lint"
    

    Looks like it enhances the paren_brace_linter so that it not only requires that there be a space between the right parenthesis and an opening curly brace, but also requires a space between the right parenthesis and the function body if they are in the same line. It is more like a paren_space_linter then.

    If we are not to enhancing existing linters in this way, then we will need a new linter to specifically check this.

  3. kpagacz commented on Jul 7, 2021

    @kpagacz
    Contributor

    I have created a PR for this issue. Let me know what you think.
    #830

  4. added
    feature
    on Jul 9, 2021
  5. added a commit that references this issue on Jul 14, 2021
    e7dcac7
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

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions