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

R6 method chaining #2813

Open
b-rhodes opened this issue Mar 4, 2025 · 6 comments
Open

R6 method chaining #2813

b-rhodes opened this issue Mar 4, 2025 · 6 comments
Labels
false-positive code that shouldn't lint, but does indentation 📏

Comments

@b-rhodes
Copy link

b-rhodes commented Mar 4, 2025

Is there a way to get the linter to recognize R6 method chaining and not complain?

https://adv-r.hadley.nz/r6.html#method-chaining

When I try to lay out code like this:

x$
  add(10)$
  add(10)$
  sum

It complains about incorrect numbers of indents.

@MichaelChirico
Copy link
Collaborator

Could you provide a reproducible example? I'm not seeing any lints from copy-pasting yours:

l = modify_defaults(all_linters(), implicit_integer_linter = NULL)
lint("
x$
  add(10)$
  add(10)$
  sum
", linters = l)
# ℹ No lints found.

@b-rhodes
Copy link
Author

b-rhodes commented Mar 6, 2025

Sorry! I didn't realise having or not method parameters would make a difference.

r$> l = modify_defaults(all_linters(), implicit_integer_linter = NULL)
    lint("
    x$
      add()$
      add()$
      sum
    ", linters = l)

# Output:
<text>:2:2: warning: [extraction_operator_linter] Use `[[` instead of `$` to extract an element.
x$
 ^
<text>:3:2: style: [indentation_linter] Indentation should be 0 spaces but is 2 spaces.
  add()$
~^
<text>:3:8: warning: [extraction_operator_linter] Use `[[` instead of `$` to extract an element.
  add()$
       ^
<text>:4:8: warning: [extraction_operator_linter] Use `[[` instead of `$` to extract an element.
  add()$
       ^

@MichaelChirico
Copy link
Collaborator

can you try updating to current dev version? extraction_operator_linter() is deprecated so I suspect you're on an old version

https://lintr.r-lib.org/reference/lintr-deprecated.html

@b-rhodes
Copy link
Author

b-rhodes commented Mar 6, 2025

Updating to the newest version on CRAN (3.2.0) changes the result to this:

l = modify_defaults(all_linters(), implicit_integer_linter = NULL)
lint("
x$
  add()$
  add()$
  sum
", linters = l)
# <text>:3:2: style: [indentation_linter] Indentation should be 0 spaces but is 2 spaces.
#   add()$
# ~^

@MichaelChirico
Copy link
Collaborator

Thanks, I confirm the issue. Not sure why my earlier example didn't spot it.

@MichaelChirico MichaelChirico added the false-positive code that shouldn't lint, but does label Mar 6, 2025
@b-rhodes
Copy link
Author

b-rhodes commented Mar 6, 2025

I think it only happens if there's no parameter in the functions used, if you pass a parameter then it goes back to no lints found.

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 indentation 📏
Projects
None yet
Development

No branches or pull requests

2 participants