Skip to content

Commit

Permalink
Add glob support
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Nov 5, 2023
1 parent 95d66b1 commit 46b1aa7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ const delay = Number(cli.flagMap.delay) || 500; //default half second de
const trim = Number(cli.flagMap.trim) || null;

// Validator
const globOptions = { ignore: '**/node_modules/**/*' };
const keep = (filename) => !filename.includes('node_modules/');
const readFolder = (folder) => globSync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
const readFolder = (folder) => globSync(folder + '**/*.html', globOptions);
const expandFolder = (file) => fs.lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
const getAllPaths = () => files.map(file => globSync(file, globOptions)).flat();
const getFilenames = () => getAllPaths().map(expandFolder).flat().filter(keep).sort();
const list = files.length ? getFilenames() : readFolder('');
const excludes = cli.flagMap.exclude?.split(',') ?? [];
const filenames = list.filter(name => !excludes.find(exclude => name.includes(exclude)));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"assert-deep-strict-equal": "~1.1",
"copy-file-util": "~1.1",
"copy-folder-util": "~1.1",
"eslint": "~8.52",
"eslint": "~8.53",
"jshint": "~2.13",
"merge-stream": "~2.0",
"mocha": "~10.2",
Expand Down
6 changes: 6 additions & 0 deletions spec/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ describe('Executing the CLI', () => {
assertDeepStrictEqual(actual, expected);
});

it('with a glob selects the correct files to validate', () => {
const actual = run('html-validator "spec/**/valid.html" --note=glob');
const expected = null;
assertDeepStrictEqual(actual, expected);
});

it('skips validation message matching --ignore and --ignore-config regex patterns', () => {
const actual = run('html-validator spec/html "--ignore=/^Section lacks heading/" --ignore-config=spec/ignore-config.txt');
const expected = null;
Expand Down

0 comments on commit 46b1aa7

Please sign in to comment.