#compdef prettier

_prettier_parser() {
  local -a parser=(${(@f)"$(prettier --help parser | sed '1,/Valid options/d' | awk '/ [a-z]+/ { print $1 }')"})
  _values 'parser' $parser
}

_prettier() {
  typeset -A opt_args
  typeset -a _arguments_options
  local ret=1

  local context curcontext=$curcontext state line
  _arguments -s -S -C \
    {-c,--check}'[Check if given files are formatted, print summary and paths to unformatted files]' \
    {-l,--list-different}'[Print names of files that are different from Prettier'\''s formatting]' \
    {-w,--write}'[Edit files in-place. (Beware!)]' \
    '--arrow-parens[Include parentheses around a sole arrow function parameter]:arrow-parens:(always avoid)' \
    '--bracket-same-line[Put > of opening tags on the last line instead of on a new line]' \
    '--no-bracket-spacing[Do not print spaces between brackets]' \
    '--embedded-language-formatting[Control how Prettier formats quoted code embedded in the file]:embedded-language-formatting:(auto off)' \
    '--end-of-line[Which end of line characters to apply]:end-of-line:(lf crlf cr auto)' \
    '--experimental-operator-position[Where to print operators when binary expressions wrap lines]:experimental-operator-position:(start end)' \
    '--no-experimental-ternaries[Default behavior of ternaries; keep question marks on the same line as the consequent]' \
    '--html-whitespace-sensitivity[How to handle whitespaces in HTML]:html-whitespace-sensitivity:(css strict ignore)' \
    '--jsx-single-quote[Use single quotes in JSX]' \
    '--object-wrap[How to wrap object literals]:object-wrap:(preserve collapse)' \
    '--parser[Which parser to use]:parser:_prettier_parser' \
    '--print-width[The line length where Prettier will try wrap]:int:' \
    '--prose-wrap[How to wrap prose]:prose-wrap:(always never preserve)' \
    '--quote-props[Change when properties in objects are quoted]:quote-props:(as-needed consistent preserve)' \
    '--no-semi[Do not print semicolons, except at the beginning of lines which may need them]' \
    '--single-attribute-per-line[Enforce single attribute per line in HTML, Vue and JSX]' \
    '--single-quote[Use single quotes instead of double quotes]' \
    '--tab-width[Number of spaces per indentation level]:int:' \
    '--trailing-comma[Print trailing commas wherever possible when multi-line]:trailing-comma:(all es5 none)' \
    '--use-tabs[Indent with tabs instead of spaces]' \
    '--vue-indent-script-and-style[Indent script and style tags in Vue files]' \
    '--config[Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js)]:path:' \
    '--no-config[Do not look for a configuration file]' \
    '--config-precedence[Define in which order config files and CLI options should be evaluated]:config-precedence:(cli-override file-override prefer-file)' \
    '--no-editorconfig[Don'\''t take .editorconfig into account when parsing configuration]' \
    '--find-config-path[Find and print the path to a configuration file for the given input file]' \
    '--ignore-path[Path to a file with patterns describing files to ignore]:path:' \
    '--plugin[Add a plugin. Multiple plugins can be passed as separate "--plugin"s]:path:' \
    '--with-node-modules[Process files inside '\''node_modules'\'' directory]' \
    '--cursor-offset[Print (to stderr) where a cursor at the given position would move to after formatting]:int:' \
    '--range-end[Format code ending at a given character offset (exclusive)]:int:' \
    '--range-start[Format code starting at a given character offset]:int:' \
    '--cache[Only format changed files. Cannot use with --stdin-filepath]' \
    '--cache-location[Path to the cache file]:path:' \
    '--cache-strategy[Strategy for the cache to use for detecting changed files]:metadata:content:' \
    '--check-ignore-pragma[Check whether the file'\''s first docblock comment contains '\''@noprettier'\'' or '\''@noformat'\'' to determine if it should be formatted]' \
    '--no-color[Do not colorize error messages]' \
    '--no-error-on-unmatched-pattern[Prevent errors when pattern is unmatched]' \
    '--file-info[Extract the following info (as JSON) for a given file path]:path:' \
    {-h,--help}'[Show CLI usage, or details about the given flag]:flag:' \
    {-u,--ignore-unknown}'[Ignore unknown files]' \
    '--insert-pragma[Insert @format pragma into file'\''s first docblock comment]' \
    '--log-level[Level of logs to report (default: log)]:log-level:(silent error warn log debug)' \
    '--require-pragma[Require either '\''@prettier'\'' or '\''@format'\'' to be present in the file'\''s first docblock comment in order for it to be formatted]' \
    '--stdin-filepath[Path to the file to pretend that stdin comes from]:path:' \
    '--support-info[Print support information as JSON]' \
    {-v,--version}'[Print Prettier version]' \
    '*: :_files' \
    && ret=0
}

_prettier "$@"
