Skip to content

refactor(hm-dsl-engine): Replace positional (bool, bool) detection result with a named struct or DslLanguage set#114

Merged
markovejnovic merged 1 commit into
mainfrom
cq/hm-dsl-engine-replace-positional-bool-bool-detection-r-15
Jun 10, 2026
Merged

refactor(hm-dsl-engine): Replace positional (bool, bool) detection result with a named struct or DslLanguage set#114
markovejnovic merged 1 commit into
mainfrom
cq/hm-dsl-engine-replace-positional-bool-bool-detection-r-15

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

The smell

scan_extensions in crates/hm-dsl-engine/src/detect.rs returned a positional (bool, bool) meaning (has_py, has_ts). Three in-file consumers destructured it positionally:

  • detect_language matched (_, true) / (true, false)
  • detect_language_python_first matched (true, _) / (false, true)
  • has_pipeline_files bound Ok((py, ts))

The two booleans are the same type, so swapping them (or transposing a match arm) is a silent logic bug the compiler cannot catch — a Python repo could resolve to TypeScript and still type-check.

The change

scan_extensions now returns a tiny named struct:

struct DetectedLangs {
    has_py: bool,
    has_ts: bool,
}

All three call sites read .has_py / .has_ts by name. The match-on-tuple sites became if/else if/else chains over the named fields. Logic, ordering (TS-preferred vs Python-preferred), error messages, and the public API (detect_language, detect_language_python_first, has_pipeline_files) are all unchanged. The new struct is private to the module.

Type-safety pattern

This applies the "relational filter / result as a named type, not a loose bool pair" guidance from fd (sharkdp/fd): naming the fields removes the positional-swap hazard while keeping behavior and the public surface identical. A has_py/has_ts mix-up is now impossible to express because the fields are addressed by name rather than position.

Validation

Only cargo check -p hm-dsl-engine was run locally (passes clean). Full CI runs on this PR. Opened as draft for review.

@markovejnovic markovejnovic marked this pull request as ready for review June 10, 2026 19:17
@markovejnovic markovejnovic merged commit 358502e into main Jun 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant