-
Notifications
You must be signed in to change notification settings - Fork 7
file path validity
This document was generated from 'src/documentation/print-linter-wiki.ts' on 2025-06-23, 11:52:06 UTC presenting an overview of flowR's linter (v2.2.15, using R v4.5.1). Please do not edit this file/wiki page directly.
File Path Validity [overview]
Checks whether file paths used in read and write operations are valid and point to existing files.
This linting rule is implemented in src/linter/rules/file-path-validity.ts.
Linting rules can be configured by passing a configuration object to the linter query as shown in the example below.
The file-path-validity
rule accepts the following configuration options:
-
additionalReadFunctions
The set of functions that should additionally be considered as reading a file path. Entries in this array use theFunctionInfo
format from the dependencies query. -
additionalWriteFunctions
The set of functions that should additionally be considered as writing to a file path. Entries in this array use theFunctionInfo
format from the dependencies query. -
includeUnknown
Whether unknown file paths should be included as linting results.
my_data <- read.csv("C:/Users/me/Documents/My R Scripts/Reproducible.csv")
The linting query can be used to run this rule on the above example:
[ { "type": "linter", "rules": [ { "name": "file-path-validity", "config": {} } ] } ]
Results (prettified and summarized):
Query: linter (1 ms)
╰ file-path-validity:
╰ definitely:
╰ Path C:/Users/me/Documents/My R Scripts/Reproducible.csv
at 2.12-74
╰ Metadata: {"totalReads":1,"totalUnknown":0,"totalWritesBeforeAlways":0,"totalValid":0,"searchTimeMs":1,"processTimeMs":0}
All queries together required ≈1 ms (1ms accuracy, total 2 ms)
Show Detailed Results as Json
The analysis required 2.2 ms (including parsing and normalization and the query) within the generation environment.
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.
{
"linter": {
"results": {
"file-path-validity": {
"results": [
{
"range": [
2,
12,
2,
74
],
"filePath": "C:/Users/me/Documents/My R Scripts/Reproducible.csv",
"certainty": "definitely"
}
],
".meta": {
"totalReads": 1,
"totalUnknown": 0,
"totalWritesBeforeAlways": 0,
"totalValid": 0,
"searchTimeMs": 1,
"processTimeMs": 0
}
}
},
".meta": {
"timing": 1
}
},
".meta": {
"timing": 1
}
}
These examples are synthesized from the test cases in: [lint-file-path-validity.test.ts](https://github.com/flowr-analysis/flowr/tree/main//lint-file-path-validity.test.ts)
As the script contains no file paths, we expect no issues
Given the following input:
cat("hello")
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
Assuming, that
file.csv
exists, we expect the linter to not report any issues, but to report an invalid file path forfile-missing.csv
Given the following input:
cat("hello")
read.csv("file.csv")
read.csv("file-missing.csv")
We expect the linter to report the following:
certainty: LintingCertainty.Definitely, filePath: 'file-missing.csv', range: [3,1,3,28]
See here for the test-case implementation.
If we configure the linter to ignore capitalization, we expect the linter to not report an issue for
file.csv
, but still report an issue forfile-missing.csv
Given the following input:
cat("hello")
read.csv("FiLe.csv")
read.csv("FiLe-missing.csv")
We expect the linter to report the following:
certainty: LintingCertainty.Definitely, filePath: 'FiLe-missing.csv', range: [3,1,3,28]
See here for the test-case implementation.
Linting should also work for relative paths, as long as the file exists, we assume
path/to/deep-file.csv
to exist
Given the following input:
cat("hello")
read.csv("path/to/deep-file.csv")
read.csv("path/to/deep-file-missing.csv")
We expect the linter to report the following:
certainty: LintingCertainty.Definitely, filePath: 'path/to/deep-file-missing.csv', range: [3,1,3,41]
See here for the test-case implementation.
If we use a relative path that is not valid (we expect there to be no
invalid/
folder), we expect the linter to report an issue too
Given the following input:
cat("hello")
read.csv("invalid/path/to/deep-file.csv")
read.csv("invalid/path/to/deep-file-missing.csv")
We expect the linter to report the following:
certainty: LintingCertainty.Definitely, filePath: 'invalid/path/to/deep-file-missing.csv', range: [3,1,3,49]
See here for the test-case implementation.
If we use a relative path that is not valid, but we create a file of such a name within the script, we expect the linter to not report an issue
Given the following input:
write.csv("hello", "file-missing.csv")
read.csv("file-missing.csv")
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
If we use a relative path that is not valid, but we create a file of such a name within the script, and ignore case, we expect the linter to not report an issue
Given the following input:
write.csv("hello", "FiLe-missing.csv")
read.csv("file-missing.csv")
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
If the code that is supposed to write the file is never executed, we expect the linter to report an issue for the missing file
Given the following input:
if(FALSE) { write.csv("hello", "file-missing.csv") }
read.csv("file-missing.csv")
We expect the linter to report the following:
certainty: LintingCertainty.Definitely, filePath: 'file-missing.csv', range: [2,1,2,28]
See here for the test-case implementation.
We should be able to recognize file paths that are bound to variables
Given the following input:
path <- "file.csv"; read.csv(path)
And using the following configuration:
{ includeUnknown: true }
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
If we configure the linter to do nothing for unknown file paths, we expect it to not report an issue for the unknown file path
Given the following input:
path <- "file" + runif(1) + ".csv"; read.csv(path)
And using the following configuration:
{ includeUnknown: false }
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
If we configure the linter to report unknown file paths, we expect it to report an issue for the unknown file path
Given the following input:
path <- "file" + runif(1) + ".csv"; read.csv(path)
And using the following configuration:
{ includeUnknown: true }
We expect the linter to report the following:
certainty: LintingCertainty.Maybe, filePath: Unknown, range: [1,37,1,50]
See here for the test-case implementation.
Currently maintained by Florian Sihler at Ulm University
Email | GitHub | Penguins | Portfolio