Skip to content

Handling control statements of any depth in return_linter #2356

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

Closed
MEO265 opened this issue Nov 27, 2023 · 1 comment · Fixed by #2362
Closed

Handling control statements of any depth in return_linter #2356

MEO265 opened this issue Nov 27, 2023 · 1 comment · Fixed by #2362
Labels
feature a feature request or enhancement

Comments

@MEO265
Copy link
Contributor

MEO265 commented Nov 27, 2023

I think this double lint is not correct either you see the if after an else as a new expression, then only the second one should be marked, or you understand an if with a lot of else as one expression (that's how I would see it) and then only the first one would have to be marked.

lint(
  trim_some("
  function(x, y) {
    if(x) {
      1
    } else if(y) {
      2
    }
  }
  "),
  return_linter(return_style = "explicit", allow_implicit_else = FALSE)
)

<text>:2:9: style: [return_linter] All functions must have an explicit return().
  if(x) {
        ^
<text>:4:10: style: [return_linter] All functions must have an explicit return().
  } else if(y) {
         ^~~~~~~

I'm not entirely sure if it's a bug of this PR or the first one. If it's one of the first, feel free to convert this message into an issue, because then I'll probably have a (simple) solution to fix it and properly handle control statements of any depth.

Originally posted by @MEO265 in #2321 (comment)

@MEO265
Copy link
Contributor Author

MEO265 commented Nov 27, 2023

This bug should be fixed at the same time

lint(
  trim_some("
  function(x, y) {
    if(x) {
      1
    } else if(y) {
      2
    }
  }
  "),
  return_linter(return_style = "implicit", allow_implicit_else = FALSE)
)

# No lint, but should lint

#2321 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants