Skip to content

Commit 7a5c680

Browse files
feat: add ignores Addon for blockMarkdownlint (#2193)
## PR Checklist - [x] Addresses an existing open issue: fixes #2191 - [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 🎁
1 parent f76157d commit 7a5c680

7 files changed

+91
-18
lines changed

Diff for: src/blocks/blockCSpell.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ describe("blockCSpell", () => {
394394
expect(actual).toBeUndefined();
395395
});
396396

397-
it("returns compilerOptions when cspell.json contains ignorePaths and words", () => {
397+
it("returns the data when cspell.json contains ignorePaths and words", () => {
398398
const data = {
399399
ignorePaths: ["other"],
400400
words: ["abc", "def"],

Diff for: src/blocks/blockContributorCovenant.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ describe("blockContributorCovenant", () => {
1313
expect(creation).toMatchInlineSnapshot(`
1414
{
1515
"addons": [
16+
{
17+
"addons": {
18+
"ignores": [
19+
".github/CODE_OF_CONDUCT.md",
20+
],
21+
},
22+
"block": [Function],
23+
},
1624
{
1725
"addons": {
1826
"badges": [
@@ -176,6 +184,14 @@ describe("blockContributorCovenant", () => {
176184
expect(creation).toMatchInlineSnapshot(`
177185
{
178186
"addons": [
187+
{
188+
"addons": {
189+
"ignores": [
190+
".github/CODE_OF_CONDUCT.md",
191+
],
192+
},
193+
"block": [Function],
194+
},
179195
{
180196
"addons": {
181197
"badges": [

Diff for: src/blocks/blockContributorCovenant.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { base } from "../base.js";
2+
import { blockMarkdownlint } from "./blockMarkdownlint.js";
23
import { blockREADME } from "./blockREADME.js";
34
import { blockRemoveFiles } from "./blockRemoveFiles.js";
45

@@ -9,6 +10,9 @@ export const blockContributorCovenant = base.createBlock({
910
produce({ options }) {
1011
return {
1112
addons: [
13+
blockMarkdownlint({
14+
ignores: [".github/CODE_OF_CONDUCT.md"],
15+
}),
1216
blockREADME({
1317
badges: [
1418
{

Diff for: src/blocks/blockMarkdownlint.test.ts

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { testBlock } from "bingo-stratum-testers";
2-
import { describe, expect, test } from "vitest";
1+
import { testBlock, testIntake } from "bingo-stratum-testers";
2+
import { describe, expect, it, test } from "vitest";
33

44
import { blockMarkdownlint } from "./blockMarkdownlint.js";
55
import { optionsBase } from "./options.fakes.js";
@@ -68,9 +68,7 @@ describe("blockMarkdownlint", () => {
6868
],
6969
"files": {
7070
".markdownlint.json": "{"extends":"markdownlint/style/prettier","first-line-h1":false,"no-inline-html":false}",
71-
".markdownlintignore": ".github/CODE_OF_CONDUCT.md
72-
CHANGELOG.md
73-
node_modules/
71+
".markdownlintignore": "node_modules/
7472
",
7573
},
7674
"scripts": [
@@ -151,9 +149,7 @@ describe("blockMarkdownlint", () => {
151149
],
152150
"files": {
153151
".markdownlint.json": "{"extends":"markdownlint/style/prettier","first-line-h1":false,"no-inline-html":false}",
154-
".markdownlintignore": ".github/CODE_OF_CONDUCT.md
155-
CHANGELOG.md
156-
lib/
152+
".markdownlintignore": "lib/
157153
node_modules/
158154
",
159155
},
@@ -244,9 +240,7 @@ describe("blockMarkdownlint", () => {
244240
],
245241
"files": {
246242
".markdownlint.json": "{"extends":"markdownlint/style/prettier","first-line-h1":false,"no-inline-html":false}",
247-
".markdownlintignore": ".github/CODE_OF_CONDUCT.md
248-
CHANGELOG.md
249-
node_modules/
243+
".markdownlintignore": "node_modules/
250244
",
251245
},
252246
"scripts": [
@@ -260,4 +254,36 @@ describe("blockMarkdownlint", () => {
260254
}
261255
`);
262256
});
257+
258+
describe("intake", () => {
259+
it("returns undefined when .markdownlintignore does not exist", () => {
260+
const actual = testIntake(blockMarkdownlint, {
261+
files: {},
262+
});
263+
264+
expect(actual).toBeUndefined();
265+
});
266+
267+
it("returns no ignores when .markdownlintignore does not contain truthy lines", () => {
268+
const actual = testIntake(blockMarkdownlint, {
269+
files: {
270+
".markdownlintignore": ["\n"],
271+
},
272+
});
273+
274+
expect(actual).toEqual({ ignores: [] });
275+
});
276+
277+
it("returns ignores when .markdownlintignore contains lines", () => {
278+
const ignores = ["abc", "def"];
279+
280+
const actual = testIntake(blockMarkdownlint, {
281+
files: {
282+
".markdownlintignore": [ignores.join("\n") + "\n"],
283+
},
284+
});
285+
286+
expect(actual).toEqual({ ignores });
287+
});
288+
});
263289
});

Diff for: src/blocks/blockMarkdownlint.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { blockPackageJson } from "./blockPackageJson.js";
88
import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js";
99
import { blockVSCode } from "./blockVSCode.js";
1010
import { formatIgnoreFile } from "./files/formatIgnoreFile.js";
11+
import { intakeFile } from "./intake/intakeFile.js";
1112
import { CommandPhase } from "./phases.js";
1213

1314
export const blockMarkdownlint = base.createBlock({
@@ -17,6 +18,17 @@ export const blockMarkdownlint = base.createBlock({
1718
addons: {
1819
ignores: z.array(z.string()).default([]),
1920
},
21+
intake({ files }) {
22+
const markdownlintignoreRaw = intakeFile(files, [".markdownlintignore"]);
23+
24+
if (!markdownlintignoreRaw) {
25+
return undefined;
26+
}
27+
28+
return {
29+
ignores: markdownlintignoreRaw[0].split("\n").filter(Boolean),
30+
};
31+
},
2032
produce({ addons }) {
2133
const { ignores } = addons;
2234

@@ -65,12 +77,7 @@ export const blockMarkdownlint = base.createBlock({
6577
"no-inline-html": false,
6678
}),
6779
".markdownlintignore": formatIgnoreFile(
68-
[
69-
".github/CODE_OF_CONDUCT.md",
70-
"CHANGELOG.md",
71-
"node_modules/",
72-
...ignores,
73-
].sort(),
80+
Array.from(new Set(["node_modules/", ...ignores])).sort(),
7481
),
7582
},
7683
scripts: [

Diff for: src/blocks/blockReleaseIt.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ describe("blockReleaseIt", () => {
1111
expect(creation).toMatchInlineSnapshot(`
1212
{
1313
"addons": [
14+
{
15+
"addons": {
16+
"ignores": [
17+
"CHANGELOG.md",
18+
],
19+
},
20+
"block": [Function],
21+
},
1422
{
1523
"addons": {
1624
"properties": {
@@ -159,6 +167,14 @@ describe("blockReleaseIt", () => {
159167
expect(creation).toMatchInlineSnapshot(`
160168
{
161169
"addons": [
170+
{
171+
"addons": {
172+
"ignores": [
173+
"CHANGELOG.md",
174+
],
175+
},
176+
"block": [Function],
177+
},
162178
{
163179
"addons": {
164180
"properties": {

Diff for: src/blocks/blockReleaseIt.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { z } from "zod";
33
import { base } from "../base.js";
44
import { getPackageDependencies } from "../data/packageData.js";
55
import { resolveUses } from "./actions/resolveUses.js";
6+
import { blockMarkdownlint } from "./blockMarkdownlint.js";
67
import { blockPackageJson } from "./blockPackageJson.js";
78
import { blockREADME } from "./blockREADME.js";
89
import { blockRepositorySecrets } from "./blockRepositorySecrets.js";
@@ -27,6 +28,9 @@ export const blockReleaseIt = base.createBlock({
2728

2829
return {
2930
addons: [
31+
blockMarkdownlint({
32+
ignores: ["CHANGELOG.md"],
33+
}),
3034
blockPackageJson({
3135
properties: {
3236
devDependencies: getPackageDependencies(

0 commit comments

Comments
 (0)