-
Notifications
You must be signed in to change notification settings - Fork 13
[Linting Rule] Unused Import
Generated from 'wiki-linter.ts' on 2026-08-19, 17:34:38 UTC (v2.14.1), please do not edit directly.
Unused Import [overview]
This rule is a best-effort rule.
Highlights packages that are attached but never used, so the code runs just the same without them. Requires a signature database, and packages that only do their work on load should be whitelisted in the configuration.
This linting rule is implemented in src/linter/rules/unused-import.ts.
Linting rules can be configured by passing a configuration object to the linter query as shown in the example below.
The unused-import rule accepts the following configuration options:
-
whitelist
packages that do their work on load and hence should never be reported, however unused they look
library(stats)
print("no stats function is used")The linting query can be used to run this rule on the above example:
[ { "type": "linter", "rules": [ { "name": "unused-import", "config": {} } ] } ]Results (prettified and summarized):
Query: linter (6 ms)
╰ Unused Import (unused-import):
╰ uncertain:
╰ Import of stats at 1.1-14 (1 quick fix(es) available)
╰ Metadata: totalConsidered: 1, totalUnresolved: 0, totalMultiPackage: 0, totalUnused: 1, searchTimeMs: 6, processTimeMs: 0
All queries together required ≈6 ms (1ms accuracy, total 7 ms)
Show Detailed Results as Json
The analysis required 7.0 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-import": {
"results": [
{
"certainty": "uncertain",
"involvedId": 3,
"loc": [
1,
1,
1,
14
],
"package": "stats",
"version": "4.5.3",
"quickFix": [
{
"type": "remove",
"description": "Remove the unused import of stats",
"loc": [
1,
1,
1,
14
]
}
]
}
],
".meta": {
"totalConsidered": 1,
"totalUnresolved": 0,
"totalMultiPackage": 0,
"totalUnused": 1,
"searchTimeMs": 6,
"processTimeMs": 0
}
}
},
".meta": {
"timing": 6
}
},
".meta": {
"timing": 6
}
}These examples are synthesized from the test cases in: test/functionality/linter/lint-unused-import.test.ts
Given the following input:
library(ggplot2)And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('ggplot2', [1, 1, 1, 16])]See here for the test-case implementation.
Given the following input:
pkg <- "ggplot2"
library(pkg, character.only = TRUE)And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('ggplot2', [2, 1, 2, 35])]See here for the test-case implementation.
Given the following input:
library(ggplot2)
ggplot()And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
require(ggplot2)
require(random1)
aes()And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('random1', [2, 1, 2, 16])]See here for the test-case implementation.
Given the following input:
library(p)
library(ggplot2)
library(random1)
ggplot()And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('p', [1, 1, 1, 10]), unused('random1', [3, 1, 3, 16])]See here for the test-case implementation.
Given the following input:
library(ggplot2)
ggplot2::ggplot()And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
library(ggplot2)
f <- function() aes()
f()And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
library(ggplot2)
if(x) { ggplot() }And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
library(ggplot2)
aes <- function() 1
aes()And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('ggplot2', [1, 1, 1, 16])]See here for the test-case implementation.
Given the following input:
library(ggplot2)
aes <- function() 1
f <- function() aes()
f()And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
library(p)
library(ggplot2)
library(random1)
p::f()
test1()And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('ggplot2', [2, 1, 2, 16])]See here for the test-case implementation.
Given the following input:
library(ggplot2)
if(x) { print(1) }And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('ggplot2', [1, 1, 1, 16])]See here for the test-case implementation.
Given the following input:
if(x) library(ggplot2)And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('ggplot2', [1, 7, 1, 22], false)]See here for the test-case implementation.
Given the following input:
f <- function() library(ggplot2)And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('ggplot2', [1, 17, 1, 32], false)]See here for the test-case implementation.
Given the following input:
library(ggplot2)
library(random1)
library(notInDb)
aes()And using the following configuration:
{ sigDb }We expect the linter to report the following:
[unused('random1', [2, 1, 2, 16])]See here for the test-case implementation.
Given the following input:
require(p)
require(ggplot2)
require(random1)
aes()And using the following configuration:
{ sigDb, whitelist: ['random1'] }We expect the linter to report the following:
[unused('p', [1, 1, 1, 10])]See here for the test-case implementation.
Given the following input:
library(ggplot2)And using the following configuration:
{ noSigDb: true }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
if(!requireNamespace("ggplot2", quietly = TRUE)) stop("need it")And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
loadNamespace("ggplot2")And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
p::f()And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
for(pkg in c("ggplot2", "p")) library(pkg, character.only = TRUE)And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Given the following input:
library(pkg, character.only = TRUE)And using the following configuration:
{ sigDb }We expect the linter to report the following:
* no lintsSee here for the test-case implementation.
Currently maintained by Florian Sihler and Oliver Gerstl at Ulm University
Email | GitHub | Penguins | Portfolio
- 🧑💻 Developer Onboarding
- 💻 Setup
- 👓 Overview
- 🪟 Interfacing with flowR
- 🌋 Core
- 🧹 Testing & Linting (Benchmark Page)
⁉️ FAQ- ℹ️ Extra Information