Skip to content

Commit 4cb2b50

Browse files
committed
chore(refactor): split parseConfig function
1 parent b319155 commit 4cb2b50

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"scopeOverrides": {
2828
"chore": [
2929
"tools",
30+
"refactor",
31+
"test",
3032
"deps",
3133
"docs",
3234
"examples"

src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,19 @@ export function getScopes(type: string, config: Config): string[] {
5555
return config.scopeOverrides[type] ?? config.scopes;
5656
}
5757

58-
export function parseConfig(path: string | undefined): Config {
58+
export function parseConfigFile(path: string | undefined): Config {
5959
const json = path
6060
? JSON.parse(readFileSync(path, { encoding: 'utf-8' }))
6161
: JSON.parse(
6262
readFileSync(join(process.cwd(), 'package.json'), {
6363
encoding: 'utf-8',
6464
})
6565
).commithelper || {};
66-
const parsed = Config.decode(json);
66+
return parseConfig(json);
67+
}
68+
69+
export function parseConfig(config: Partial<Config>): Config {
70+
const parsed = Config.decode(config);
6771
const onLeft = (): never => {
6872
throw new Error(PathReporter.report(parsed).join('\n'));
6973
};

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Command, Option } from 'commander';
22
import { readFileSync, writeFileSync, promises } from 'fs';
33
import { resolve } from 'path';
44

5-
import { parseConfig } from './config';
5+
import { parseConfigFile } from './config';
66
import { createCommitMessage } from './prompt';
77
import { checkMessage } from './lint';
88
import { renderMessage, parseMessage } from './message';
@@ -46,7 +46,7 @@ program
4646

4747
function lintMessage(): void {
4848
const options = checkCommand.opts();
49-
const config = parseConfig(options.config);
49+
const config = parseConfigFile(options.config);
5050
const msg = readFileSync(options.file ?? process.stdin.fd, {
5151
encoding: 'utf-8',
5252
});
@@ -62,7 +62,7 @@ function lintMessage(): void {
6262

6363
function runInteractive(): void {
6464
const options = promptCommand.opts();
65-
const config = parseConfig(options.config);
65+
const config = parseConfigFile(options.config);
6666

6767
createCommitMessage(config)
6868
.then(msg => {

0 commit comments

Comments
 (0)