Skip to content
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

brace_linter exception opening exception should apply when a comment precedes the lone brace, too #1434

Closed
MichaelChirico opened this issue Jun 28, 2022 · 1 comment · Fixed by #1451
Assignees
Labels
false-positive code that shouldn't lint, but does

Comments

@MichaelChirico
Copy link
Collaborator

MichaelChirico commented Jun 28, 2022

(nearly the same as #1433, and maybe both fixed at the same time, but filed separately since the cause is just different enough)

Compare:

lintr::lint('
switch(stat,
  o = {
    FUN <- FO
    bw <- 0.01
  },
  s = {
    FUN <- FS
    bw <- 0.005
  },
  {
    FUN <- FE
    bw <- 2
  }
)',
lintr::brace_linter())

vs

lintr::lint('
switch(stat,
  o = {
    FUN <- FO
    bw <- 0.01
  },
  s = {
    FUN <- FS
    bw <- 0.005
  },
  # else
  {
    FUN <- FE
    bw <- 2
  }
)',
lintr::brace_linter())
# <text>:12:3: style: [brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
#   {
#   ^

The latter also shouldn't lint -- the # else comment is quite common/helpful, especially for long switch() statements.

@IndrajeetPatil
Copy link
Collaborator

With #1451

lintr::lint('
switch(stat,
  o = {
    FUN <- FO
    bw <- 0.01
  },
  s = {
    FUN <- FS
    bw <- 0.005
  },
  # else
  {
    FUN <- FE
    bw <- 2
  }
)',
lintr::brace_linter())

Created on 2022-07-16 by the reprex package (v2.0.1)

@MichaelChirico MichaelChirico added this to the 3.0.1 milestone Jul 25, 2022
@IndrajeetPatil IndrajeetPatil self-assigned this Jul 26, 2022
@MichaelChirico MichaelChirico modified the milestones: 3.0.3, 3.1.0 Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants