Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ParserOptions

Hierarchy

Index

Properties

Optional allowAwaitOutsideFunction

allowAwaitOutsideFunction: undefined | false | true

By default, await use is not allowed outside of an async function. Set this to true to accept such code.

Optional allowImportExportEverywhere

allowImportExportEverywhere: undefined | false | true

By default, import and export declarations can only appear at a program's top level. Setting this option to true allows them anywhere where a statement is allowed.

Optional allowReturnOutsideFunction

allowReturnOutsideFunction: undefined | false | true

By default, a return statement at the top level raises an error. Set this to true to accept such code.

Optional allowSuperOutsideMethod

allowSuperOutsideMethod: undefined | false | true

Optional allowUndeclaredExports

allowUndeclaredExports: undefined | false | true

By default, exported identifiers must refer to a declared variable. Set this to true to allow export statements to reference undeclared variables.

arrowParens

arrowParens: "avoid" | "always"

Include parentheses around a sole arrow function parameter.

default

'always'

bracketSpacing

bracketSpacing: boolean

Print spaces between brackets in object literals.

default

true

Optional createParenthesizedExpressions

createParenthesizedExpressions: undefined | false | true

By default, the parser adds information about parentheses by setting extra.parenthesized to true as needed. When this option is true the parser creates ParenthesizedExpression AST nodes instead of using the extra property.

embeddedLanguageFormatting

embeddedLanguageFormatting: "auto" | "off"

Control whether Prettier formats quoted code embedded in the file.

default

'auto'

endOfLine

endOfLine: "auto" | "lf" | "crlf" | "cr"

Which end of line characters to apply.

default

'lf'

filepath

filepath: string

Specify the input filepath. This will be used to do parser inference.

htmlWhitespaceSensitivity

htmlWhitespaceSensitivity: "css" | "strict" | "ignore"

How to handle whitespaces in HTML.

default

'css'

insertPragma

insertPragma: boolean

Prettier can insert a special @format marker at the top of files specifying that the file has been formatted with prettier. This works well when used in tandem with the --require-pragma option. If there is already a docblock at the top of the file then this option will add a newline to it with the @format marker.

default

false

jsxBracketSameLine

jsxBracketSameLine: boolean

Put the > of a multi-line JSX element at the end of the last line instead of being alone on the next line.

default

false

jsxSingleQuote

jsxSingleQuote: boolean

Use single quotes in JSX.

default

false

locEnd

locEnd: (node: any) => number

Type declaration

    • (node: any): number
    • Parameters

      • node: any

      Returns number

locStart

locStart: (node: any) => number

Type declaration

    • (node: any): number
    • Parameters

      • node: any

      Returns number

originalText

originalText: string

parser

Specify which parser to use.

Optional plugins

plugins: ParserPlugin[]

Array containing the plugins that you want to enable.

printWidth

printWidth: number

Specify the line length that the printer will wrap on.

default

80

proseWrap

proseWrap: "always" | "never" | "preserve"

By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer. In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out.

default

'preserve'

quoteProps

quoteProps: "as-needed" | "consistent" | "preserve"

Change when properties in objects are quoted.

default

'as-needed'

rangeEnd

rangeEnd: number

Format only a segment of a file.

default

Infinity

rangeStart

rangeStart: number

Format only a segment of a file.

default

0

Optional ranges

ranges: undefined | false | true

Adds a ranges property to each node: [node.start, node.end]

requirePragma

requirePragma: boolean

Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file. This is very useful when gradually transitioning large, unformatted codebases to prettier.

default

false

semi

semi: boolean

Print semicolons at the ends of statements.

default

true

singleQuote

singleQuote: boolean

Use single quotes instead of double quotes.

default

false

Optional sourceFilename

sourceFilename: undefined | string

Correlate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.

Optional sourceType

sourceType: "script" | "module" | "unambiguous"

Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". Defaults to "script". "unambiguous" will make @babel/parser attempt to guess, based on the presence of ES6 import or export statements. Files with ES6 imports and exports are considered "module" and are otherwise "script".

Optional startLine

startLine: undefined | number

By default, the first line of code parsed is treated as line 1. You can provide a line number to alternatively start with. Useful for integration with other source tools.

Optional strictMode

strictMode: undefined | false | true

Should the parser work in strict mode. Defaults to true if sourceType === 'module'. Otherwise, false.

tabWidth

tabWidth: number

Specify the number of spaces per indentation-level.

default

2

Optional tokens

tokens: undefined | false | true

Adds all parsed tokens to a tokens property on the File node.

trailingComma

trailingComma: "none" | "es5" | "all"

Print trailing commas wherever possible.

default

'es5'

useTabs

useTabs: boolean

Indent lines with tabs instead of spaces

default

false

vueIndentScriptAndStyle

vueIndentScriptAndStyle: boolean

Whether or not to indent the code inside