Skip to content

Commit

Permalink
fix: support plugins and additional config properties
Browse files Browse the repository at this point in the history
Fixes #730
  • Loading branch information
joshbolduc committed Jun 25, 2023
1 parent 24d581d commit 38d3080
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
} from 'vscode';
import type { InputBox } from './git';
import { runLint } from './lint';
import { log } from './log';
import { parseCommit } from './parse';
import { stringify } from './stringify';
import { tryGetGitExtensionApi } from './tryGetGitExtensionApi';
import { isGitCommitDoc, isScmTextInput } from './utils';

Expand Down Expand Up @@ -69,7 +71,9 @@ async function tryGetDiagnostics(doc: TextDocument) {

try {
return await getDiagnostics(doc);
} catch {
} catch (e) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
log(`Uncaught exception: ${stringify(e)}`);
return [];
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export async function runLint(text: string, path: string | undefined) {
const lint = importCommitlintLint(path);

return {
problems: await lint(
text,
config.rules,
config.parserPreset
? { parserOpts: config.parserPreset.parserOpts as ParserOptions }
: {},
),
problems: await lint(text, config.rules, {
defaultIgnores: config.defaultIgnores,
helpUrl: config.helpUrl,
ignores: config.ignores,
parserOpts: config.parserPreset?.parserOpts as ParserOptions | undefined,
plugins: config.plugins,
}),
helpUrl: config.helpUrl,
};
}
17 changes: 17 additions & 0 deletions src/stringify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const stringify = (item: unknown) => {
if (item instanceof Error) {
return `${item.name}: ${item.message}${
item.stack ? `\n${item.stack}\n` : ''
}`;
}

if (typeof item === 'object' && String(item) === '[object Object]') {
try {
return JSON.stringify(item);
} catch {
// fall through
}
}

return item;
};

0 comments on commit 38d3080

Please sign in to comment.