Skip to content

Commit

Permalink
Account for regexes in ignoreErrors setting (fixes #70)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderRonde committed Apr 22, 2024
1 parent 33b5cdc commit 3d33ad2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 8 additions & 3 deletions server/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ export async function getConfiguration(
options: config.options.map((option) =>
replaceVariables(option, workspaceFolders)
),
ignoreErrors: config.ignoreErrors.map((error) =>
replaceVariables(error, workspaceFolders)
),
ignoreErrors: config.ignoreErrors.map((error) => {
if (error instanceof RegExp) {
return new RegExp(
replaceVariables(error.source, workspaceFolders)
);
}
return replaceVariables(error, workspaceFolders);
}),
};
}

Expand Down
5 changes: 4 additions & 1 deletion server/src/lib/phpstan/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ export class PHPStanRunner implements Disposable {

private _filterIgnoredErrors(
errors: string[],
ignoredErrors: string[]
ignoredErrors: (string | RegExp)[]
): string[] {
for (const ignoreError of ignoredErrors) {
const regExp = (() => {
if (ignoreError instanceof RegExp) {
return ignoreError;
}
try {
return new RegExp(ignoreError);
} catch (e) {
Expand Down
7 changes: 6 additions & 1 deletion shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ export type ConfigSettingsWithoutPrefix = {
? R
: unknown]: ConfigSettings[K];
};
export type ConfigSettings = GetConfigurationType<typeof config>;
export type ConfigSettings = Omit<
GetConfigurationType<typeof config>,
'phpstan.ignoreErrors'
> & {
'phpstan.ignoreErrors': (string | RegExp)[];
};

0 comments on commit 3d33ad2

Please sign in to comment.