Skip to content

Commit

Permalink
fix: use root-level slashes in .gitignore and .prettierignore (#1696)
Browse files Browse the repository at this point in the history
## 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/[email protected],
I'm pretty sure the Git docs have a small typo. But per
https://lore.kernel.org/git/[email protected] I don't know that
it'll get resolved soon.

💖
  • Loading branch information
JoshuaKGoldberg authored Nov 26, 2024
1 parent 722f045 commit 9e1c008
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
coverage*/
lib/
node_modules/
/coverage*
/lib
/node_modules
10 changes: 5 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.all-contributorsrc
.husky/
coverage*/
lib/
pnpm-lock.yaml
/.all-contributorsrc
/.husky
/coverage*
/lib
/pnpm-lock.yaml
20 changes: 10 additions & 10 deletions script/__snapshots__/migrate-test-e2e.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand Down
10 changes: 5 additions & 5 deletions src/steps/writing/creation/createDotGitignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ describe("createDotGitignore", () => {
const actual = createDotGitignore({ excludeTests: false });

expect(actual).toMatchInlineSnapshot(`
"coverage/
lib/
node_modules/
"/coverage
/lib
/node_modules
"
`);
});
Expand All @@ -18,8 +18,8 @@ describe("createDotGitignore", () => {
const actual = createDotGitignore({ excludeTests: true });

expect(actual).toMatchInlineSnapshot(`
"lib/
node_modules/
"/lib
/node_modules
"
`);
});
Expand Down
6 changes: 3 additions & 3 deletions src/steps/writing/creation/createDotGitignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { formatIgnoreFile } from "./formatters/formatIgnoreFile.js";

export function createDotGitignore(options: Pick<Options, "excludeTests">) {
return formatIgnoreFile([
...(options.excludeTests ? [] : ["coverage/"]),
"lib/",
"node_modules/",
...(options.excludeTests ? [] : ["/coverage"]),
"/lib",
"/node_modules",
]);
}
10 changes: 5 additions & 5 deletions src/steps/writing/creation/rootFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9e1c008

Please sign in to comment.