---
# Repository-owned Semgrep rules.
#
# Keep this file small and project-specific. Broad default/community rules have
# been noisy for this Rust library and duplicate CodeQL, cargo-audit, Clippy,
# Ruff, and ShellCheck coverage.
#
# The rules below are intentionally disabled with an impossible include path
# while legacy call sites are cleaned up in
# https://github.com/acgetchell/delaunay/issues/338. To enable one, replace its
# "__semgrep_disabled__/**" include with the intended path such as "src/**/*.rs"
# and remove the "enabled: false" metadata note.

rules:
  - id: delaunay.rust.no-stdio-diagnostics-in-src
    languages:
      - rust
    severity: WARNING
    message: "Use tracing macros for production diagnostics instead of stdout/stderr macros."
    metadata:
      enabled: false
      category: maintainability
      tracking_issue: "https://github.com/acgetchell/delaunay/issues/338"
      rationale: "Runtime diagnostics should be filterable through tracing and RUST_LOG."
    paths:
      include:
        - "/__semgrep_disabled__/**/*.rs"
      exclude:
        - "/tests/**"
        - "/examples/**"
        - "/benches/**"
    patterns:
      - pattern-either:
          - pattern: println!(...)
          - pattern: eprintln!(...)
      - pattern-not-inside: |
          #[cfg(test)]
          mod $MOD {
              ...
          }
      - pattern-not-inside: |
          #[cfg(any(test, ...))]
          mod $MOD {
              ...
          }
      - pattern-not-inside: |
          #[cfg(test)]
          fn $FUNC(...) {
              ...
          }
      - pattern-not-inside: |
          #[cfg(any(test, ...))]
          fn $FUNC(...) {
              ...
          }
      - pattern-not-inside: |
          #[cfg(test)]
          impl $TYPE {
              ...
          }
      - pattern-not-inside: |
          #[cfg(any(test, ...))]
          impl $TYPE {
              ...
          }

  - id: delaunay.rust.no-nonfinite-unwrap-defaults
    languages:
      - rust
    severity: WARNING
    message: "Do not hide failed floating-point conversion with NaN or infinity defaults."
    metadata:
      enabled: false
      category: correctness
      tracking_issue: "https://github.com/acgetchell/delaunay/issues/338"
      rationale: >-
        Geometric predicates and diagnostics should not synthesize non-finite
        sentinels after conversion failure.
    paths:
      include:
        - "/__semgrep_disabled__/**/*.rs"
    pattern-either:
      - pattern: $VALUE.unwrap_or(f64::NAN)
      - pattern: $VALUE.unwrap_or(f64::INFINITY)
      - pattern: $VALUE.unwrap_or(f64::NEG_INFINITY)
      - pattern: $VALUE.unwrap_or(std::f64::NAN)
      - pattern: $VALUE.unwrap_or(std::f64::INFINITY)
      - pattern: $VALUE.unwrap_or(std::f64::NEG_INFINITY)
      - pattern: $VALUE.unwrap_or_else(|| f64::NAN)
      - pattern: $VALUE.unwrap_or_else(|| f64::INFINITY)
      - pattern: $VALUE.unwrap_or_else(|| f64::NEG_INFINITY)
