Skip to content

Commit

Permalink
fix: packageRules don’t match undefined depName (#7462)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Oct 13, 2020
1 parent 4d0f99a commit 5e38204
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/util/package-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ describe('applyPackageRules()', () => {
expect(res.x).toBeUndefined();
expect(res.y).toBeUndefined();
});
it('ignores patterns if lock file maintenance', () => {
const dep = {
enabled: true,
packagePatterns: ['.*'],
updateType: 'lockFileMaintenance' as UpdateType,
packageRules: [
{
excludePackagePatterns: ['^foo'],
enabled: false,
},
],
};
const res = applyPackageRules(dep);
expect(res.enabled).toBe(true);
const res2 = applyPackageRules({ ...dep, depName: 'anything' });
expect(res2.enabled).toBe(false);
});
it('matches anything if missing inclusive rules', () => {
const config: TestConfig = {
packageRules: [
Expand Down
4 changes: 2 additions & 2 deletions lib/util/package-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function matchesRule(inputConfig: Config, packageRule: PackageRule): boolean {
}
positiveMatch = true;
}
if (packageNames.length || packagePatterns.length) {
if (depName && (packageNames.length || packagePatterns.length)) {
let isMatch = packageNames.includes(depName);
// name match is "or" so we check patterns if we didn't match names
if (!isMatch) {
Expand Down Expand Up @@ -164,7 +164,7 @@ function matchesRule(inputConfig: Config, packageRule: PackageRule): boolean {
}
positiveMatch = true;
}
if (excludePackagePatterns.length) {
if (depName && excludePackagePatterns.length) {
let isMatch = false;
for (const pattern of excludePackagePatterns) {
const packageRegex = regEx(
Expand Down

0 comments on commit 5e38204

Please sign in to comment.