src/rules/suspicious/spare.bend checks
raw source on the hub · import bolt@1.63.0.0/src/rules/suspicious/spare.bend as Spare
rule spare (project): an import the file never names, of a file that is
imported for its names alone. Reported: in a file that is neither a law
file nor a proof file, an import of a file by a relative path under an
alias (import ./ops.bend as O) when no dotted name of the file outside
its import lines starts with the alias and a dot (O.add), the file does
name the alias of another import of its own, the imported file was read
in the run, and neither it nor any file it reaches by relative imports
loads. One finding, on the import's line.
A file loads when it states a law, holds a def that is a proof, or holds
a foreign def (rules/links.bend). bend checks a law and a proof with
whatever imports their file, and links a foreign def only when the entry
reaches its file, so an import of such a file is made for what it does,
whatever its alias: a module that imports its own proofs, a check that
imports the entry to keep the native effects registered. Deleting one of
those would silence the finding and drop a check, so it is never
reported.
A file that names none of its imports is left alone too: it loads them
(an entry that lists what a package publishes, a harness, a file that
exists to type-check a library). So is an import with no alias
(import Base), one of a hub package (its path is not relative: nothing
is known of it), and one whose target the run did not read.
The fix is to delete the import line: the file says it depends on a
module it does not use, bend checks that module for nothing, and a
published package carries it.
It needs every file, so it runs in bolt over a tree and never in the
editor; over files named on the line it sees only those, and reports an
import only when its target is among them.
6 imports
import Base import ../../finding.bend as F import ../../lazy/lazy.bend as Lazy import ../digest.bend as Digest import ../imports.bend as Imports import ../links.bend as Links
Definitions
def loaders.put source · line 40 · raw
@loads:Bool -> @norm:String -> @more:List<&2, String> -> List<&2, String>
a path before the others when its file loads
def loaders source · line 48 · raw
@ds:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> List<&2, String>
the normalized paths of the files that load, in order
def any source · line 58 · raw
@ps:List<&2, String> -> @+ls:List<&2, String> -> Bool
is any of the paths among the loaders?
def closure source · line 67 · raw
@+all:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> @target:String -> List<&2, String>
what the file at a path reaches by relative imports among the files read,
itself first: the walk coverage takes (laws/ImportReachIsClosed.bend)
def reaches source · line 72 · raw
@all:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> @ls:List<&2, String> -> @target:String -> Bool
does importing the file at a path load something: is the file, or one it reaches by relative imports among the files read, a loader?
def read source · line 76 · raw
@all:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> @target:String -> Bool
was the file at a path read in the run?
def idle source · line 81 · raw
@+all:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> @ls:List<&2, String> -> @+target:String -> Bool
is a spare import reported: its target was read, and importing it loads nothing?
def say source · line 85 · raw
@alias:String -> String
what a finding says
def cite source · line 89 · raw
@alias:String -> @line:U32 -> @path:String -> 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding
the finding on the import's line, over the word import
def found source · line 93 · raw
@hit:Bool -> @alias:String -> @line:U32 -> @path:String -> @more:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding> -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>
a finding on the import when it is reported, before the rest
def file source · line 101 · raw
@ss:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/links.Spare> -> @+path:String -> @+all:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> @+ls:List<&2, String> -> @more:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding> -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>
a file's spare imports that are reported, in order, before the rest
def check.go source · line 116 · raw
@ds:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> @+all:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> @+ls:List<&2, String> -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>
every reported import of every file that is neither a law file nor a proof file, in order: all are the files of the run, ls those that load
def check source · line 127 · raw
@+ds:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/rules/digest.Digest> -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>
the rule