Skip to content
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

feat: add ignores on .prettierrc files and package.json #16286

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

devjiwonchoi
Copy link

@devjiwonchoi devjiwonchoi commented May 13, 2024

Description

This PR added support for the ignores field in the prettier configs and the --ignore-pattern flag.

Why it took so long…

Prettier reads the config based on the current file to format as O(n).

The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’t) found.

Therefore it is reasonable to reduce the number of files to handle by ignoring them firsthand.

This is why it was tough to support this feature, since we had to get the list to ignore before going through the files.

So how?

Since we can cache the process of loading the config, this PR simply added a step of reading and caching the config to retrieve the proper ignore list before further operations.

To reduce the I/O as described above, we initially check for the config based on the process.cwd, which would be the most case.

Usage Examples

.prettierrc.js

module.exports = { ignores: [ 'dist'] }

package.json

{ "prettier": { "ignores": ["dist"] } }

--ignore-pattern

Allows multiple values like plugin and ignore-path

prettier --ignore-pattern dist

Closes #3460

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@devjiwonchoi devjiwonchoi marked this pull request as ready for review May 14, 2024 18:08
@devjiwonchoi
Copy link
Author

devjiwonchoi commented May 14, 2024

I'd like some feedback before moving on to the docs.

Key points:

  • The option is ignores, not ignorePatterns as discussed before. The keyword came from ESLint v9.
  • The purpose of --ignore-pattern conflicts with the current glob-based value. Expecting no side-effect, so I'm thinking of leaving it out as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prettierIgnore key in package.json?
1 participant