struct
Noir::ExcludePath
- Noir::ExcludePath
- Struct
- Value
- Object
Overview
Compiled --exclude-path patterns, and the single implementation of
what they mean.
The option used to be spelled out inline in the detector's walk
(src/detector/detector.cr), which is the only place that sees every
file — so it protected exactly the analyzers that take their file set
from CodeLocator. The six adapters that enumerate the filesystem
themselves (Spring/Quarkus static resources, Dropwizard config, the Go
static-dir resolver, the Android/iOS resource walks) never went through
it and happily reported files the user had excluded. Analyzer#excluded_path?
applies this to them, which is only correct as long as both sides agree
on what a pattern means — hence one type, used by both.
Pattern semantics (unchanged from the detector's original inline form):
- a pattern containing
/matches the file's path relative to the scan base, as a glob (tests/*,**/vendor/**), as an exact directory (src/legacy), or as a directory prefix (everything undersrc/legacy/); - a pattern without
/matches the basename as a glob (*.test.js); - on macOS/Windows the comparison folds case, because their default filesystems do. Folding on Linux would wrongly drop case-distinct files that legitimately coexist.
Defined in:
utils/exclude_path.crConstant Summary
-
CASE_INSENSITIVE =
{% if (flag?(:darwin)) || (flag?(:windows)) %} true {% else %} false {% end %} -
Mirrors the detector's original
exclude_case_insensitive.
Constructors
-
.new(raw : String)
rawis the comma-separated option value.
Instance Method Summary
-
#active? : Bool
True when the user supplied at least one usable pattern.
-
#excluded?(relative_path : String) : Bool
relative_pathis the file's location relative to the scan base that owns it.
Constructor Detail
raw is the comma-separated option value. Windows-style backslashes
are normalized before the / classification, so src\legacy is
treated as a path pattern (and matches) instead of an unmatchable
basename.
Instance Method Detail
True when the user supplied at least one usable pattern. Callers
should check this before computing a relative path per file — with no
--exclude-path there is nothing to compute it for.
relative_path is the file's location relative to the scan base that
owns it. A leading / is accepted (that is the shape
Analyzer#base_relative_path returns) and ignored, so both callers
can hand over their own spelling.
Raises File::BadPatternError on a malformed glob, which the
detector converts into Noir::InvalidExcludePathError — a bad
pattern must stop the scan rather than silently exclude nothing.