Skip to content

Latest commit

 

History

History
91 lines (75 loc) · 29.3 KB

prettier-example.md

File metadata and controls

91 lines (75 loc) · 29.3 KB

Prettier configuration file reference

Config

Object containing the following properties:

Property Description Type Default
arrowParens Include parentheses around a sole arrow function parameter. 'always' | 'avoid' 'always'
bracketSameLine Put > of opening tags on the last line instead of on a new line. boolean false
bracketSpacing Print spaces between brackets. boolean true
cursorOffset Print (to stderr) where a cursor at the given position would move to after formatting. number (int) -1
embeddedLanguageFormatting Control how Prettier formats quoted code embedded in the file. 'auto' | 'off' 'auto'
endOfLine Which end of line characters to apply. 'lf' | 'crlf' | 'cr' | 'auto' 'lf'
experimentalTernaries Use curious ternaries, with the question mark after the condition. boolean false
filepath Specify the input filepath. This will be used to do parser inference. string
htmlWhitespaceSensitivity How to handle whitespaces in HTML. 'css' | 'strict' | 'ignore' 'css'
insertPragma Insert @format pragma into file's first docblock comment. boolean false
jsxSingleQuote Use single quotes in JSX. boolean false
parser Which parser to use. 'flow' | 'babel' | 'babel-flow' | 'babel-ts' | 'typescript' | 'acorn' | 'espree' | 'meriyah' | 'css' | 'less' | 'scss' | 'json' | 'json5' | 'jsonc' | 'json-stringify' | 'graphql' | 'markdown' | 'mdx' | 'vue' | 'yaml' | 'glimmer' | 'html' | 'angular' | 'lwc' | string
plugins Add a plugin. Multiple plugins can be passed as separate --plugins. Array<string> []
printWidth The line length where Prettier will try wrap. number (int) 80
proseWrap How to wrap prose. 'always' | 'never' | 'preserve' 'preserve'
quoteProps Change when properties in objects are quoted. 'as-needed' | 'consistent' | 'preserve' 'as-needed'
rangeEnd Format code ending at a given character offset (exclusive).
The range will extend forwards to the end of the selected statement.
number (int) (nullable) null
rangeStart Format code starting at a given character offset.
The range will extend backwards to the start of the first line containing the selected statement.
number (int) 0
requirePragma Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
boolean false
semi Print semicolons. boolean true
singleAttributePerLine Enforce single attribute per line in HTML, Vue and JSX. boolean false
singleQuote Use single quotes instead of double quotes. boolean false
tabWidth Number of spaces per indentation level. number (int) 2
trailingComma Print trailing commas wherever possible when multi-line. 'all' | 'es5' | 'none' 'all'
useTabs Indent with tabs instead of spaces. boolean false
vueIndentScriptAndStyle Indent script and style tags in Vue files. boolean false
overrides (*) Provide a list of patterns to override prettier configuration. Array of objects:
  • files: string | Array<string> - Include these files in this override.
  • excludeFiles: string | Array<string> - Exclude these files from this override.
  • options: Options - The options to apply for this override.

(*) Required.

Options

Object containing the following properties:

Property Description Type Default
arrowParens Include parentheses around a sole arrow function parameter. 'always' | 'avoid' 'always'
bracketSameLine Put > of opening tags on the last line instead of on a new line. boolean false
bracketSpacing Print spaces between brackets. boolean true
cursorOffset Print (to stderr) where a cursor at the given position would move to after formatting. number (int) -1
embeddedLanguageFormatting Control how Prettier formats quoted code embedded in the file. 'auto' | 'off' 'auto'
endOfLine Which end of line characters to apply. 'lf' | 'crlf' | 'cr' | 'auto' 'lf'
experimentalTernaries Use curious ternaries, with the question mark after the condition. boolean false
filepath Specify the input filepath. This will be used to do parser inference. string
htmlWhitespaceSensitivity How to handle whitespaces in HTML. 'css' | 'strict' | 'ignore' 'css'
insertPragma Insert @format pragma into file's first docblock comment. boolean false
jsxSingleQuote Use single quotes in JSX. boolean false
parser Which parser to use. 'flow' | 'babel' | 'babel-flow' | 'babel-ts' | 'typescript' | 'acorn' | 'espree' | 'meriyah' | 'css' | 'less' | 'scss' | 'json' | 'json5' | 'jsonc' | 'json-stringify' | 'graphql' | 'markdown' | 'mdx' | 'vue' | 'yaml' | 'glimmer' | 'html' | 'angular' | 'lwc' | string
plugins Add a plugin. Multiple plugins can be passed as separate --plugins. Array<string> []
printWidth The line length where Prettier will try wrap. number (int) 80
proseWrap How to wrap prose. 'always' | 'never' | 'preserve' 'preserve'
quoteProps Change when properties in objects are quoted. 'as-needed' | 'consistent' | 'preserve' 'as-needed'
rangeEnd Format code ending at a given character offset (exclusive).
The range will extend forwards to the end of the selected statement.
number (int) (nullable) null
rangeStart Format code starting at a given character offset.
The range will extend backwards to the start of the first line containing the selected statement.
number (int) 0
requirePragma Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
boolean false
semi Print semicolons. boolean true
singleAttributePerLine Enforce single attribute per line in HTML, Vue and JSX. boolean false
singleQuote Use single quotes instead of double quotes. boolean false
tabWidth Number of spaces per indentation level. number (int) 2
trailingComma Print trailing commas wherever possible when multi-line. 'all' | 'es5' | 'none' 'all'
useTabs Indent with tabs instead of spaces. boolean false
vueIndentScriptAndStyle Indent script and style tags in Vue files. boolean false

All properties are optional.

Overrides

Object containing the following properties:

Property Description Type
overrides (*) Provide a list of patterns to override prettier configuration. Array of objects:
  • files: string | Array<string> - Include these files in this override.
  • excludeFiles: string | Array<string> - Exclude these files from this override.
  • options: Options - The options to apply for this override.

(*) Required.

Prettierrc

Schema for .prettierrc

Union of the following possible types: