Skip to content

Commit

Permalink
feat: streamlined and unified README.md badges (#1154)
Browse files Browse the repository at this point in the history
## PR Checklist

- [x] Addresses an existing open issue: fixes #1088
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Standardizes README.md badges to have the emoji at the start because I
want them consistent and the npm version badge can't have the emoji
tacked on.

Streamlines them by removing the _sponsor_ and _style_ badges and
trimming the _code of conduct_ badge down to say _kept_ instead of
_enforced. This means they should all fit on one line in the npm site.

Also fixes a bug in `findExistingBadges` where matchers were being
re-created _then_ looped on, instead of re-created each instance of the
loop. `/g` regexp state matters!
  • Loading branch information
JoshuaKGoldberg committed Dec 31, 2023
1 parent d2adaa0 commit 6daf043
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"badgeTemplate": "\t<a href=\"#contributors\" target=\"_blank\"><img alt=\"All Contributors: <%= contributors.length %> 馃應\" src=\"https://img.shields.io/badge/all_contributors-<%= contributors.length %>_馃應-21bb42.svg\" /></a>",
"badgeTemplate": "\t<a href=\"#contributors\" target=\"_blank\"><img alt=\"馃應 All Contributors: <%= contributors.length %>\" src=\"https://img.shields.io/badge/馃應_all_contributors-<%= contributors.length %>-21bb42.svg\" /></a>",
"commit": false,
"commitConvention": "angular",
"commitType": "docs",
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
<p align="center">
<!-- prettier-ignore-start -->
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors" target="_blank"><img alt="All Contributors: 40 馃應" src="https://img.shields.io/badge/all_contributors-40_馃應-21bb42.svg" /></a>
<a href="#contributors" target="_blank"><img alt="馃應 All Contributors: 40" src="https://img.shields.io/badge/馃應_all_contributors-40-21bb42.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<!-- prettier-ignore-end -->
<a href="https://codecov.io/gh/JoshuaKGoldberg/create-typescript-app" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/create-typescript-app/branch/main/graph/badge.svg"/></a>
<a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Code of Conduct: Enforced 馃" src="https://img.shields.io/badge/code_of_conduct-enforced_馃-21bb42" /></a>
<a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT 馃摑" src="https://img.shields.io/badge/license-MIT_馃摑-21bb42.svg"></a>
<a href="https://github.com/sponsors/JoshuaKGoldberg" target="_blank"><img alt="Sponsor: On GitHub 馃捀" src="https://img.shields.io/badge/sponsor-on_github_馃捀-21bb42.svg" /></a>
<img alt="Style: Prettier 馃Ч" src="https://img.shields.io/badge/style-prettier_馃Ч-21bb42.svg" />
<img alt="TypeScript: Strict 馃挭" src="https://img.shields.io/badge/typescript-strict_馃挭-21bb42.svg" />
<img alt="npm package version" src="https://img.shields.io/npm/v/create-typescript-app?color=21bb42" />
<a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="馃 Code of Conduct: Kept" src="https://img.shields.io/badge/馃_code_of_conduct-kept-21bb42" /></a>
<a href="https://codecov.io/gh/JoshuaKGoldberg/create-typescript-app" target="_blank"><img alt="馃И Coverage" src="https://img.shields.io/codecov/c/github/JoshuaKGoldberg/create-typescript-app?label=馃И%20coverage"/></a>
<a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/LICENSE.md" target="_blank"><img alt="馃摑 License: MIT" src="https://img.shields.io/badge/馃摑_license-MIT-21bb42.svg"></a>
<a href="http://npmjs.com/package/create-typescript-app"><img alt="馃摝 npm version" src="https://img.shields.io/npm/v/create-typescript-app?color=21bb42&label=馃摝%20npm" /></a>
<img alt="馃挭 TypeScript: Strict" src="https://img.shields.io/badge/馃挭_typescript-strict-21bb42.svg" />
</p>

<img align="right" alt="Project logo: the TypeScript blue square with rounded corners, but a plus sign instead of 'TS'" src="./create-typescript-app.png">
Expand Down
22 changes: 1 addition & 21 deletions script/__snapshots__/migrate-test-e2e.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,7 @@ exports[`expected file changes > README.md 1`] = `
"--- a/README.md
+++ b/README.md
@@ ... @@
<p align="center">
<!-- prettier-ignore-start -->
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
- <a href="#contributors" target="_blank"><img alt="All Contributors: 39 馃應" src="https://img.shields.io/badge/all_contributors-39_馃應-21bb42.svg" /></a>
+ <a href="#contributors" target="_blank"><img alt="All Contributors: 39 馃應" src="https://img.shields.io/badge/all_contributors-39_馃應-21bb42.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<!-- prettier-ignore-end -->
<a href="https://codecov.io/gh/JoshuaKGoldberg/create-typescript-app" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/create-typescript-app/branch/main/graph/badge.svg"/></a>
- <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Code of Conduct: Enforced 馃" src="https://img.shields.io/badge/code_of_conduct-enforced_馃-21bb42" /></a>
- <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT 馃摑" src="https://img.shields.io/badge/license-MIT_馃摑-21bb42.svg"></a>
- <a href="https://github.com/sponsors/JoshuaKGoldberg" target="_blank"><img alt="Sponsor: On GitHub 馃捀" src="https://img.shields.io/badge/sponsor-on_github_馃捀-21bb42.svg" /></a>
- <img alt="Style: Prettier 馃Ч" src="https://img.shields.io/badge/style-prettier_馃Ч-21bb42.svg" />
- <img alt="TypeScript: Strict 馃挭" src="https://img.shields.io/badge/typescript-strict_馃挭-21bb42.svg" />
+ <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>
+ <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/JoshuaKGoldberg/create-typescript-app?color=21bb42"></a>
+ <a href="https://github.com/sponsors/JoshuaKGoldberg" target="_blank"><img alt="Sponsor: On GitHub" src="https://img.shields.io/badge/sponsor-on_github-21bb42.svg" /></a>
+ <img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />
+ <img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />
<img alt="npm package version" src="https://img.shields.io/npm/v/create-typescript-app?color=21bb42" />
+ <a href="#contributors" target="_blank"><img alt="All Contributors: 39 馃應" src="https://img.shields.io/badge/all_contributors-39_馃應-21bb42.svg" /></a>
+ <img alt="Sponsor: On GitHub 馃捀" src="https://img.shields.io/badge/sponsor-on_github_馃捀-21bb42.svg" />
<img alt="馃挭 TypeScript: Strict" src="https://img.shields.io/badge/馃挭_typescript-strict-21bb42.svg" />
</p>
-<img align="right" alt="Project logo: the TypeScript blue square with rounded corners, but a plus sign instead of 'TS'" src="./create-typescript-app.png">
Expand Down
34 changes: 21 additions & 13 deletions src/steps/writeReadme/findExistingBadges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("findExistingBadges", () => {

describe("single result cases", () => {
test.each([
`[![GitHub CI](https://github.com/JoshuaKGoldberg/console-fail-test/actions/workflows/compile.yml/badge.svg)](https://github.com/JoshuaKGoldberg/console-fail-test/actions/workflows/compile.yml)`,
`[![GitHub CI](https://github.com/ExampleOwner/console-fail-test/actions/workflows/compile.yml/badge.svg)](https://github.com/ExampleOwner/console-fail-test/actions/workflows/compile.yml)`,
`[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)](https://prettier.io)`,
`![TypeScript: Strict](https://img.shields.io/badge/typescript-strict-brightgreen.svg)`,
`[![NPM version](https://badge.fury.io/js/console-fail-test.svg)](http://badge.fury.io/js/console-fail-test)`,
Expand All @@ -36,14 +36,22 @@ describe("findExistingBadges", () => {
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<!-- prettier-ignore-end -->
</a>`,
` <a href="https://codecov.io/gh/JoshuaKGoldberg/all-contributors-auto-action" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/all-contributors-auto-action/branch/main/graph/badge.svg"/></a>`,
` <a href="https://github.com/JoshuaKGoldberg/all-contributors-auto-action/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>`,
` <a href="https://codecov.io/gh/ExampleOwner/example-repository" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/ExampleOwner/example-repository/branch/main/graph/badge.svg"/></a>`,
` <a href="https://github.com/ExampleOwner/example-repository/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>`,
`<a href="http://npmjs.com/package/example-repository"><img alt="馃摝 npm version" src="https://img.shields.io/npm/v/example-repository?color=21bb42&label=馃摝%20npm" /></a>`,
`<a href="https://codecov.io/gh/ExampleOwner/example-repository" target="_blank"><img alt="馃И Coverage" src="https://img.shields.io/codecov/c/github/ExampleOwner/example-repository?label=馃И%20coverage"/></a>`,
`<a href="https://github.com/ExampleOwner/example-repository/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="馃 Code of Conduct: kept" src="https://img.shields.io/badge/kept-21bb42?label=馃%20code%20of%20conduct" /></a>`,
`<a href="https://github.com/ExampleOwner/example-repository/blob/main/LICENSE.md" target="_blank"><img alt="馃摑 License: MIT" src="https://img.shields.io/badge/馃摑_license-MIT-21bb42.svg"></a>`,
`<a href="https://github.com/ExampleOwner/example-repository/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/ExampleOwner/example-repository?color=21bb42"></a>`,
`
<a href="https://github.com/JoshuaKGoldberg/all-contributors-auto-action/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/JoshuaKGoldberg/all-contributors-auto-action?color=21bb42"></a>`,
`
<a href="https://github.com/sponsors/JoshuaKGoldberg" target="_blank"><img alt="Sponsor: On GitHub" src="https://img.shields.io/badge/sponsor-on_github-21bb42.svg" /></a>`,
<a href="https://github.com/ExampleOwner/example-repository/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/ExampleOwner/example-repository?color=21bb42"></a>
`,
`<img alt="馃挭 TypeScript: Strict" src="https://img.shields.io/badge/馃挭_typescript-strict-21bb42.svg" />`,
`<img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />`,
`<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />`,
`
<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />
`,
])("%s", (contents) => {
expect(findExistingBadges(contents)).toEqual([contents.trim()]);
});
Expand Down Expand Up @@ -82,21 +90,21 @@ describe("findExistingBadges", () => {
<a href="#contributors" target="_blank"><img alt="All Contributors: 1" src="https://img.shields.io/badge/all_contributors-1-21bb42.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<!-- prettier-ignore-end -->
<a href="https://codecov.io/gh/JoshuaKGoldberg/all-contributors-auto-action" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/all-contributors-auto-action/branch/main/graph/badge.svg?token=eVIFY4MhfQ"/></a>
<a href="https://github.com/JoshuaKGoldberg/all-contributors-auto-action/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>
<a href="https://github.com/JoshuaKGoldberg/all-contributors-auto-action/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/JoshuaKGoldberg/all-contributors-auto-action?color=21bb42"></a>
<a href="https://github.com/sponsors/JoshuaKGoldberg" target="_blank"><img alt="Sponsor: On GitHub" src="https://img.shields.io/badge/sponsor-on_github-21bb42.svg" /></a>
<a href="https://codecov.io/gh/ExampleOwner/example-repository" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/ExampleOwner/example-repository/branch/main/graph/badge.svg?token=eVIFY4MhfQ"/></a>
<a href="https://github.com/ExampleOwner/example-repository/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>
<a href="https://github.com/ExampleOwner/example-repository/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/ExampleOwner/example-repository?color=21bb42"></a>
<img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />
<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />
</p>
`),
).toMatchInlineSnapshot(`
[
"<a href="#contributors" target="_blank"><img alt="All Contributors: 1" src="https://img.shields.io/badge/all_contributors-1-21bb42.svg" /></a>",
"<a href="https://github.com/JoshuaKGoldberg/all-contributors-auto-action/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>",
"<a href="https://github.com/sponsors/JoshuaKGoldberg" target="_blank"><img alt="Sponsor: On GitHub" src="https://img.shields.io/badge/sponsor-on_github-21bb42.svg" /></a>",
"<img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/all-contributors-auto-action/branch/main/graph/badge.svg?token=eVIFY4MhfQ"/>",
"<a href="https://codecov.io/gh/ExampleOwner/example-repository" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/ExampleOwner/example-repository/branch/main/graph/badge.svg?token=eVIFY4MhfQ"/></a>",
"<a href="https://github.com/ExampleOwner/example-repository/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a>",
"<a href="https://github.com/ExampleOwner/example-repository/blob/main/LICENSE.md" target="_blank"><img alt="License: MIT" src="https://img.shields.io/github/license/ExampleOwner/example-repository?color=21bb42"></a>",
"<img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />",
"<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />",
]
`);
});
Expand Down
9 changes: 3 additions & 6 deletions src/steps/writeReadme/findExistingBadges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export function findExistingBadges(contents: string): string[] {
let remaining = contents.split(/<\s*h2.*>|##/)[0];

for (const createMatcher of existingBadgeMatcherCreators) {
const matcher = createMatcher();

while (true) {
const matcher = createMatcher();
const matched = matcher.exec(remaining);

if (!matched) {
Expand All @@ -22,10 +21,8 @@ export function findExistingBadges(contents: string): string[] {
const [badge] = matched;

badges.push(badge.trim());
remaining = [
remaining.slice(0, matched.index),
remaining.slice(matched.index + badge.length),
].join("");

remaining = remaining.replace(badge, "");
}
}

Expand Down
Loading

0 comments on commit 6daf043

Please sign in to comment.