This repository has been archived by the owner on Apr 18, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on WebDevStudios/js-coding-standards#2, the goal is to let Prettier deal with formatting.
While ESLint can also be a formatter, the scope is limited to JavaScript. Prettier on the other hand, can format just about everything, except PHP.
Also, in my opinion, WDS should revaluate how we're doing JS, Sass, and CSS coding standards and use Gutenberg and their sharable configs as the baseline.
Table of contents
Description
@wordpress/scripts based projects
As of two weeks ago, both Gutenberg and @wordpress/scripts support Prettier. There's also a sharable config.
If WDS has a project using
@wordpress/scripts
, we can create a.prettierrc.js
file in the project root with the following:Adding this file to a project, will override our own coding standards.
Non-@wordpress/scripts Projects
For non-@wordpress/scripts based on projects, we can rely on this PR.
Based on Prettier's documentation as well as the
eslint-config-prettier
docs, this PR adds support for Prettier by:eslint-config-prettier
dependencyLearn more about configuration: https://github.com/prettier/eslint-config-prettier#example-configuration
Configure Code Editor
In your favorite code editor, make sure you have an ESLint, Prettier, and EditorConfig extensions installed and turned on. For example, here are the settings for VS Code:
Inform the Code Editor
Every WDS project should have an
.editorconfig
. This is the most basic way to ensure all our code editors are on the same page. Prettier looks for.editorconfig
as a possible config file.Here are the config files Prettier looks for, in order:
.prettierrc
or.prettierrc.js
.editorconfig
This is the recommended
.editorconfig
configuration directly from WordPress.Verify ESLint and Prettier Rules
The
eslint-config-prettier
package comes with CLI utility to verify that both ESLint and Prettier are playing together nicely.Run
npx eslint --print-config path/to/main.js | npx eslint-config-prettier-check
If everything is OK, you should see:
No rules that are unnecessary or conflict with Prettier were found.
Disable Prettier
Don't want to use Prettier on a project? Don't want to mess with your code editor settings to disable Prettier? Prettier can ignore files and directories at the project level. Add a
.prettierignore
file to the root of your project. Note:.prettierignore
follows the.gitignore
syntax. Learn more.prettierignore example: