Skip to content

lint dead code

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

This document was generated from 'src/documentation/print-linter-wiki.ts' on 2025-08-01, 13:05:58 UTC presenting an overview of flowR's linter (v2.3.0, using R v4.5.0). Please do not edit this file/wiki page directly.

Dead Code [overview]

smell reproducibility usability best-effort

Marks areas of code that are never reached during execution.
This linting rule is implemented in src/linter/rules/dead-code.ts.

Configuration

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

Examples

if(TRUE) 1 else 2

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

[ { "type": "linter",   "rules": [ { "name": "dead-code",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (1 ms)
   ╰ Dead Code (dead-code):
       ╰ certain:
           ╰ Code at 1.17
       ╰ Metadata: {"consideredNodes":7,"searchTimeMs":1,"processTimeMs":0}
All queries together required ≈1 ms (1ms accuracy, total 16 ms)

Show Detailed Results as Json

The analysis required 15.6 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": {
      "dead-code": {
        "results": [
          {
            "certainty": "certain",
            "range": [
              1,
              17,
              1,
              17
            ]
          }
        ],
        ".meta": {
          "consideredNodes": 7,
          "searchTimeMs": 1,
          "processTimeMs": 0
        }
      }
    },
    ".meta": {
      "timing": 1
    }
  },
  ".meta": {
    "timing": 1
  }
}

Additional Examples

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

Test Case: none

Given the following input:

x <- 1

We expect the linter to report the following:

* no lints

See here for the test-case implementation.

Test Case: always

Given the following input:

if(TRUE) 1 else 2

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 17, 1, 17]

See here for the test-case implementation.

Test Case: never

Given the following input:

if(FALSE) 1 else 2

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 11, 1, 11]

See here for the test-case implementation.

Test Case: no analysis

Given the following input:

if(FALSE) 1 else 2

And using the following configuration:

{ simplificationPasses: DefaultCfgSimplificationOrder }

We expect the linter to report the following:

* no lints

See here for the test-case implementation.

Test Case: stopifnot true

Given the following input:

if(TRUE) 1; stopifnot(TRUE); 2

We expect the linter to report the following:

* no lints

See here for the test-case implementation.

Test Case: stopifnot false

Given the following input:

if(TRUE) 1; stopifnot(FALSE); 2

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 13, 1, 28] },
{ certainty: LintingResultCertainty.Certain, range: [1, 31, 1, 31] },

See here for the test-case implementation.

Test Case: always

Given the following input:

x <- TRUE; if(x) 1 else 2

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 25, 1, 25]

See here for the test-case implementation.

Test Case: never

Given the following input:

x <- FALSE; if(x) 1 else 2

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 19, 1, 19]

See here for the test-case implementation.

Test Case: TRUE FALSE

Given the following input:

if(TRUE) 1 else if (FALSE) 2 else 3

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 17, 1, 35]

See here for the test-case implementation.

Test Case: FALSE FALSE

Given the following input:

if(FALSE) 1 else if (FALSE) 2 else 3

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 11, 1, 11] },
{ certainty: LintingResultCertainty.Certain, range: [1, 29, 1, 29]

See here for the test-case implementation.

Test Case: FALSE TRUE

Given the following input:

if(FALSE) 1 else if (TRUE) 2 else 3

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 11, 1, 11] },
{ certainty: LintingResultCertainty.Certain, range: [1, 35, 1, 35]

See here for the test-case implementation.

Test Case: after infinite repeat

Given the following input:

repeat{ foo }; 2

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 16, 1, 16]

See here for the test-case implementation.

Test Case: after infinite while

Given the following input:

while(TRUE){ foo }; 2

We expect the linter to report the following:

certainty: LintingResultCertainty.Certain, range: [1, 21, 1, 21]

See here for the test-case implementation.

Clone this wiki locally