# alint://bundled/monorepo@v1
#
# Hygiene checks for repositories that host multiple packages
# under common subdirectories (`packages/*`, `crates/*`,
# `apps/*`, `services/*`). Language-agnostic about the packages
# themselves — pair with `rust@v1` / `node@v1` / etc. when you
# know the ecosystem.
#
# Conventions:
# - `packages/*` is the npm / JS convention — each entry should
#   have a `package.json` and a `README.md`.
# - `crates/*` is the Rust workspace convention — each entry
#   should have a `Cargo.toml` and a `README.md`.
# - `apps/*` and `services/*` are polyglot buckets — README
#   required, manifest optional (no universal convention).

version: 1

rules:
  # --- README per package directory --------------------------------
  # `{a,b,c}` brace alternation in globs matches any of the listed
  # directories, so this fires for each entry under any of the
  # four common monorepo layout roots.
  - id: monorepo-packages-have-readme
    kind: for_each_dir
    select: "{packages,crates,apps,services}/*"
    level: warning
    message: "Every monorepo package directory should have a README.md."
    require:
      - kind: file_exists
        paths: "{path}/README.md"

  # --- Ecosystem-specific manifests --------------------------------
  - id: monorepo-packages-have-package-json
    kind: for_each_dir
    select: "packages/*"
    level: error
    message: "Every `packages/*` entry should have a package.json."
    require:
      - kind: file_exists
        paths: "{path}/package.json"

  - id: monorepo-crates-have-cargo-toml
    kind: for_each_dir
    select: "crates/*"
    level: error
    message: "Every `crates/*` entry should have a Cargo.toml."
    require:
      - kind: file_exists
        paths: "{path}/Cargo.toml"

  # --- Uniqueness across the workspace -----------------------------
  - id: monorepo-unique-package-names
    # A package directory name should be globally unique so tooling
    # and contributors can refer to a package unambiguously.
    kind: unique_by
    select: "{packages,crates,apps,services}/*"
    key: "{basename}"
    level: warning
    message: "Package-directory basenames should be unique across the monorepo."
