Skip to content

literal_coercion_linter() fails with interweaved comments #2824

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

Open
MichaelChirico opened this issue Mar 10, 2025 · 0 comments
Open

literal_coercion_linter() fails with interweaved comments #2824

MichaelChirico opened this issue Mar 10, 2025 · 0 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@MichaelChirico
Copy link
Collaborator

As fixed in #2822, here are some tests generating errors on main:

linter <- literal_coercion_linter()
expect_no_lint(
  trim_some("
    as.numeric(foo('a' # comment
    = 1))
  "),
  linter
)
# Error in `lint(file, ...)`: Linter `linter()` failed in '/tmp/Rtmpzq66vo/file2ed8721ec1677':
# Caused by error in `str2expression()`:
# ! <text>:2:0: unexpected end of input
# 1: as.numeric(foo('a'# comment=1))
#    ^
expect_no_warning(
  expect_lint(
    trim_some("
      as.double(
        NA # comment
      )
    "),
    "Use NA_real_",
    linter
  )
)
# Error in `lint(file, ...)`: Linter `linter()` failed in '/tmp/Rtmpzq66vo/file2ed87513c779d':
# Caused by error in `str2expression()`:
# ! <text>:2:0: unexpected end of input
# 1: as.double(NA# comment)
#    ^
expect_lint(
  trim_some("{
    as.integer( # comment
    1           # comment
    )           # comment
    lgl(        # comment
    1L          # comment
    )           # comment
  }"),
  list(
    list(rex::rex("Use 1L instead of as.integer(1)"), line_number = 2L),
    list(rex::rex("Use TRUE instead of lgl(1L)"), line_number = 5L)
  ),
  linter
)
# Error in `lint(file, ...)`: Linter `linter()` failed in '/tmp/Rtmpzq66vo/file2ed871b70ce2b':
# Caused by error in `str2expression()`:
# ! <text>:3:0: unexpected end of input
# 1: as.integer(# comment1# comment)
# 2: rlang::lgl(# comment1L# comment)
#   ^
@MichaelChirico MichaelChirico added the bug an unexpected problem or unintended behavior label Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant