Skip to content

topmark.filetypes.filename_rules

topmark / filetypes / filename_rules

Normalize and validate file type filename rules.

FileType.filenames entries are declarative registry matching rules, not filesystem paths. Rules are stored as canonical POSIX-style strings so registry output and resolver behavior stay stable across platforms.

A rule may be either an exact basename such as Makefile or a relative tail-subpath such as .vscode/settings.json. Backslashes are accepted as compatibility input and normalized to /; absolute paths, drive paths, UNC paths, empty segments, and . / .. segments are rejected.

normalize_filename_rules

normalize_filename_rules(rules, *, file_type)

Return canonical POSIX-style filename rules.

Parameters:

Name Type Description Default
rules Iterable[str]

Exact basename and relative tail-subpath filename rules to normalize.

required
file_type str

Qualified file type identifier used in validation errors.

required

Returns:

Type Description
list[str]

Canonical filename rules using / as separator.

Invalid rules are rejected by the single-rule normalizer before any canonical value is returned.

Source code in src/topmark/filetypes/filename_rules.py
def normalize_filename_rules(rules: Iterable[str], *, file_type: str) -> list[str]:
    """Return canonical POSIX-style filename rules.

    Args:
        rules: Exact basename and relative tail-subpath filename rules to
            normalize.
        file_type: Qualified file type identifier used in validation errors.

    Returns:
        Canonical filename rules using `/` as separator.

    Invalid rules are rejected by the single-rule normalizer before any
    canonical value is returned.
    """
    return [_normalize_filename_rule(rule, file_type=file_type) for rule in rules]