Skip to content

Commit dd4fc29

Browse files
feat: populate existing cspell.json words during migration (#1208)
## PR Checklist - [x] Addresses an existing open issue: fixes #702 - [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 Runs `pnpm lint:spelling` and matches `Unknown word (...)` complaints. Also standardizes two things in code that were bugging me: * `node:fs/promises` imports as `import * as fs` * Using `formatJson` instead of manually `prettier.format` calls This finally means that the file creator for `cspell.json` no longer needs to prepopulate with a static list of words. So unnecessary ignored words will no longer be potentially introduced by that. Yay.
1 parent a21348a commit dd4fc29

24 files changed

+243
-123
lines changed

cspell.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22
"dictionaries": ["typescript"],
33
"ignorePaths": [
44
"./coverage*",
5+
"./script/__snapshots__",
56
".github",
67
"CHANGELOG.md",
78
"lib",
89
"node_modules",
9-
"pnpm-lock.yaml",
10-
"./script/__snapshots__"
10+
"pnpm-lock.yaml"
1111
],
1212
"words": [
1313
"allcontributors",
1414
"apexskier",
1515
"arethetypeswrong",
16-
"Codecov",
1716
"codespace",
18-
"commitlint",
1917
"contributorsrc",
20-
"conventionalcommits",
2118
"execa",
2219
"infile",
23-
"joshuakgoldberg",
2420
"knip",
25-
"lcov",
2621
"markdownlintignore",
2722
"mtfoley",
2823
"npmignore",
29-
"npmjs",
3024
"npmpackagejsonlintrc",
3125
"outro",
3226
"packagejson",
3327
"quickstart",
3428
"tada",
3529
"tsup",
36-
"Unstaged",
37-
"vitest",
38-
"wontfix"
30+
"vitest"
3931
]
4032
}

script/__snapshots__/migrate-test-e2e.js.snap

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -156,42 +156,30 @@ exports[`expected file changes > cspell.json 1`] = `
156156
"dictionaries": ["typescript"],
157157
"ignorePaths": [
158158
- "./coverage*",
159+
- "./script/__snapshots__",
159160
".github",
160161
"CHANGELOG.md",
161162
+ "coverage",
162163
"lib",
163164
"node_modules",
164-
- "pnpm-lock.yaml",
165-
- "./script/__snapshots__"
166-
+ "pnpm-lock.yaml"
167-
],
168-
"words": [
169-
- "allcontributors",
170-
- "apexskier",
171-
- "arethetypeswrong",
172-
"Codecov",
173-
"codespace",
174-
"commitlint",
165+
"pnpm-lock.yaml"
166+
@@ ... @@
175167
"contributorsrc",
176-
"conventionalcommits",
177-
- "execa",
178-
- "infile",
179-
- "joshuakgoldberg",
168+
"execa",
169+
"infile",
170+
+ "joshuakgoldberg",
180171
"knip",
181-
"lcov",
172+
+ "markdownlint",
182173
"markdownlintignore",
183-
- "mtfoley",
184-
- "npmignore",
185-
- "npmjs",
186-
"npmpackagejsonlintrc",
187-
"outro",
188-
"packagejson",
174+
"mtfoley",
175+
"npmignore",
176+
@@ ... @@
189177
"quickstart",
190-
- "tada",
178+
"tada",
191179
"tsup",
192-
- "Unstaged",
193-
- "vitest",
194-
"wontfix"
180+
- "vitest"
181+
+ "vitest",
182+
+ "wontfix"
195183
]
196184
}"
197185
`;

script/initialize-test-e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { $ } from "execa";
22
import { globby } from "globby";
33
import { strict as assert } from "node:assert";
4-
import fs from "node:fs/promises";
4+
import * as fs from "node:fs/promises";
55

66
const description = "New Description Test";
77
const owner = "RNR1";

script/migrate-test-e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import chalk from "chalk";
22
import { $, execaCommand } from "execa";
3-
import fs from "node:fs/promises";
3+
import * as fs from "node:fs/promises";
44
import { assert, describe, expect, test } from "vitest";
55

66
import packageData from "../package.json" assert { type: "json" };

src/create/createWithOptions.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Options } from "../shared/types.js";
77
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
88
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
99
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
10+
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
1011
import { runCommands } from "../steps/runCommands.js";
1112
import { createWithOptions } from "./createWithOptions.js";
1213

@@ -60,6 +61,8 @@ vi.mock("../steps/writeReadme/index.js");
6061

6162
vi.mock("../steps/finalizeDependencies.js");
6263

64+
vi.mock("../steps/populateCSpellDictionary.js");
65+
6366
vi.mock("../steps/runCommands.js");
6467

6568
vi.mock("../shared/doesRepositoryExist.js", () => ({
@@ -111,18 +114,19 @@ describe("createWithOptions", () => {
111114
expect(addToolAllContributors).not.toHaveBeenCalled();
112115
});
113116

114-
it("does not call finalizeDependencies or runCommands when skipInstall is true", async () => {
117+
it("does not call finalizeDependencies, populateCSpellDictionary, or runCommands when skipInstall is true", async () => {
115118
const options = {
116119
...optionsBase,
117120
skipInstall: true,
118121
};
119122

120123
await createWithOptions({ github, options });
121124
expect(finalizeDependencies).not.toHaveBeenCalled();
125+
expect(populateCSpellDictionary).not.toHaveBeenCalled();
122126
expect(runCommands).not.toHaveBeenCalled();
123127
});
124128

125-
it("calls finalizeDependencies and runCommands when skipInstall is false", async () => {
129+
it("calls finalizeDependencies, populateCSpellDictionary, and runCommands when skipInstall is false", async () => {
126130
const options = {
127131
...optionsBase,
128132
skipInstall: false,
@@ -131,6 +135,7 @@ describe("createWithOptions", () => {
131135
await createWithOptions({ github, options });
132136

133137
expect(finalizeDependencies).toHaveBeenCalledWith(options);
138+
expect(populateCSpellDictionary).toHaveBeenCalled();
134139
expect(runCommands).toHaveBeenCalled();
135140
});
136141

src/create/createWithOptions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GitHubAndOptions } from "../shared/options/readOptions.js";
77
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
88
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
99
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
10+
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
1011
import { runCommands } from "../steps/runCommands.js";
1112
import { writeReadme } from "../steps/writeReadme/index.js";
1213
import { writeStructure } from "../steps/writing/writeStructure.js";
@@ -38,6 +39,13 @@ export async function createWithOptions({ github, options }: GitHubAndOptions) {
3839
finalizeDependencies(options),
3940
);
4041

42+
if (!options.excludeLintSpelling) {
43+
await withSpinner(
44+
"Populating CSpell dictionary",
45+
populateCSpellDictionary,
46+
);
47+
}
48+
4149
await runCommands(
4250
"Cleaning up files",
4351
createCleanUpFilesCommands({

src/migrate/migrateWithOptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { clearUnnecessaryFiles } from "../steps/clearUnnecessaryFiles.js";
55
import { detectExistingContributors } from "../steps/detectExistingContributors.js";
66
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
77
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
8+
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
89
import { runCommands } from "../steps/runCommands.js";
910
import { updateAllContributorsTable } from "../steps/updateAllContributorsTable.js";
1011
import { updateLocalFiles } from "../steps/updateLocalFiles.js";
@@ -61,6 +62,10 @@ export async function migrateWithOptions({
6162
);
6263
}
6364

65+
if (!options.excludeLintSpelling) {
66+
await withSpinner("Populating CSpell dictionary", populateCSpellDictionary);
67+
}
68+
6469
await runCommands(
6570
"Cleaning up files",
6671
createCleanUpFilesCommands({

src/shared/options/createOptionDefaults/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { $ } from "execa";
22
import gitRemoteOriginUrl from "git-remote-origin-url";
33
import gitUrlParse from "git-url-parse";
44
import lazyValue from "lazy-value";
5-
import fs from "node:fs/promises";
5+
import * as fs from "node:fs/promises";
66
import npmUser from "npm-user";
77

88
import { readPackageData } from "../../packages.js";

src/shared/readFileSafe.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import { readFileSafe } from "./readFileSafe.js";
55
const mockReadFile = vi.fn();
66

77
vi.mock("node:fs/promises", () => ({
8-
get default() {
9-
return {
10-
get readFile() {
11-
return mockReadFile;
12-
},
13-
};
8+
get readFile() {
9+
return mockReadFile;
1410
},
1511
}));
1612

src/shared/readFileSafe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from "node:fs/promises";
1+
import * as fs from "node:fs/promises";
22

33
export async function readFileSafe(filePath: URL | string, fallback: string) {
44
try {

0 commit comments

Comments
 (0)