Skip to content

Commit

Permalink
fix(rule): allow leading directories in rule path glob
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Nov 10, 2019
1 parent 5609dfb commit 00c7b89
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/rule/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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>> {
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);
Expand Down

0 comments on commit 00c7b89

Please sign in to comment.