Skip to content

Throw lint for grepl("^", x) in string_boundary_linter #1331

Open
@MichaelChirico

Description

@MichaelChirico

grepl("^", x) doesn't have a strict startsWith() equivalent, but it is quite poor usage -- !is.na(x) is clearly far superior.

x = c(NA, "", "abc")
cbind(
  grepl = grepl("^", x),
  starts_with = startsWith(x, ""),
  is_na = !is.na(x)
)
#      grepl starts_with is_na
# [1,] FALSE          NA FALSE
# [2,]  TRUE        TRUE  TRUE
# [3,]  TRUE        TRUE  TRUE

Same goes for grepl("$", x)

Originally posted by @AshesITR in #1311 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    false-negativecode that should lint, but doesn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions