From 00c7b89f93c9910dbeb0a8331735ecc346ec40a2 Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 9 Nov 2019 23:04:18 -0600 Subject: [PATCH] fix(rule): allow leading directories in rule path glob --- src/rule/index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/rule/index.ts b/src/rule/index.ts index ccb0886..bd38654 100644 --- a/src/rule/index.ts +++ b/src/rule/index.ts @@ -3,7 +3,6 @@ import { applyDiff, diff } from 'deep-diff'; import { cloneDeep, Dictionary, intersection, isNil } from 'lodash'; import { Minimatch } from 'minimatch'; import { LogLevel } from 'noicejs'; -import { join } from 'path'; import recursive from 'recursive-readdir'; import { YamlParser } from '../parser/YamlParser'; @@ -121,17 +120,19 @@ export async function loadRuleFiles(paths: Array, ctx: VisitorContext): } export async function loadRulePaths(paths: Array, ctx: VisitorContext): Promise> { - const match = new Minimatch('*.+(json|yaml|yml)'); + const match = new Minimatch('**/*.+(json|yaml|yml)', { + nocase: true, + }); const rules = []; for (const path of paths) { const allFiles = await recursive(path); - ctx.logger.debug({ files: allFiles }, 'path matched files'); // skip files that start with `.`, limit to json and yaml/yml const files = allFiles .filter((name) => name[0] !== '.') - .filter((name) => match.match(name.toLowerCase())) - .map((name) => join(path, name)); + .filter((name) => match.match(name)); + + ctx.logger.debug({ allFiles, files }, 'path matched files'); const pathRules = await loadRuleFiles(files, ctx); rules.push(...pathRules);