Skip to content

Instantly share code, notes, and snippets.

@drewwyatt
Created February 3, 2024 18:16
Show Gist options
  • Save drewwyatt/f51741b64af99b65eec7ce5ab9c6b30d to your computer and use it in GitHub Desktop.
Save drewwyatt/f51741b64af99b65eec7ce5ab9c6b30d to your computer and use it in GitHub Desktop.
/// https://prettier.io/docs/en/options
/// Try prettier's new ternary formatting before it becomes the default behavior.
/// true - Use curious ternaries, with the question mark after the condition.
/// false - Retain the default behavior of ternaries; keep question marks on the same line as the consequent.
experimentalTernaries: Boolean = false
/// Specify the line length that the printer will wrap on.
///
/// For readability we recommend against using more than 80 characters:
/// In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don’t strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum.
/// Prettier’s printWidth option does not work the same way. It is not the hard upper allowed line length limit. It is a way to say to Prettier roughly how long you’d like lines to be. Prettier will make both shorter and longer lines, but generally strive to meet the specified printWidth.
/// Remember, computers are dumb. You need to explicitly tell them what to do, while humans can make their own (implicit) judgements, for example on when to break a line.
/// In other words, don’t try to use printWidth as if it was ESLint’s max-len – they’re not the same. max-len just says what th
printWidth: Int = 80
/// Specify the number of spaces per indentation-level.
tabWidth: Int = 2
/// Indent lines with tabs instead of spaces.
useTabs: Boolean = false
/// Print semicolons at the ends of statements.
///
/// Valid options:
/// true - Add a semicolon at the end of every statement.
/// false - Only add semicolons at the beginning of lines that may introduce ASI failures.
semi: Boolean = true
/// Use single quotes instead of double quotes.
///
/// Notes:
/// JSX quotes ignore this option – see jsx-single-quote.
/// If the number of quotes outweighs the other quote, the quote which is less used will be used to format the string - Example: "I'm double quoted" results in "I'm double quoted" and "This \"example\" is single quoted" results in 'This "example" is single quoted'.
singleQuote: Boolean = false
/// "as-needed" - Only add quotes around object properties where required.
/// "consistent" - If at least one property in an object requires quotes, quote all properties.
/// "preserve" - Respect the input use of quotes in object properties.
typealias QuoteProps = "as-needed" | "consistent" | "preserve"
/// Change when properties in objects are quoted.
quoteProps: QuoteProps = "as-needed"
/// Use single quotes instead of double quotes in JSX.
jsxSingleQuote: Boolean = false
/// "all" - Trailing commas wherever possible (including function parameters and calls). To run, JavaScript code formatted this way needs an engine that supports ES2017 (Node.js 8+ or a modern browser) or downlevel compilation. This also enables trailing commas in type parameters in TypeScript (supported since TypeScript 2.7 released in January 2018).
/// "es5" - Trailing commas where valid in ES5 (objects, arrays, etc.). Trailing commas in type parameters in TypeScript and Flow.
/// "none" - No trailing commas.
typealias TrailingCommas = "all" | "es5" | "none"
/// Print trailing commas wherever possible in multi-line comma-separated syntactic structures. (A single-line array, for example, never gets trailing commas.)
trailingComma: TrailingCommas = "all"
/// Print spaces between brackets in object literals.
///
/// true - Example: { foo: bar }.
/// false - Example: {foo: bar}.
bracketSpacing: Boolean = true
/// Put the > of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being alone on the next line (does not apply to self closing elements).
bracketSameLine: Boolean = false
/// "always" - Always include parens. Example: (x) => x
/// "avoid" - Omit parens when possible. Example: x => x
typealias ArrowParens = "always" | "avoid"
/// Include parentheses around a sole arrow function parameter.
arrowParens: ArrowParens = "always"
/// Format only a segment of a file.
///
/// These two options can be used to format code starting and ending at a given character offset (inclusive and exclusive, respectively). The range will extend:
/// Backwards to the start of the first line containing the selected statement.
/// Forwards to the end of the selected statement.
rangeStart: Int?
/// Format only a segment of a file.
///
/// These two options can be used to format code starting and ending at a given character offset (inclusive and exclusive, respectively). The range will extend:
/// Backwards to the start of the first line containing the selected statement.
/// Forwards to the end of the selected statement.
rangeEnd: Int?
/// "babel" (via @babel/parser) Named "babylon" until v1.16.0
/// "babel-flow" (same as "babel" but enables Flow parsing explicitly to avoid ambiguity) First available in v1.16.0
/// "babel-ts" (similar to "typescript" but uses Babel and its TypeScript plugin) First available in v2.0.0
/// "flow" (via flow-parser)
/// "typescript" (via @typescript-eslint/typescript-estree) First available in v1.4.0
/// "espree" (via espree) First available in v2.2.0
/// "meriyah" (via meriyah) First available in v2.2.0
/// "acorn" (via acorn) First available in v2.6.0
/// "css" (via postcss) First available in v1.7.1
/// "scss" (via postcss-scss) First available in v1.7.1
/// "less" (via postcss-less) First available in v1.7.1
/// "json" (via @babel/parser parseExpression) First available in v1.5.0
/// "json5" (same parser as "json", but outputs as json5) First available in v1.13.0
/// "jsonc" (same parser as "json", but outputs as "JSON with Comments") First available in v3.2.0
/// "json-stringify" (same parser as "json", but outputs like JSON.stringify) First available in v1.13.0
/// "graphql" (via graphql/language) First available in v1.5.0
/// "markdown" (via remark-parse) First available in v1.8.0
/// "mdx" (via remark-parse and @mdx-js/mdx) First available in v1.15.0
/// "html" (via angular-html-parser) First available in 1.15.0
/// "vue" (same parser as "html", but also formats vue-specific syntax) First available in 1.10.0
/// "angular" (same parser as "html", but also formats angular-specific syntax via angular-estree-parser) First available in 1.15.0
/// "lwc" (same parser as "html", but also formats LWC-specific syntax for unquoted template attributes) First available in 1.17.0
/// "yaml" (via yaml and yaml-unist-parser) First available in 1.14.0
typealias Parser = "babel" | "babel-flow" | "babel-ts" | "flow" | "typescript" | "espree" | "meriyah" | "acorn" | "css" | "scss" | "less" | "json" | "json5" | "jsonc" | "json-stringify" | "graphql" | "markdown" | "mdx" | "html" | "vue" | "angular" | "lwc" | "yaml"
/// Specify which parser to use.
/// Prettier automatically infers the parser from the input file path, so you shouldn’t have to change this setting.
/// Both the babel and flow parsers support the same set of JavaScript features (including Flow type annotations). They might differ in some edge cases, so if you run into one of those you can try flow instead of babel. Almost the same applies to typescript and babel-ts. babel-ts might support JavaScript features (proposals) not yet supported by TypeScript, but it’s less permissive when it comes to invalid code and less battle-tested than the typescript parser.
parser: Parser?
/// Specify the file name to use to infer which parser to use.
///
/// For example, the following will use the CSS parser:
/// cat foo | prettier --stdin-filepath foo.css
filePath: String?
/// A file with the following as its first comment will be formatted when --require-pragma is supplied:
///
/// /**
/// * @prettier
/// */
/// or
/// /**
/// * @format
/// */
requirePragma: Boolean = false
/// 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.
/// Note that “in tandem” doesn’t mean “at the same time”. When the two options are used simultaneously, --require-pragma has priority, so --insert-pragma is ignored. The idea is that during an incremental adoption of Prettier in a big codebase, the developers participating in the transition process use --insert-pragma whereas --require-pragma is used by the rest of the team and automated tooling to process only files already transitioned. The feature has been inspired by Facebook’s adoption strategy.
insertPragma: Boolean = false
/// "always" - Wrap prose if it exceeds the print width.
/// "never" - Un-wrap each block of prose into one line.
/// "preserve" - Do nothing, leave prose as-is. First available in v1.9.0
typealias ProseWrap = "always" | "never" | "preserve"
/// By default, Prettier will not change wrapping in markdown text since some services use a linebreak-sensitive renderer, e.g. GitHub comments and BitBucket. To have Prettier wrap prose to the print width, change this option to "always". If you want Prettier to force all prose blocks to be on a single line and rely on editor/viewer soft wrapping instead, you can use "never".
proseWrap: ProseWrap = "preserve"
/// "css" - Respect the default value of CSS display property. For Handlebars treated same as strict.
/// "strict" - Whitespace (or the lack of it) around all tags is considered significant.
/// "ignore" - Whitespace (or the lack of it) around all tags is considered insignificant.
typealias HTMLWhiteSpaceSensitivity = "css" | "strict" | "ignore"
/// Specify the global whitespace sensitivity for HTML, Vue, Angular, and Handlebars. See whitespace-sensitive formatting for more info.
htmlWhitespaceSensitivity: HTMLWhiteSpaceSensitivity = "css"
/// Whether or not to indent the code inside <script> and <style> tags in Vue files.
///
/// false - Do not indent script and style tags in Vue files.
/// true - Indent script and style tags in Vue files.
vueIndentScriptAndStyle: Boolean = false
/// "lf" – Line Feed only (\n), common on Linux and macOS as well as inside git repos
/// "crlf" - Carriage Return + Line Feed characters (\r\n), common on Windows
/// "cr" - Carriage Return character only (\r), used very rarely
/// "auto" - Maintain existing line endings (mixed values within one file are normalised by looking at what’s used after the first line)
typealias EndOfLine = "lf" | "crlf" | "cr" | "auto"
/// For historical reasons, there exist two common flavors of line endings in text files. That is \n (or LF for Line Feed) and \r\n (or CRLF for Carriage Return + Line Feed). The former is common on Linux and macOS, while the latter is prevalent on Windows. Some details explaining why it is so can be found on Wikipedia.
/// When people collaborate on a project from different operating systems, it becomes easy to end up with mixed line endings in a shared git repository. It is also possible for Windows users to accidentally change line endings in a previously committed file from LF to CRLF. Doing so produces a large git diff and thus makes the line-by-line history for a file (git blame) harder to explore.
///
/// If you want to make sure that your entire git repository only contains Linux-style line endings in files covered by Prettier:
/// 1. Ensure Prettier’s endOfLine option is set to lf (this is a default value since v2.0.0)
/// 2. Configure a pre-commit hook that will run Prettier
/// 3. Configure Prettier to run in your CI pipeline using --check flag. If you use Travis CI, set the autocrlf option to input in .travis.yml.
/// 4. Add * text=auto eol=lf to the repo’s .gitattributes file. You may need to ask Windows users to re-clone your repo after this change to ensure git has not converted LF to CRLF on checkout.
///
/// All modern text editors in all operating systems are able to correctly display line endings when \n (LF) is used. However, old versions of Notepad for Windows will visually squash such lines into one as they can only deal with \r\n (CRLF).
endOfLine: EndOfLine = "lf"
typealias EmbeddedLanguageFormatting = "auto" | "off"
/// Control whether Prettier formats quoted code embedded in the file.
/// When Prettier identifies cases where it looks like you've placed some code it knows how to format within a string in another file, like in a tagged template in JavaScript with a tag named html or in code blocks in Markdown, it will by default try to format that code.
/// Sometimes this behavior is undesirable, particularly in cases where you might not have intended the string to be interpreted as code. This option allows you to switch between the default behavior (auto) and disabling this feature entirely (off).
embeddedLanguageFormatting: EmbeddedLanguageFormatting = "auto"
/// Enforce single attribute per line in HTML, Vue and JSX.
singleAttributePerLine: Boolean = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment