Skip to content

Commit

Permalink
Ignore .gitignored files (#14731)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 4, 2023
1 parent dcc081d commit b86e42c
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 121 deletions.
8 changes: 8 additions & 0 deletions changelog_unreleased/cli/14731.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#### [Breaking] Ignore `.gitignore`d files by default (#14731 by @fisker)

Prettier ignores files ignored by `.gitignore` by default.
If you want the old behavior(only ignore files ignored by `.prettierignore`), use

```console
prettier . --write --ignore-path=.prettierignore
```
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"concat",
"concating",
"cond",
"customignore",
"daleroy",
"danez",
"Dara",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ module.exports = {
return;
}

// wrapped
// `const runCliWithoutGitignore = () => runCli()`
// `const runCliWithoutGitignore = () => { return runCli() }`
if (
(parent.type === "ArrowFunctionExpression" &&
parent.body === callExpression) ||
(parent.type === "ReturnStatement" &&
parent.argument === callExpression)
) {
return;
}

if (
parent.type === "MemberExpression" &&
parent.object === callExpression &&
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli-options.evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const options = {
ignorePath: {
array: true,
category: optionCategories.CATEGORY_CONFIG,
default: [{ value: [".prettierignore"] }],
default: [{ value: [".gitignore", ".prettierignore"] }],
description: outdent`
Path to a file with patterns describing files to ignore.
Multiple values are accepted.
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/__tests__/__snapshots__/early-exit.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Config options:
Find and print the path to a configuration file for the given input file.
--ignore-path <path> Path to a file with patterns describing files to ignore.
Multiple values are accepted.
Defaults to [.prettierignore].
Defaults to [.gitignore, .prettierignore].
--plugin <path> Add a plugin. Multiple plugins can be passed as separate \`--plugin\`s.
Defaults to [].
--plugin-search-dir <path>
Expand Down Expand Up @@ -283,7 +283,7 @@ Config options:
Find and print the path to a configuration file for the given input file.
--ignore-path <path> Path to a file with patterns describing files to ignore.
Multiple values are accepted.
Defaults to [.prettierignore].
Defaults to [.gitignore, .prettierignore].
--plugin <path> Add a plugin. Multiple plugins can be passed as separate \`--plugin\`s.
Defaults to [].
--plugin-search-dir <path>
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/__tests__/__snapshots__/file-info.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ exports[`extracts file-info with ignored=true for a file in .prettierignore (std

exports[`extracts file-info with ignored=true for a file in .prettierignore (write) 1`] = `[]`;

exports[`extracts file-info with ignored=true for a file in a hand-picked .prettierignore (stderr) 1`] = `""`;
exports[`extracts file-info with ignored=true for a file in a hand-picked ignore file (stderr) 1`] = `""`;

exports[`extracts file-info with ignored=true for a file in a hand-picked .prettierignore (stdout) 1`] = `
exports[`extracts file-info with ignored=true for a file in a hand-picked ignore file (stdout) 1`] = `
"{ "ignored": true, "inferredParser": null }
"
`;

exports[`extracts file-info with ignored=true for a file in a hand-picked .prettierignore (write) 1`] = `[]`;
exports[`extracts file-info with ignored=true for a file in a hand-picked ignore file (write) 1`] = `[]`;

exports[`extracts file-info with inferredParser=foo when a plugin is hand-picked (stderr) 1`] = `""`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ exports[`show detailed usage with --help ignore-path (stdout) 1`] = `
Path to a file with patterns describing files to ignore.
Multiple values are accepted.
Default: [.prettierignore]"
Default: [.gitignore, .prettierignore]"
`;
exports[`show detailed usage with --help ignore-path (write) 1`] = `[]`;
Expand Down
9 changes: 0 additions & 9 deletions tests/integration/__tests__/__snapshots__/ignore-path.js.snap

This file was deleted.

0 comments on commit b86e42c

Please sign in to comment.