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

False positive in pipe_continuation_linter when code has nested pipes #2631

Open
javieriserte opened this issue Jul 15, 2024 · 4 comments
Open
Labels
false-positive code that shouldn't lint, but does help wanted ❤️ we'd love your help!

Comments

@javieriserte
Copy link

When a piece of code has two pipes, one nested inside another like in example code below:

c("1", "2", "3", "4") |>
  sapply(function(x) x |> runif() |> mean()) |>
  as.character()

the linter produces a false positive:

<text>:2:46: style: [pipe_continuation_linter] `|>` should always have a space before it and a new line after it, unless the full pipeline fits on one line.
  sapply(function(x) x |> runif() |> mean()) |>
                                         ^~

I think that the linter may consider the expression like a single pipe, instead of two nested pipes.

I'm using lintr 3.1.2.

@AshesITR
Copy link
Collaborator

Does the following work for you?

c("1", "2", "3", "4") |>
  sapply(
    function(x) x |> runif() |> mean()
  ) |>
  as.character()

I think linting he inner pipeline could be made optional. Personally I prefer keeping the lint because regardless of syntax, discerning the multiple pipe characters in one line is hard on my eyes.

@MichaelChirico
Copy link
Collaborator

discerning the multiple pipe characters in one line is hard on my eyes.

I agree, but for this we already have https://github.com/r-lib/lintr/blob/73e55d31f6ead2908fcd9a49d6ccf46524b1cccc/R/nested_pipe_linter.R

I'll mark this as "help wanted" as I'm not sure it's worth the effort, but if this is driving you nuts feel free to have a go at it.

@MichaelChirico MichaelChirico added help wanted ❤️ we'd love your help! false-positive code that shouldn't lint, but does labels Jul 16, 2024
@javieriserte
Copy link
Author

Thank you!,

I'll look into it.

@AshesITR
Copy link
Collaborator

Keeping this open to track the false positive

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 help wanted ❤️ we'd love your help!
Projects
None yet
Development

No branches or pull requests

3 participants