1
0
Fork 0

fix(rule): allow leading directories in rule path glob

This commit is contained in:
ssube 2019-11-09 23:04:18 -06:00
parent 5609dfb4c6
commit 00c7b89f93
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
1 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,6 @@ import { applyDiff, diff } from 'deep-diff';
import { cloneDeep, Dictionary, intersection, isNil } from 'lodash'; import { cloneDeep, Dictionary, intersection, isNil } from 'lodash';
import { Minimatch } from 'minimatch'; import { Minimatch } from 'minimatch';
import { LogLevel } from 'noicejs'; import { LogLevel } from 'noicejs';
import { join } from 'path';
import recursive from 'recursive-readdir'; import recursive from 'recursive-readdir';
import { YamlParser } from '../parser/YamlParser'; import { YamlParser } from '../parser/YamlParser';
@ -121,17 +120,19 @@ export async function loadRuleFiles(paths: Array<string>, ctx: VisitorContext):
} }
export async function loadRulePaths(paths: Array<string>, ctx: VisitorContext): Promise<Array<Rule>> { export async function loadRulePaths(paths: Array<string>, ctx: VisitorContext): Promise<Array<Rule>> {
const match = new Minimatch('*.+(json|yaml|yml)'); const match = new Minimatch('**/*.+(json|yaml|yml)', {
nocase: true,
});
const rules = []; const rules = [];
for (const path of paths) { for (const path of paths) {
const allFiles = await recursive(path); const allFiles = await recursive(path);
ctx.logger.debug({ files: allFiles }, 'path matched files');
// skip files that start with `.`, limit to json and yaml/yml // skip files that start with `.`, limit to json and yaml/yml
const files = allFiles const files = allFiles
.filter((name) => name[0] !== '.') .filter((name) => name[0] !== '.')
.filter((name) => match.match(name.toLowerCase())) .filter((name) => match.match(name));
.map((name) => join(path, name));
ctx.logger.debug({ allFiles, files }, 'path matched files');
const pathRules = await loadRuleFiles(files, ctx); const pathRules = await loadRuleFiles(files, ctx);
rules.push(...pathRules); rules.push(...pathRules);