Skip to content

Commit 4a8a4c9

Browse files
committed
refactor: unnest getEditFilePath
1 parent 3d4f506 commit 4a8a4c9

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

@commitlint/read/src/get-edit-file-path.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@ export async function getEditFilePath(
88
top: string,
99
edit?: boolean | string
1010
): Promise<string> {
11-
let editFilePath: string;
1211
if (typeof edit === 'string') {
13-
editFilePath = path.resolve(top, edit);
14-
} else {
15-
const dotgitPath = path.join(top, '.git');
16-
const dotgitStats: Stats = sander.lstatSync(dotgitPath);
17-
if (dotgitStats.isDirectory()) {
18-
editFilePath = path.join(top, '.git/COMMIT_EDITMSG');
19-
} else {
20-
const gitFile: string = await sander.readFile(dotgitPath, {
21-
encoding: 'utf-8'
22-
});
23-
const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', '');
24-
editFilePath = path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG');
25-
}
12+
return path.resolve(top, edit);
2613
}
2714

28-
return editFilePath;
15+
const dotgitPath = path.join(top, '.git');
16+
const dotgitStats: Stats = sander.lstatSync(dotgitPath);
17+
18+
if (dotgitStats.isDirectory()) {
19+
return path.join(top, '.git/COMMIT_EDITMSG');
20+
}
21+
22+
const gitFile: string = await sander.readFile(dotgitPath, {
23+
encoding: 'utf-8'
24+
});
25+
const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', '');
26+
return path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG');
2927
}

0 commit comments

Comments
 (0)