Home

Awesome

<div align="center"> <img alt="Prettier" src="https://raw.githubusercontent.com/prettier/prettier-logo/master/images/prettier-icon-light.png"> <img alt="CoffeeScript" height="184" width="220" hspace="44" vspace="15" src="https://cdn.worldvectorlogo.com/logos/coffeescript.svg"> </div> <h2 align="center">Prettier CoffeeScript Plugin</h2> <p align="center"> <a href="https://travis-ci.org/com/helixbass/prettier-plugin-coffeescript/"> <img alt="Travis" src="https://img.shields.io/travis/com/helixbass/prettier-plugin-coffeescript.svg"> </a> <a href="https://www.npmjs.com/package/prettier-plugin-coffeescript"> <img alt="npm version" src="https://img.shields.io/npm/v/prettier-plugin-coffeescript.svg?style=flat-square"> </a> <a href="#badge"> <img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square"> </a> </p>

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary

This plugin adds support for the CoffeeScript language to Prettier

Install

This plugin currently requires a forked version of Prettier (in order to support things like implicit calls and objects, new Prettier primitives are required - here's the PR) as well as CoffeeScript v2.5.0 or higher.

So the best way to ensure that the required dependencies are available to the plugin is to explicitly install them in your project along with the plugin:

yarn:

yarn add --dev coffeescript@^2.5.0 github:helixbass/prettier#prettier-v2.1.0-dev.100-gitpkg prettier-plugin-coffeescript

npm:

npm install --save-dev coffeescript@^2.5.0 github:helixbass/prettier#prettier-v2.1.0-dev.100-gitpkg prettier-plugin-coffeescript

Usage

To run Prettier manually, you can add prettier as a script in your package.json,

{
  "scripts": {
    "prettier": "prettier"
  }
}

and then run it via

yarn run prettier path/to/file.coffee --write
# or
npm run prettier -- path/to/file.coffee --write

In practice, there are various ways to run Prettier:

The "Usage" section of the Prettier docs describes how to set these up

Running in-editor

Depending on your editor, there may or may not currently be a straightforward way to get Prettier running against .coffee files (e.g. using a Prettier editor plugin).

If you're having trouble getting Prettier running in your editor (and it's not listed below), please file an issue and we'll try and help with support for your editor.

VS Code

To run Prettier from VS Code, first install the VS Code Prettier extension.

Then add to your VS Code settings.json:

"[coffeescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
}

Configuration

The following formatting options are supported:

NameDefaultDescription
printWidth80Same as in Prettier (see prettier docs)
tabWidth2Same as in Prettier (see prettier docs)
singleQuotetrueIf set to true, non-interpolated strings/heredocs will prefer single quotes ('abc'/'''I'm a heredoc''')
commanoneApplies to multiline arrays/calls/function params/explicit objects <br> If set to none, no commas will be used <br> If set to nonTrailing, commas will be added after non-last items <br> If set to all, commas will be added after all items
noImplicit[]If includes callParens, call parentheses will always be explicitly included <br> If includes objectBraces, object braces will always be explicitly included
respectExplicit[]If includes callParens, explicit call parentheses in the original source will be preserved <br> If includes objectBraces, explicit object braces in the original source will be preserved
respectBreak['control', 'functionBody', 'object']Applies to multiline structures in the original source <br> If includes control, the formatter will not attempt to inline multiline control structures (if/unless/for/while/until/try) <br> If includes functionBody, the formatter will not attempt to inline functions with indented bodies <br> If includes object, the formatter will not attempt to inline multiline objects (similar to Prettier JS formatter)
inlineAssignmentsTo['control']If includes control, will attempt to inline assignments of control structures
emptyParamListParensfalseIf set to true, functions with an empty param list will include an empty pair of parentheses eg () -> a
indentChainfalseIf set to true, multiline chained method calls will be indented with respect to the first line of the chain <br> :warning: Warning :warning: Setting indentChain: true can currently cause broken formatting in some edge cases

Any of these can be added to an existing or new Prettier configuration file. For example:

{
  "respectExplicit": ["objectBraces"],
}

Help / Contributing / Feedback

Please file an issue or submit a pull request on Github with any bugs/questions/suggestions

If you're interested in contributing to the development of this plugin, Prettier's CONTRIBUTING guide may be helpful

To get started:

License

MIT