From 9e1c008932adb76cd71c53dd49f9aa1bb25dcd2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Tue, 26 Nov 2024 15:06:42 -0500 Subject: [PATCH] fix: use root-level slashes in .gitignore and .prettierignore (#1696) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## PR Checklist - [x] Addresses an existing open issue: fixes #1693 - [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 Per https://git-scm.com/docs/gitignore#_pattern_format, uses preceding `/` slashes to indicate directories and files that should only be matched at the root. Which is all of them. The Git docs also noted that a trailing `/` makes the pattern only match directories. Since these are known directory names that won't be swapped with files accidentally, I took out any trailing `/`s to keep the files as small as possible. Aside: Per https://lore.kernel.org/git/pull.1720.git.git.1715705582609.gitgitgadget@gmail.com, I'm pretty sure the Git docs have a small typo. But per https://lore.kernel.org/git/xmqqseyk2hce.fsf@gitster.g I don't know that it'll get resolved soon. 💖 --- .gitignore | 6 +++--- .prettierignore | 10 +++++----- script/__snapshots__/migrate-test-e2e.ts.snap | 20 +++++++++---------- .../creation/createDotGitignore.test.ts | 10 +++++----- .../writing/creation/createDotGitignore.ts | 6 +++--- src/steps/writing/creation/rootFiles.ts | 10 +++++----- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 32ffbca94..cd60c28d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -coverage*/ -lib/ -node_modules/ +/coverage* +/lib +/node_modules diff --git a/.prettierignore b/.prettierignore index 608dd8d91..40d32561f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,5 @@ -.all-contributorsrc -.husky/ -coverage*/ -lib/ -pnpm-lock.yaml +/.all-contributorsrc +/.husky +/coverage* +/lib +/pnpm-lock.yaml diff --git a/script/__snapshots__/migrate-test-e2e.ts.snap b/script/__snapshots__/migrate-test-e2e.ts.snap index af25592f4..83eeb3dde 100644 --- a/script/__snapshots__/migrate-test-e2e.ts.snap +++ b/script/__snapshots__/migrate-test-e2e.ts.snap @@ -31,22 +31,22 @@ exports[`expected file changes > .gitignore 1`] = ` "--- a/.gitignore +++ b/.gitignore @@ ... @@ --coverage*/ -+coverage/ - lib/ - node_modules/" +-/coverage* ++/coverage + /lib + /node_modules" `; exports[`expected file changes > .prettierignore 1`] = ` "--- a/.prettierignore +++ b/.prettierignore @@ ... @@ - .all-contributorsrc - .husky/ --coverage*/ -+coverage/ - lib/ - pnpm-lock.yaml" + /.all-contributorsrc + /.husky +-/coverage* ++/coverage + /lib + /pnpm-lock.yaml" `; exports[`expected file changes > README.md 1`] = ` diff --git a/src/steps/writing/creation/createDotGitignore.test.ts b/src/steps/writing/creation/createDotGitignore.test.ts index c887e4b66..1ce565fe1 100644 --- a/src/steps/writing/creation/createDotGitignore.test.ts +++ b/src/steps/writing/creation/createDotGitignore.test.ts @@ -7,9 +7,9 @@ describe("createDotGitignore", () => { const actual = createDotGitignore({ excludeTests: false }); expect(actual).toMatchInlineSnapshot(` - "coverage/ - lib/ - node_modules/ + "/coverage + /lib + /node_modules " `); }); @@ -18,8 +18,8 @@ describe("createDotGitignore", () => { const actual = createDotGitignore({ excludeTests: true }); expect(actual).toMatchInlineSnapshot(` - "lib/ - node_modules/ + "/lib + /node_modules " `); }); diff --git a/src/steps/writing/creation/createDotGitignore.ts b/src/steps/writing/creation/createDotGitignore.ts index 3321ba826..e0cd5ed67 100644 --- a/src/steps/writing/creation/createDotGitignore.ts +++ b/src/steps/writing/creation/createDotGitignore.ts @@ -3,8 +3,8 @@ import { formatIgnoreFile } from "./formatters/formatIgnoreFile.js"; export function createDotGitignore(options: Pick) { return formatIgnoreFile([ - ...(options.excludeTests ? [] : ["coverage/"]), - "lib/", - "node_modules/", + ...(options.excludeTests ? [] : ["/coverage"]), + "/lib", + "/node_modules", ]); } diff --git a/src/steps/writing/creation/rootFiles.ts b/src/steps/writing/creation/rootFiles.ts index fd0ab23e6..e86b0f380 100644 --- a/src/steps/writing/creation/rootFiles.ts +++ b/src/steps/writing/creation/rootFiles.ts @@ -27,11 +27,11 @@ export async function createRootFiles(options: Options) { }), ".nvmrc": `20.12.2\n`, ".prettierignore": formatIgnoreFile([ - ...(options.excludeAllContributors ? [] : [".all-contributorsrc"]), - ".husky/", - ...(options.excludeTests ? [] : ["coverage/"]), - "lib/", - "pnpm-lock.yaml", + ...(options.excludeAllContributors ? [] : ["/.all-contributorsrc"]), + "/.husky", + ...(options.excludeTests ? [] : ["/coverage"]), + "/lib", + "/pnpm-lock.yaml", ]), ".prettierrc.json": await formatJson({ $schema: "http://json.schemastore.org/prettierrc",