Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new excludeFilesPattern option #117

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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