Skip to content

Ambiguous files in cache cause lint crash #212

@fangly

Description

@fangly

Hi Jim,

I obtained a "Marker line is unspecified or invalidNA" error when using lintr with caching. I managed to find out what is causing this problem. It is reproducible using these steps:

  1. Create two packages, "A" and "B", that have the identically-named files "tests/testthat.R". Let us assume that "A/tests/testthat.R" and "B/tests/testthat.R" are identical, except that "A/tests/testthat.R" has some trailing newlines.
  2. In package A, run expect_lint_free(cache=TRUE). This runs fine, yields a few lints because of the trailing newlines, and generates a "~/.R/lintr_cache/testthat.R" file.
  3. In package B, run expect_lint_free(cache=TRUE). This operation crashes with "Marker line is unspecified or invalidNA". I imagine this is because lintr sees the "~/.R/lintr_cache/testthat.R" file and wrongly assumes that it belongs to package B. Since there are some lints at line numbers after last line of file "B/tests/testthat.R", mayhem ensues...

My conclusion is that the cache should differentiate files belonging to different packages. This is important because many packages use the same names, e.g. "testthat.R" or "zzz.R".

But the problem is probably not limited to identically-named files between packages. When I create a file "A/R/more/testthat.R", issue a clear_cache() and re-run expect_lint_free(cache=TRUE), there is a single "~/.R/lintr_cache/testthat.R" file, meaning that the two "testthat.R" files in package A were likely cached in the same location, one of them overwriting the other.

A straightforward solution would be to create a subfolder for each package, and further subfolders mimicking the folder structure of the respective packages, i.e.

Source file Cache file
A/tests/testthat.R ~/.R/lintr_cache/A/tests/testthat.R
A/R/more/testthat.R ~/.R/lintr_cache/A/R/more/testthat.R
B/tests/testthat.R ~/.R/lintr_cache/B/tests/testthat.R

Cheers,
Florent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions