Prettier Coffeescript Plugin
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
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:
``bash`
yarn add --dev coffeescript@^2.5.0 github:helixbass/prettier#prettier-v2.1.0-dev.100-gitpkg prettier-plugin-coffeescript
npm:
`bash`
npm install --save-dev coffeescript@^2.5.0 github:helixbass/prettier#prettier-v2.1.0-dev.100-gitpkg prettier-plugin-coffeescript
To run Prettier manually, you can add prettier as a script in your package.json,
`json`
{
"scripts": {
"prettier": "prettier"
}
}
and then run it via
`bash`
yarn run prettier path/to/file.coffee --writeor
npm run prettier -- path/to/file.coffee --write
In practice, there are various ways to run Prettier:
- most editors can be configured to run Prettier automatically (see below for instructions for specific editors)
- Prettier can be configured to run via a linter like ESLint
- you can enforce the usage of Prettier by having it run automatically before committing code
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"
}
The following formatting options are supported:
| Name | Default | Description |
| -------------- | ------------ | ----------------------------------------------------------------------------------------------- |
| printWidth | 80 | Same as in Prettier (see prettier docs) |tabWidth
| | 2 | Same as in Prettier (see prettier docs) |singleQuote
| | true | If set to true, non-interpolated strings/heredocs will prefer single quotes ('abc'/'''I'm a heredoc''') |comma
| | none | Applies to multiline arrays/calls/function params/explicit objects none
If set to , no commas will be used nonTrailing
If set to , commas will be added after non-last items all
If set to , commas will be added after all items |noImplicit
| | [] | If includes callParens, call parentheses will always be explicitly included objectBraces
If includes , object braces will always be explicitly included |respectExplicit
| | [] | If includes callParens, explicit call parentheses in the original source will be preserved objectBraces
If includes , explicit object braces in the original source will be preserved |respectBreak
| | ['control', 'functionBody', 'object'] | Applies to multiline structures in the original source control
If includes , the formatter will not attempt to inline multiline control structures (if/unless/for/while/until/try) functionBody
If includes , the formatter will not attempt to inline functions with indented bodies object
If includes , 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 |emptyParamListParens
| | false | If set to true, functions with an empty param list will include an empty pair of parentheses eg () -> a |indentChain
| | false | If set to true, multiline chained method calls will be indented with respect to the first line of the chain indentChain: true
:warning: Warning :warning: Setting 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:
`json`
{
"respectExplicit": ["objectBraces"],
}
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:
- Clone this repository
- Run yarn installtest.coffee
- Create a fileyarn prettier test.coffee
- Run to check the output.prettierrc
- You can adjust the project's file to temporarily adjust formatting options when running manuallyyarn test
- Run while developing to see if any formatting snapshots have changedyarn test -u
- To update the stored snapshots, run tests/
- Add new snapshot tests under . New subdirectories need a jsfmt.spec.js` file, where you can specify multiple different formatting option configurations for those snapshots if desired
MIT