Skip to content

prettier.star

Set Prettier options in whichever config a repo uses.

Supports .prettierrc (JSON or YAML), .prettierrc.json, .prettierrc.yaml, .prettierrc.yml and the prettier key of package.json. JavaScript configs (prettier.config.js and friends) can't be edited safely and are not supported.

load("@fleet//prettier.star", "find", "get", "set_option")
Function What it does
find Finds the repo's Prettier config.
get Reads an option from the Prettier config.
set_option Sets an option in the Prettier config, keeping its format.

find

find(repo)

Finds the repo's Prettier config.

Arguments

Name Description
repo The repo passed to change(repo).

Returns: The path of the first of .prettierrc, .prettierrc.json, .prettierrc.yaml and .prettierrc.yml that exists, package.json when it has a prettier key, or None.

Example

find(repo)
# returns "package.json"

package.json

{"name": "web", "prettier": {"semi": false}}

Source

get

get(repo, option)

Reads an option from the Prettier config.

Arguments

Name Description
repo The repo passed to change(repo).
option The option, such as printWidth.

Returns: The value, or None when it isn't set or there is no config. YAML values come back as strings.

Example

get(repo, "printWidth")
# returns "100"

.prettierrc

singleQuote: true
printWidth: 100

Source

set_option

set_option(repo, option, value)

Sets an option in the Prettier config, keeping its format.

Arguments

Name Description
repo The repo passed to change(repo).
option The option, such as printWidth or trailingComma.
value A string, number or boolean.

Returns: True when the file changed; False when the repo has no config.

Example

set_option(repo, "trailingComma", "all")
# returns True

.prettierrc.json

{
  "semi": false,
  "trailingComma": "es5"
}

.prettierrc.json

{
  "semi": false,
  "trailingComma": "all"
}

Used in: prettier-eslint

Source