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

Export prettierrc #160

Merged
merged 6 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*/

module.exports = {
extends: ['plugin:@automattic/wpvip/recommended'],
extends: [ 'plugin:@automattic/wpvip/recommended' ],
root: true,
};
6 changes: 1 addition & 5 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"bracketSpacing": true,
"singleQuote": true,
"useTabs": true
}
"./prettierrc.js"
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ You may also wish to define an `.eslintignore` file if there are files or paths

The "recommended" config includes rules for JavaScript, TypeScript, Jest, and React, including rules related to formatting and white space. It is intended to be strict! Opinionated defaults keep our codebases consistent and reduce the friction we experience when context-switching between projects.

If your project has installed [Prettier](https://prettier.io/) as a dependency, then many formatting tasks will be delegated to it (via `eslint-plugin-prettier`). You are encouraged to define your own [`.prettierrc` configuration file](https://prettier.io/docs/en/configuration.html) to fine-tune your project’s formatting.

Of course, this recommended config may not be ideal for every project, so feel free to "build your own" using the available modular configs. The recommended config is equivalent to:

```js
Expand All @@ -52,6 +50,22 @@ module.exports = {

Note that the order of configs can matter, since they can contain overrides. It is particularly important to add the `prettier` config last.

### Prettier

Install [WP Prettier](https://github.com/Automattic/wp-prettier) to benefit from additional formatting rules:

```sh
npm i --save-dev --save-exact "prettier@npm:wp-prettier@latest"
```

This repo also provides a Prettier config, which you can use with the following `.prettierrc`:

```json
"@automattic/eslint-plugin-wpvip/prettierrc"
```

For maximum benefit, see [Prettier's documentation on enabling format-on-save in your editor](https://prettier.io/docs/en/editors.html). This enables you to concentrate on coding while Prettier handles formatting.

## CLI

The `cli` config allows certain behaviors that are usually against best practice but are useful in a codebase that produces a CLI tool:
Expand Down
11 changes: 5 additions & 6 deletions __fixtures__/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ new RegExp( dosPattern );

function x( y ) {
return xIsACoolParam;
};
}

let things = {
a: 13,
cd: 99.99,
e9: 6e99,
f7: ( ) => ['x'],
f7: () => [ 'x' ],
12: '32',
ff: xx => xx,
gg: ( {fds, }) =>
fds,
gg: ( { fds } ) => fds,
};

export async function doThingsInSequence() {
Expand All @@ -31,7 +30,7 @@ export async function doThingsInSequence() {
}

export function doThingsInSequenceWithoutWaiting() {
Object.keys( things ).forEach( async ( thing ) => {
Object.keys( things ).forEach( async thing => {
await Promise.resolve( thing );
} );
}
Expand All @@ -43,4 +42,4 @@ export function shadow() {

nonExistent();

// There is intentionally no new line at the end of this file to hit [eol-last](https://eslint.org/docs/rules/eol-last).
// There is intentionally no new line at the end of this file to hit [eol-last](https://eslint.org/docs/rules/eol-last).
5 changes: 1 addition & 4 deletions __fixtures__/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ export default {
things,
};

function someCoolDecorator(
totallyRadArgument,
value
): typeof totallyRadArgument {
function someCoolDecorator( totallyRadArgument, value ): typeof totallyRadArgument {
return totallyRadArgument;
}

Expand Down
Loading