Skip to content

lint unused definitions

github-actions[bot] edited this page Jul 14, 2025 · 1 revision

This document was generated from 'src/documentation/print-linter-wiki.ts' on 2025-07-14, 16:41:24 UTC presenting an overview of flowR's linter (v2.2.16, using R v4.5.0). Please do not edit this file/wiki page directly.

Unused Definitions [overview]

smell quickfix readability

Checks for unused definitions.
This linting rule is implemented in src/linter/rules/unused-definition.ts.

Configuration

Linting rules can be configured by passing a configuration object to the linter query as shown in the example below. The unused-definitions rule accepts the following configuration options:

  • includeFunctionDefinitions
    Whether to include (potentially anonymous) function definitions in the search (e.g., should we report uncalled anonymous functions?).

Examples

x <- 42
y <- 3
print(x)

The linting query can be used to run this rule on the above example:

[ { "type": "linter",   "rules": [ { "name": "unused-definitions",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (1 ms)
   ╰ Unused Definitions (unused-definitions):
       ╰ maybe:
           ╰ Definition of y at 3.1 (1 quick fix(es) available)
       ╰ Metadata: {"totalConsidered":2,"searchTimeMs":0,"processTimeMs":1}
All queries together required ≈1 ms (1ms accuracy, total 4 ms)

Show Detailed Results as Json

The analysis required 4.5 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": {
      "unused-definitions": {
        "results": [
          {
            "certainty": "maybe",
            "variableName": "y",
            "range": [
              3,
              1,
              3,
              1
            ],
            "quickFix": [
              {
                "type": "remove",
                "range": [
                  3,
                  1,
                  3,
                  6
                ],
                "description": "Remove unused definition of `y`"
              }
            ]
          }
        ],
        ".meta": {
          "totalConsidered": 2,
          "searchTimeMs": 0,
          "processTimeMs": 1
        }
      }
    },
    ".meta": {
      "timing": 1
    }
  },
  ".meta": {
    "timing": 1
  }
}

Additional Examples

These examples are synthesized from the test cases in: test/functionality/linter/lint-unused-definition.test.ts

Clone this wiki locally