diff --git a/docs/usage/string-pattern-matching.md b/docs/usage/string-pattern-matching.md index 61ad36545a9f7c..02cbc6e3856f7d 100644 --- a/docs/usage/string-pattern-matching.md +++ b/docs/usage/string-pattern-matching.md @@ -5,6 +5,38 @@ Renovate string matching syntax for some configuration options allows you, as us - [`minimatch`](https://github.com/isaacs/minimatch) glob patterns, including exact strings matches - regular expression (regex) patterns +The following fields support this pattern matching: + +- `allowedEnv` +- `allowedHeaders` +- `autodiscoverProjects` +- `matchRepositories` + +## Special case: Match everything + +The value `*` is a special case which means "match everything". +It is not valid to combine `*` with any other positive or negative match. + +```json title="Example of valid wildcard use" +{ + "allowedEnv": ["*"] +} +``` + +```json title="Example of invalid wildcard use with additional match" +{ + "allowedEnv": ["*", "ABC"] +} +``` + +```json title="Example of invalid wildcard use with negation" +{ + "allowedEnv": ["*", "!ABC"] +} +``` + +In the latter case, the `*` can be ommitted and achieve the same thing. + ## Regex matching A valid regex pattern: @@ -76,6 +108,9 @@ For example, the pattern `["/^abc/", "!/^abcd/", "!/abce/"]`: - matches `"abc"` and `"abcf"` - does _not_ match `"foo"`, `"abcd"`, `"abce"`, or `"abcdef"` +If you find yourself in a situation where you need to positive-match a string which starts with `!`, then you need to do so using a regular expression pattern. +For example, `["/^!abc$/"]` will positively match against the string `"!abc"`. + ## Usage in Renovate configuration options Renovate has evolved its approach to string pattern matching over time, but this means that existing configurations may have a mix of approaches and not be entirely consistent with each other. diff --git a/lib/util/string-match.spec.ts b/lib/util/string-match.spec.ts index 0321d4ce5720d6..e76d200d7b03f5 100644 --- a/lib/util/string-match.spec.ts +++ b/lib/util/string-match.spec.ts @@ -14,6 +14,10 @@ describe('util/string-match', () => { expect(matchRegexOrGlobList('test', ['/test2/'])).toBeFalse(); }); + it('returns true if star', () => { + expect(matchRegexOrGlobList('&&&', ['*'])).toBeTrue(); + }); + it('returns true if any match', () => { expect(matchRegexOrGlobList('test', ['test', '/test2/'])).toBeTrue(); }); diff --git a/lib/util/string-match.ts b/lib/util/string-match.ts index 241debfbd17d0d..80cbc6dc05d7bd 100644 --- a/lib/util/string-match.ts +++ b/lib/util/string-match.ts @@ -19,6 +19,9 @@ export function getRegexOrGlobPredicate(pattern: string): StringMatchPredicate { } export function matchRegexOrGlob(input: string, pattern: string): boolean { + if (pattern === '*') { + return true; + } const predicate = getRegexOrGlobPredicate(pattern); return predicate(input); }