Skip to main content

rules_source

Function rules_source 

Source
pub fn rules_source(
    rules_files: Option<&[RulesFileEntry]>,
    configured: Option<&OsStr>,
    repository_root: &Path,
) -> Result<RulesSource, RulesListError>
Expand description

What: Select the rules files: the configured rulesFile entries, else the variable’s list, else the default file, each relative to the repository root. Option<&[RulesFileEntry]> is “the configured entries or nothing”; Option<&OsStr> is “the variable’s value or nothing”; Result<..> fails only for a variable that is not a valid rules list. Why: The user decided on 2026-10-05 that configuration names the file first and the variable second. The spawned scanner ran with the repository root as its working directory, so a relative setting meant “relative to the root”. In-process there is no such directory change, so the root is joined explicitly; .join(..) keeps an absolute variable value as it is, and a configured name is relative by construction (config_rules_file.rs). A configured name or a set variable makes a missing file an error unless its entry is optional; only the default file may be missing. The variable is parsed with the scanner’s own rules-list parser, so both tools read one grammar.

In TS you’d write (pseudocode):

function rulesSource(rulesFiles: RulesFileEntry[] | undefined, variable: string | undefined, repositoryRoot: string): RulesSource; // throws RulesListError