Skip to content

feat: add ignores Addon for blockMarkdownlint #2193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
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
2 changes: 1 addition & 1 deletion src/blocks/blockCSpell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ describe("blockCSpell", () => {
expect(actual).toBeUndefined();
});

it("returns compilerOptions when cspell.json contains ignorePaths and words", () => {
it("returns the data when cspell.json contains ignorePaths and words", () => {
const data = {
ignorePaths: ["other"],
words: ["abc", "def"],
Expand Down
16 changes: 16 additions & 0 deletions src/blocks/blockContributorCovenant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ describe("blockContributorCovenant", () => {
expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"ignores": [
".github/CODE_OF_CONDUCT.md",
],
},
"block": [Function],
},
{
"addons": {
"badges": [
Expand Down Expand Up @@ -176,6 +184,14 @@ describe("blockContributorCovenant", () => {
expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"ignores": [
".github/CODE_OF_CONDUCT.md",
],
},
"block": [Function],
},
{
"addons": {
"badges": [
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/blockContributorCovenant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { base } from "../base.js";
import { blockMarkdownlint } from "./blockMarkdownlint.js";
import { blockREADME } from "./blockREADME.js";
import { blockRemoveFiles } from "./blockRemoveFiles.js";

Expand All @@ -9,6 +10,9 @@ export const blockContributorCovenant = base.createBlock({
produce({ options }) {
return {
addons: [
blockMarkdownlint({
ignores: [".github/CODE_OF_CONDUCT.md"],
}),
blockREADME({
badges: [
{
Expand Down
48 changes: 37 additions & 11 deletions src/blocks/blockMarkdownlint.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testBlock } from "bingo-stratum-testers";
import { describe, expect, test } from "vitest";
import { testBlock, testIntake } from "bingo-stratum-testers";
import { describe, expect, it, test } from "vitest";

import { blockMarkdownlint } from "./blockMarkdownlint.js";
import { optionsBase } from "./options.fakes.js";
Expand Down Expand Up @@ -68,9 +68,7 @@ describe("blockMarkdownlint", () => {
],
"files": {
".markdownlint.json": "{"extends":"markdownlint/style/prettier","first-line-h1":false,"no-inline-html":false}",
".markdownlintignore": ".github/CODE_OF_CONDUCT.md
CHANGELOG.md
node_modules/
".markdownlintignore": "node_modules/
",
},
"scripts": [
Expand Down Expand Up @@ -151,9 +149,7 @@ describe("blockMarkdownlint", () => {
],
"files": {
".markdownlint.json": "{"extends":"markdownlint/style/prettier","first-line-h1":false,"no-inline-html":false}",
".markdownlintignore": ".github/CODE_OF_CONDUCT.md
CHANGELOG.md
lib/
".markdownlintignore": "lib/
node_modules/
",
},
Expand Down Expand Up @@ -244,9 +240,7 @@ describe("blockMarkdownlint", () => {
],
"files": {
".markdownlint.json": "{"extends":"markdownlint/style/prettier","first-line-h1":false,"no-inline-html":false}",
".markdownlintignore": ".github/CODE_OF_CONDUCT.md
CHANGELOG.md
node_modules/
".markdownlintignore": "node_modules/
",
},
"scripts": [
Expand All @@ -260,4 +254,36 @@ describe("blockMarkdownlint", () => {
}
`);
});

describe("intake", () => {
it("returns undefined when .markdownlintignore does not exist", () => {
const actual = testIntake(blockMarkdownlint, {
files: {},
});

expect(actual).toBeUndefined();
});

it("returns no ignores when .markdownlintignore does not contain truthy lines", () => {
const actual = testIntake(blockMarkdownlint, {
files: {
".markdownlintignore": ["\n"],
},
});

expect(actual).toEqual({ ignores: [] });
});

it("returns ignores when .markdownlintignore contains lines", () => {
const ignores = ["abc", "def"];

const actual = testIntake(blockMarkdownlint, {
files: {
".markdownlintignore": [ignores.join("\n") + "\n"],
},
});

expect(actual).toEqual({ ignores });
});
});
});
19 changes: 13 additions & 6 deletions src/blocks/blockMarkdownlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { blockPackageJson } from "./blockPackageJson.js";
import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js";
import { blockVSCode } from "./blockVSCode.js";
import { formatIgnoreFile } from "./files/formatIgnoreFile.js";
import { intakeFile } from "./intake/intakeFile.js";
import { CommandPhase } from "./phases.js";

export const blockMarkdownlint = base.createBlock({
Expand All @@ -17,6 +18,17 @@ export const blockMarkdownlint = base.createBlock({
addons: {
ignores: z.array(z.string()).default([]),
},
intake({ files }) {
const markdownlintignoreRaw = intakeFile(files, [".markdownlintignore"]);

if (!markdownlintignoreRaw) {
return undefined;
}

return {
ignores: markdownlintignoreRaw[0].split("\n").filter(Boolean),
};
},
produce({ addons }) {
const { ignores } = addons;

Expand Down Expand Up @@ -65,12 +77,7 @@ export const blockMarkdownlint = base.createBlock({
"no-inline-html": false,
}),
".markdownlintignore": formatIgnoreFile(
[
".github/CODE_OF_CONDUCT.md",
"CHANGELOG.md",
"node_modules/",
...ignores,
].sort(),
Array.from(new Set(["node_modules/", ...ignores])).sort(),
),
},
scripts: [
Expand Down
16 changes: 16 additions & 0 deletions src/blocks/blockReleaseIt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ describe("blockReleaseIt", () => {
expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"ignores": [
"CHANGELOG.md",
],
},
"block": [Function],
},
{
"addons": {
"properties": {
Expand Down Expand Up @@ -159,6 +167,14 @@ describe("blockReleaseIt", () => {
expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"ignores": [
"CHANGELOG.md",
],
},
"block": [Function],
},
{
"addons": {
"properties": {
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/blockReleaseIt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";
import { base } from "../base.js";
import { getPackageDependencies } from "../data/packageData.js";
import { resolveUses } from "./actions/resolveUses.js";
import { blockMarkdownlint } from "./blockMarkdownlint.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockREADME } from "./blockREADME.js";
import { blockRepositorySecrets } from "./blockRepositorySecrets.js";
Expand All @@ -27,6 +28,9 @@ export const blockReleaseIt = base.createBlock({

return {
addons: [
blockMarkdownlint({
ignores: ["CHANGELOG.md"],
}),
blockPackageJson({
properties: {
devDependencies: getPackageDependencies(
Expand Down