Skip to content

Commit

Permalink
add new excludeFilesPattern option (#117)
Browse files Browse the repository at this point in the history
Adding new excludeFilesPattern option, so we can specify to good-fences what files to ignore. For example *.test.ts files.
  • Loading branch information
joker99 authored Mar 7, 2023
1 parent c7f83d4 commit 4502c31
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ Default | CLI | API
`6000` | `--maxConcurrentFenceJobs <number>`<br/>`-j <number>` | `maxConcurrentFenceJobs: number`


### Exclude Files Patten

Specify a pattern for file names that should be excluded from good-fences validation. For example *.test.ts to exclude test files.

Default | CLI | API
----------------|-------------------------------------------------------|----
`undefined` | `--excludeFilesPattern <string>`<br/>`-p <string>` | `excludeFilesPattern: string`


## Return value

When running good-fences via the API, the results are returned in a structure like the following:
Expand Down
5 changes: 5 additions & 0 deletions sample/src/componentA/helperA1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import helperB1 from '../componentB/helperB1'; // INVALID IMPORT in regular code, but valid in test code

export default function helperA1() {
helperB1();
}
4 changes: 4 additions & 0 deletions src/core/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ async function main() {
'-j, --maxConcurrentFenceJobs',
'Maximum number of concurrent fence jobs to run. Default 6000'
)
.option(
'-p, --excludeFilesPattern <string>',
'Exclude files matching the pattern from validation'
)
.option('-b, --progressBar', 'Show a progress bar while evaluating fences');
program.parse(process.argv);
const options = program.opts() as RawOptions;
Expand Down
11 changes: 11 additions & 0 deletions src/core/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ export async function run(rawOptions: RawOptions) {
? getSourceFilesFromPartialCheck(sourceFileProvider, partialCheck)
: getSourceFilesNormalized(sourceFileProvider));

if (options.excludeFilesPattern !== undefined) {
// A naive string replace to convert the glob pattern to a regex pattern
let regexString = options.excludeFilesPattern
.replace('\\', '\\\\.')
.replace('.', '\\.')
.replace('*', '.*?');
normalizedFiles = normalizedFiles.filter(
fileName => !fileName.match(new RegExp(regexString, 'i'))
);
}

await runWithConcurrentLimit(
// we have to limit the concurrent executed promises because
// otherwise we will open all the files at the same time and
Expand Down
1 change: 1 addition & 0 deletions src/types/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export default interface Options {
// we try to open too many files concurrently.
maxConcurrentFenceJobs: number;
progress: boolean;
excludeFilesPattern?: string;
}
1 change: 1 addition & 0 deletions src/types/RawOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default interface RawOptions {
looseRootFileDiscovery?: boolean;
maxConcurrentJobs?: number;
progressBar?: boolean;
excludeFilesPattern?: string;
}
1 change: 1 addition & 0 deletions src/utils/getOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export function setOptions(rawOptions: RawOptions) {
looseRootFileDiscovery: rawOptions.looseRootFileDiscovery || false,
maxConcurrentFenceJobs: rawOptions.maxConcurrentJobs || 6000,
progress: rawOptions.progressBar || false,
excludeFilesPattern: rawOptions.excludeFilesPattern,
};
}
2 changes: 2 additions & 0 deletions test/endToEnd/endToEndTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('runner', () => {
// Act
const actualResults = await run({
rootDir: './sample',
excludeFilesPattern: '*.test.ts',
});

// Assert
Expand All @@ -29,6 +30,7 @@ describe('runner', () => {
const actualResults = await run({
rootDir: './sample',
looseRootFileDiscovery: true,
excludeFilesPattern: '*.test.ts',
});

// Assert
Expand Down

0 comments on commit 4502c31

Please sign in to comment.