Glob Pattern Matching Algorithm

Reference of the Glob Pattern Matching Algorithm

The glob pattern matching algorithm describes the rules and behavior for matching file paths against glob patterns on the Ketryx Platform, specifically for restricting dependency file locations and detecting Git-based items for repositories.

Examples

Glob PatternMeaning

**

Matches any file in the file path

!**

Matches no files

**/test.js

Matches any file in the given root directory and its sub directories matching test.js

test/**

Matches any file in the test directory and its sub directories

**/*.[jt]s

Matches any file with .js and .ts extensions

spec-[1-4].md

Matches files spec-1.md, spec-2.md, spec-3.md, and spec-4.md

**/*{.js,.ts,.jsx,.tsx}

Matches any file with .js, .ts, .jsx, and .tsx extensions

Matching a file path when multiple glob patterns have been provided

  • Matching occurs from the first defined pattern to the last defined pattern

  • During the matching, it keeps a match / no match state that is updated based on the current matching result of each glob pattern

  • The given file path is matched against each glob pattern

  • As soon as a non-negated glob pattern matches the file path, the matching state would be true

  • From there on, negated patterns (starting with !) matching the file path may set the matching state back to false

  • Following negation, subsequent matches of non-negated patterns can revert the matching state back to true, allowing for toggling between inclusion and exclusion of files or paths

  • Alternating matches of negated and non-negated patterns can toggle the matching state, allowing fine-grained control over which files or paths are ultimately selected

  • The final matching result will be returned, i.e. "the last match wins", and whether the file is included in the analysis is based on whether that match is negated or not

Last updated

© 2024 Ketryx Corporation