Skip to content

unique_by

No two files matching select may share the value of key (a path template; tokens {path}/{dir}/{basename}/{stem}/{ext}/{parent_name}). Catches basename collisions across subdirectories. With case_insensitive: true the key is folded to lowercase before grouping, so README.md and readme.md collide — the case-insensitive-filesystem hazard (Windows / macOS).

OptionTypeRequiredDefaultDescription
case_insensitivebooleanfalseFold the key to lowercase before grouping, so keys that collide only under case-folding count as duplicates - the case-insensitive-filesystem hazard (Windows / macOS).
keystring{basename}Path-template producing a key per matched file. Default: {basename}.
selectstringyesGlob selecting the files to deduplicate.

Plus the common level, id, and when fields. This rule analyses the whole repository, so it takes no paths. This table is generated from the JSON Schema; option types and defaults are authoritative.

The rule fires on this repository:

a/
a/util.rs
b/
b/util.rs
c/
c/other.rs
a/util.rs
pub fn a() {}
b/util.rs
pub fn b() {}
c/other.rs
pub fn c() {}

With this .alint.yml:

version: 1
rules:
- id: unique-rs-stems
kind: unique_by
select: "**/*.rs"
key: "{stem}"
level: warning

alint check reports:

Terminal window
--- a/util.rs ------------------------------------------------------------------
! warning unique-rs-stems
duplicate key "util" shared by 2 file(s): a/util.rs, b/util.rs
Summary (1 violation):
! 1 warning
0 passing * 1 failing

This repository is compliant:

src/
src/alpha.rs
src/beta.rs
src/gamma.rs

With this .alint.yml:

version: 1
rules:
- id: unique-rs-stems
kind: unique_by
select: "**/*.rs"
key: "{stem}"
level: warning

alint check reports:

Terminal window
v All 1 rule(s) passed.