KogenCredo.CoreSupport.Paths (KogenCredo v0.1.0)

View Source

Filename scoping helpers shared by the KogenCredo checks.

Paths are matched on segment boundaries, so "lib/app" matches lib/app.ex and lib/app/x.ex but not lib/app_web/x.ex. A prefix also matches below a leading directory (apps/web/lib/x.ex matches "lib/"), so umbrella projects need no extra configuration.

Summary

Functions

True when filename lies at or below one of the path prefixes.

True when the file is in included (empty means everywhere) and not in excluded.

Matches filename against exact paths, path suffixes or */** globs.

Normalises separators and strips a leading ./.

Functions

in_paths?(filename, prefixes)

@spec in_paths?(String.t(), [String.t()]) :: boolean()

True when filename lies at or below one of the path prefixes.

in_scope?(filename, included, excluded \\ [])

@spec in_scope?(String.t(), [String.t()], [String.t()]) :: boolean()

True when the file is in included (empty means everywhere) and not in excluded.

matches_any?(filename, patterns)

@spec matches_any?(String.t(), [String.t()]) :: boolean()

Matches filename against exact paths, path suffixes or */** globs.

A pattern without * matches the whole filename or a trailing path suffix.

normalize(filename)

@spec normalize(String.t()) :: String.t()

Normalises separators and strips a leading ./.