Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

fix: yaml formatting #557

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions readme-parser/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const DATA = `

## Description

This is an amazing codemod which does \`the thing\`
This is an amazing codemod which does \`the thing\`. Changes:

### WARNING

Expand Down Expand Up @@ -98,7 +98,7 @@ describe('parse/yaml', function () {
deepEqual(parseResult, {
name: 'Do the thing',
description:
'This is an amazing codemod which does `the thing`\n\n### WARNING\n\nThis codemod does the thing\n' +
'This is an amazing codemod which does `the thing`. Changes:\n\n\n### WARNING\n\nThis codemod does the thing\n' +
'Following the original msw [upgrade guide](https://mswjs.io/docs/migrations/1.x-to-2.x/#imports), ' +
'there are certain imports that changed their location and/or naming. This codemod will adjust your imports to the new location and naming.\n' +
' - `setupWorker` is now imported from `msw/browser`\n' +
Expand Down Expand Up @@ -171,7 +171,8 @@ f_long-description: >-
## Description


This is an amazing codemod which does \`the thing\`
This is an amazing codemod which does \`the thing\`. Changes:


### WARNING

Expand Down Expand Up @@ -249,8 +250,8 @@ seo:
title: Msw V2 - Do the thing | Codemod.com Automations
og:title: Msw V2 - Do the thing | Codemod.com Automations
twitter:title: Msw V2 - Do the thing | Codemod.com Automations
description: This is an amazing codemod which does \`the thing\`
twitter:card: This is an amazing codemod which does \`the thing\`
description: This is an amazing codemod which does the thing
twitter:card: This is an amazing codemod which does the thing
`.trim(),
);
});
Expand Down
8 changes: 7 additions & 1 deletion readme-parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,13 @@ export const convertToYaml = (
}
titleWithVersion = capitalize(titleWithVersion);

const shortDescription = description.split('\n').at(0);
const shortDescription = description
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be undefined, can it be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically it's not possible because split will always return a single-item array even if no splits happened
it's the native typing of at() method that causes optional chaining to be necessary. i would still prefer it over non-null assertion.

.split('\n')
.at(0)
?.split('.')
.at(0)
?.replace('`', '')
.replace(/\W$/g, '');

const res = `
created-on: ${new Date().toISOString()}
Expand Down
Loading