Skip to content

absolute file paths

github-actions[bot] edited this page Jun 25, 2025 · 1 revision

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.

Absolute Paths [overview]

smell quickfix reproducibility robustness

Checks whether file paths are absolute.
This linting rule is implemented in src/linter/rules/absolute-path.ts.

Configuration

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 the FunctionInfo 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.

Examples

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 (0 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":0,"processTimeMs":0}
All queries together required ≈0 ms (1ms accuracy, total 2 ms)

Show Detailed Results as Json

The analysis required 1.8 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": 0,
          "processTimeMs": 0
        }
      }
    },
    ".meta": {
      "timing": 0
    }
  },
  ".meta": {
    "timing": 0
  }
}

Additional Examples

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)

Test Case: is relative to home

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.

Test Case: is relative to home

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.

Test Case: none

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.

Test Case: none with all strings

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.

Test Case: too short

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.

Test Case: change fsep

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.

Test Case: skrewed fsep

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.

Test Case: skrewed fsep

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.

Test Case: change fsep

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.

Test Case: skrewed fsep

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.

Clone this wiki locally