Skip to content

Commit

Permalink
Eslint: Restore curly rule when using prettier
Browse files Browse the repository at this point in the history
The `curly` eslint rule was disabled when using prettier. Some
configurations of the rule may conflict with prettier's autoformatting,
but the `all` option used in @wordpress/eslint-plugin does not.

This aligns with the WordPress JavaScript Standards:

> `if`, `else`, `for`, `while`, and `try` blocks should always use
> braces, and always go on multiple lines.

- WordPress JavaScript Standards: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/#blocks-and-curly-braces
- `curly` rule description: https://eslint.org/docs/latest/rules/curly#rule-details

Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
  • Loading branch information
5 people committed Apr 30, 2024
1 parent 2f6b916 commit d6226be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Enable `curly` eslint rule when using prettier ([#61204](https://github.com/WordPress/gutenberg/pull/61204)).

## 17.13.0 (2024-04-19)

## 17.12.0 (2024-04-03)
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-plugin/configs/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ if ( isPackageInstalled( 'prettier' ) ) {
const prettierConfig = { ...defaultPrettierConfig, ...localPrettierConfig };
config.rules = {
'prettier/prettier': [ 'error', prettierConfig ],
// Prettier _disables_ this rule, but we want it!
// See https://github.com/prettier/eslint-config-prettier?tab=readme-ov-file#curly
// > This rule requires certain options.
// > …
// > If you like this rule, it can be used just fine with Prettier as long as you don’t use the "multi-line" or "multi-or-nest" option.
curly: [ 'error', 'all' ],
};
}

Expand Down

0 comments on commit d6226be

Please sign in to comment.