Skip to content

Replace outdated Prettier settings with recommended ones#43756

Closed
gaearon wants to merge 2 commits intofacebook:mainfrom
gaearon:patch-3
Closed

Replace outdated Prettier settings with recommended ones#43756
gaearon wants to merge 2 commits intofacebook:mainfrom
gaearon:patch-3

Conversation

@gaearon
Copy link
Copy Markdown
Collaborator

@gaearon gaearon commented Apr 2, 2024

Summary:

The React Native ESLint preset currently endorses the Prettier integration that is explicitly recommended against by Pretier itself. Notice the difference between these two packages:

  • eslint-config-prettier is the config that turns off all formatting rules. It's recommended by Prettier to be used together with Prettier. You'd still use Prettier itself to actually do the formatting.
  • eslint-plugin-prettier is a legacy plugin developed a long time ago and that predates most modern Prettier integrations. It runs Prettier as if it were an ESLint rule, applies formatting on --fix, and is not recommended.

Unfortunately, RN uses the latter one (and always has).

This PR removes eslint-plugin-prettier and instead enables eslint-config-prettier, as recommended by Prettier.

As a consequence, you'll no longer see squiggly lines in your editor for stuff that isn't actually errors:

Screenshot 2024-04-01 at 20 00 50

As another consequence, you'll have to set up your own Prettier step in your pipeline.

For example, if your precommit hook only contained eslint --fix, you'll now also need to run prettier --write there as well. Similarly, if you want Prettier to fail CI, you'd need to find where you call eslint and also do prettier --check there.

Here's an example for how to do it: bluesky-social/social-app#3373

Changelog:

[GENERAL] [BREAKING] - RN ESLint config no longer runs Prettier during ESLint

Test Plan:

Tested locally, verified formatting changes no longer get flagged as violations by the RN config.

Screenshot 2024-04-01 at 20 33 55

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 2, 2024
@berdyshev
Copy link
Copy Markdown

duplicate of #41877?

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@yungsters has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

},

extends: ['plugin:prettier/recommended'],
extends: ['prettier'],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/prettier/eslint-config-prettier/blob/5687e7de69ac132f053b4bc5474d5963aa3bf6d6/README.md#L7

Note that this config only turns rules off, so it only makes sense using it together with some other config.

Suggested change
extends: ['prettier'],

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that people probably rely on it being turned off. So without this, the upgrade path might be too annoying / non-obvious. I think we can remove it separately later.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like I’m missing something. In what situation does it help to have extends: ['prettier'] here? Remember that rules win over extends.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption is that developers are using this along with recommended configs (e.g. the ones included with ESLint), so this would disable those rules.

If someone has a project in which they explicitly enable rules that are disabled by eslint-config-prettier, then yes… this would not overrule that.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@yungsters merged this pull request in 727f30b.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Apr 4, 2024
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 4, 2024

This pull request was successfully merged by @gaearon in 727f30b.

When will my fix make it into a release? | How to file a pick request?

paulschreiber added a commit to techmatters/terraso-mobile-client that referenced this pull request Sep 9, 2024
react native config no long runs prettier as part of eslint
facebook/react-native#43756

We now run prettier on its own
paulschreiber added a commit to techmatters/terraso-mobile-client that referenced this pull request Sep 9, 2024
* build: add prettier as a separate command

react native config no long runs prettier as part of eslint
facebook/react-native#43756

We now run prettier on its own

* style: format code
johannesparty pushed a commit to techmatters/terraso-mobile-client that referenced this pull request Oct 22, 2025
* build: add prettier as a separate command

react native config no long runs prettier as part of eslint
facebook/react-native#43756

We now run prettier on its own

* style: format code
blancham pushed a commit to kraaft-co/eslint-config-react-native that referenced this pull request Jan 13, 2026
Summary:
The React Native ESLint preset currently endorses the Prettier integration that is [explicitly recommended against by Pretier itself](https://prettier.io/docs/en/integrating-with-linters). Notice the difference between these two packages:

- `eslint-config-prettier` is the config that turns off all formatting rules. It's **recommended by Prettier** to be used together with Prettier. You'd still use Prettier itself to actually do the formatting.
- `eslint-plugin-prettier` is a legacy plugin developed a long time ago and that predates most modern Prettier integrations. It runs Prettier as if it were an ESLint rule, applies formatting on `--fix`, and **is not recommended**.

Unfortunately, RN uses the latter one (and always has).

This PR removes `eslint-plugin-prettier` and instead enables `eslint-config-prettier`, as recommended by Prettier.

As a consequence, you'll no longer see squiggly lines in your editor for stuff that isn't actually errors:

<img width="558" alt="Screenshot 2024-04-01 at 20 00 50" src="https://github.com/facebook/react-native/assets/810438/91ae2cec-a9ef-4205-a9ce-6ab858785ed2">

As another consequence, **you'll have to set up your own Prettier step in your pipeline**.

For example, if your precommit hook only contained `eslint --fix`, you'll now also need to run `prettier --write` there as well. Similarly, if you want Prettier to fail CI, you'd need to find where you call `eslint` and also do `prettier --check` there.

Here's an example for how to do it: bluesky-social/social-app#3373

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[GENERAL] [BREAKING] - RN ESLint config no longer runs Prettier during ESLint

Pull Request resolved: facebook/react-native#43756

Test Plan:
Tested locally, verified formatting changes no longer get flagged as violations by the RN config.

<img width="470" alt="Screenshot 2024-04-01 at 20 33 55" src="https://github.com/facebook/react-native/assets/810438/515db971-18bc-4625-bb6d-b9d072692923">

Reviewed By: motiz88

Differential Revision: D55643699

Pulled By: yungsters

fbshipit-source-id: 97df774275922086f0356ac857d6425713184e39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants