Skip to content

Commit

Permalink
refactor: make formatter a sync function
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc committed Sep 22, 2023
1 parent b6f95b2 commit 976f9ce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const changelogDescription = `All notable changes to this project will be docume
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).`;

export type Formatter = (changelog: string) => Promise<string>;
/**
* Formatter function that formats a Markdown changelog string.
*/
export type Formatter = (changelog: string) => string;

type ReleaseMetadata = {
/**
Expand Down Expand Up @@ -272,7 +275,7 @@ export default class Changelog {
constructor({
repoUrl,
tagPrefix = 'v',
formatter = async (changelog) => changelog,
formatter = (changelog) => changelog,
}: {
repoUrl: string;
tagPrefix?: string;
Expand Down Expand Up @@ -454,7 +457,7 @@ export default class Changelog {
*
* @returns The stringified changelog.
*/
async toString(): Promise<string> {
toString(): string {
const changelog = `${changelogTitle}
${changelogDescription}
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async function validate({
const changelogContent = await readChangelog(changelogPath);

try {
await validateChangelog({
validateChangelog({
changelogContent,
currentVersion,
repoUrl,
Expand Down Expand Up @@ -430,7 +430,7 @@ async function main() {
}
}

const formatter = async (changelog: string) => {
const formatter = (changelog: string) => {
return usePrettier
? prettier.format(changelog, { parser: 'markdown' })
: changelog;
Expand Down
2 changes: 1 addition & 1 deletion src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Changelog from './changelog';
* @param options.tagPrefix - The prefix used in tags before the version number.
* @returns The initial changelog text.
*/
export async function createEmptyChangelog({
export function createEmptyChangelog({
repoUrl,
tagPrefix = 'v',
}: {
Expand Down
4 changes: 2 additions & 2 deletions src/validate-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type ValidateChangelogOptions = {
* `true` and the changelog contains uncategorized changes.
* @throws `ChangelogFormattingError` - Will throw if there is a formatting error.
*/
export async function validateChangelog({
export function validateChangelog({
changelogContent,
currentVersion,
repoUrl,
Expand Down Expand Up @@ -141,7 +141,7 @@ export async function validateChangelog({
}
}

const validChangelog = await changelog.toString();
const validChangelog = changelog.toString();
if (validChangelog !== changelogContent) {
throw new ChangelogFormattingError({
validChangelog,
Expand Down

0 comments on commit 976f9ce

Please sign in to comment.