2.0.0 • Published 5 months ago

@sensible-ts/prettier v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@sensible-ts/prettier

npm prettier code style: prettier semantic-release: conventional commits license: MIT

A sensible Prettier config. This configuration sticks to the Prettier defaults for the most part, with a few changes that work better with TypeScript.

Usage

First, install this package as a dev dependency.

npm install --save-dev @sensible-ts/prettier

Then, add the following line to your package.json.

{
  "prettier": "@sensible-ts/prettier"
}

Finally, add some scripts to format your code, or, better yet, install the Prettier plugin for your editor, and set it up to auto-format on save.

Rationale

This configuration makes a few changes to the Prettier default options. The following is my rationale for changing each of them.

Print width

Default value: 80 Configured value: 100

When writing TypeScript, it can be particularly easy to go over the 80 column mark. With type annotations, Prettier can print out some ugly looking code if it is forced to not go much over 80 columns. Using a width of around 100 columns gives enough breathing room to eliminate this issue in most circumstances without going overboard.

Trailing commas

Default value: "es5" Configured value: "all"

Trailing commas are really nice when you are making updates to a list.

If you want to add a new property, you can add a new line without modifying the previously last line if that line already uses a trailing comma. This makes version-control diffs cleaner and editing code might be less troublesome.

MDN Web Docs

By default, Prettier only permits trailing commas where they are valid in ES5. The docs mention that you can turn on trailing commas everywhere depending on your target.

To run, JavaScript code formatted this way needs an engine that supports ES2017 (Node.js 8+ or a modern browser) or downlevel compilation. This also enables trailing commas in type parameters in TypeScript (supported since TypeScript 2.7 released in January 2018).

Prettier documentation

If you're using TypeScript, this isn't really a concern, since the compiler can remove them if your target is set below ES2017.

License

Licensed under the MIT License.

2.0.0

5 months ago

1.0.0

1 year ago