Skip to content

literal_coercion_linter() fails with interweaved comments #2824

Open
@MichaelChirico

Description

@MichaelChirico

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)
#   ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions