-
Notifications
You must be signed in to change notification settings - Fork 7
lint absolute file paths
This document was generated from 'src/documentation/print-linter-wiki.ts' on 2025-06-25, 16:32:16 UTC presenting an overview of flowR's linter (v2.2.15, using R v4.5.0). Please do not edit this file/wiki page directly.
Absolute Paths [overview]
Checks whether file paths are absolute.
This linting rule is implemented in src/linter/rules/absolute-path.ts.
Linting rules can be configured by passing a configuration object to the linter query as shown in the example below.
The absolute-file-paths
rule accepts the following configuration options:
-
absolutePathRegex
Extend the built-in absolute path recognition with additional regexes -
additionalPathFunctions
The set of functions that should additionally be considered as using a file path. Entries in this array use theFunctionInfo
format from the dependencies query. -
include
Include paths that are built by functions, e.g.,file.path()
-
useAsWd
Which path should be considered to be the origin for relative paths. This is only relevant with quickfixes. In the future we may be sensitive to setwd etc.
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": "absolute-file-paths", "config": {} } ] } ]
Results (prettified and summarized):
Query: linter (1 ms)
╰ absolute-file-paths:
╰ definitely:
╰ Path C:/Users/me/Documents/My R Scripts/Reproducible.csv
at 2.1-63
╰ Metadata: {"totalConsidered":1,"totalUnknown":0,"searchTimeMs":1,"processTimeMs":0}
All queries together required ≈1 ms (1ms accuracy, total 6 ms)
Show Detailed Results as Json
The analysis required 6.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": {
"absolute-file-paths": {
"results": [
{
"certainty": "definitely",
"filePath": "C:/Users/me/Documents/My R Scripts/Reproducible.csv",
"range": [
2,
1,
2,
63
]
}
],
".meta": {
"totalConsidered": 1,
"totalUnknown": 0,
"searchTimeMs": 1,
"processTimeMs": 0
}
}
},
".meta": {
"timing": 1
}
},
".meta": {
"timing": 1
}
}
These examples are synthesized from the test cases in: [lint-absolute-path.test.ts](https://github.com/flowr-analysis/flowr/tree/main//lint-absolute-path.test.ts)
Given an absolute path and assuming a home directory of
/home/me
, we expect the linter to suggest a relative path
Given the following input:
"/home/me/foo.bar"
And using the following configuration:
{
useAsFilePath: '/home/me',
include: {
allStrings: true
}
}
We expect the linter to report the following:
certainty: LintingCertainty.Maybe,
filePath: '/home/me/foo.bar',
range: [1, 1, 1, 18],
quickFix: [{
type: 'replace',
'description': 'Replace with a relative path to `/home/me/foo.bar`',
range: [1, 1, 1, 18],
replacement: '"./foo.bar"'
}]
See here for the test-case implementation.
Replacing absolute paths with relative paths should work within function calls as well
Given the following input:
read.csv("/home/me/foo.bar")
And using the following configuration:
{
useAsFilePath: '/home/me',
include: {
allStrings: true
}
}
We expect the linter to report the following:
certainty: LintingCertainty.Maybe,
filePath: '/home/me/foo.bar',
range: [1, 10, 1, 27],
quickFix: [{
type: 'replace',
'description': 'Replace with a relative path to `/home/me/foo.bar`',
range: [1, 10, 1, 27],
replacement: '"./foo.bar"'
}]
See here for the test-case implementation.
If the script contains no function that reads a file path, 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.
If the script contains no file paths, but we include all strings, we expect no issues either
Given the following input:
cat("hello")
And using the following configuration:
{
include: {
allStrings: true
}
}
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
if we consider all strings for absolute paths, and the string contains something that might be a path, yet we deem it too short, we expect no issues
Given the following input:
"/x"
And using the following configuration:
{
include: {
allStrings: true
}
}
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
As we also incorporate the
file.path
function, we should be able to detect relative paths with a given separator
Given the following input:
file.path("a", "b", fsep="\\\\")
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
Given the following input:
file.path("a", "b", fsep="")
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
Given the following input:
file.path("a", "b", fsep=u)
We expect the linter to report the following:
* no lints
See here for the test-case implementation.
Given the following input:
file.path("C:", "b", fsep="\\\\")
We expect the linter to report the following:
certainty: LintingCertainty.Maybe,
filePath: 'C:\\\\b',
range: [1, 1, 1, 31]
See here for the test-case implementation.
If someone constructs an absolute path due to a (cursed) fsep, we should still be able to detect it
Given the following input:
file.path("C", "b", fsep=":/")
We expect the linter to report the following:
certainty: LintingCertainty.Maybe,
filePath: 'C:/b',
range: [1, 1, 1, 30]
See here for the test-case implementation.
Currently maintained by Florian Sihler at Ulm University
Email | GitHub | Penguins | Portfolio