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

chore: add .prettierignore #5262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chancancode
Copy link
Contributor

@chancancode chancancode commented Dec 13, 2024

Which problem is this PR solving?

The issue I'm trying to address is that prettier as a tool covers a wide variety of file formats beyond JavaScript, including JSON, YAML markdown, and more. When using an editor that comes with prettier integration (such as VSCode + the prettier extension), it will see that the project uses prettier, but it doesn't know the project only uses it via ESLint. Thus, when saving a file not currently covered by our set up, such as CHANGELOG.md, it may attempt to re-format the file according to prettier's conventions, causing unnecessary diffs that then need to be reverted.

Short description of the changes

This solves the issue by adding a .prettierignore file that tries to ignore everything that isn't intended to be formatted. This is obtained by trial-and-error, until running npx prettier -w . no longer result in any changes.

Context

Currently, this project uses prettier to enforce consistent formatting, but only via the eslint-plugin-prettier integration, which only covers *.js and *.ts files in sub-packages with ESLint setup.

Notably, this setup is not recommended by the prettier project. The recommended setup is to use prettier as a standalone tool, and use eslint-plugin-config to disable any conflicting rules.

In my experience that does result in a better development experience and this is worth revisiting in the future. However, this PR doesn't aim to change that at this moment.

Most of the changes that prettier would have made are actually quite minor, and IMO good. If there is appetite in revisiting the prettier setup and commiting those changes, I am happy to propose that in a different PR.

Type of change

Please delete options that are not relevant.

  • Internal chore
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • npx prettier -w .

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@chancancode chancancode requested a review from a team as a code owner December 13, 2024 03:01
@chancancode chancancode force-pushed the prettierignore branch 2 times, most recently from 4a17ddb to ca9de44 Compare December 18, 2024 01:10
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.64%. Comparing base (8dc74e6) to head (7de0393).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5262      +/-   ##
==========================================
+ Coverage   94.63%   94.64%   +0.01%     
==========================================
  Files         323      323              
  Lines        8083     8083              
  Branches     1643     1643              
==========================================
+ Hits         7649     7650       +1     
+ Misses        434      433       -1     

see 1 file with indirect coverage changes

@chancancode
Copy link
Contributor Author

rebased

Currently, this project uses `prettier` to enforce consistent
formatting, but only via the `eslint-plugin-prettier` integration,
which only covers `*.js` and `*.ts` files in sub-packages with
ESLint setup.

Notably, this setup is [not recommended by the prettier project][1].
The recommended setup is to use prettier as a standalone tool, and
use `eslint-plugin-config` to disable any conflicting rules.

In my experience that does result in a better development experience
and this is worth revisiting in the future. However, this PR doesn't
aim to change that at this moment.

The issue I'm trying to address is that prettier as a tool covers a
wide variety of file formats beyond JavaScript, including JSON, YAML
markdown, and more. When using an editor that comes with prettier
integration (such as VSCode + the prettier extension), it will see
that the project uses prettier, but it doesn't know the project only
uses it via ESLint. Thus, when saving a file not currently covered
by our set up, such as CHANGELOG.md, it may attempt to re-format the
file according to prettier's conventions, causing unnecessary diffs
that then need to be reverted.

This solves the issue by adding a `.prettierignore` file that tries
to ignore everything that isn't intended to be formatted. This is
obtained by trial-and-error, until running `npx prettier -w .` no
longer result in any changes.

Most of the changes that prettier would have made are actually
quite minor, and IMO good. If there is appetite in revisiting the
prettier setup and commiting those changes, I am happy to propose
that in a different PR.

[1]: https://prettier.io/docs/en/integrating-with-linters#notes
@chancancode
Copy link
Contributor Author

Oops, guess I rebased against the wrong branch the first time, should be fixed now, and ran npx prettier -w . against the latest code on main to confirm it still had the intended effect (i.e. no diff)

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

Successfully merging this pull request may close these issues.

2 participants