├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── autoload ├── prettier.vim └── prettier │ ├── bridge │ └── parser.vim │ ├── job │ ├── async │ │ ├── neovim.vim │ │ └── vim.vim │ └── runner.vim │ ├── logging │ └── error.vim │ ├── presets │ └── fb.vim │ ├── resolver │ ├── config.vim │ ├── executable.vim │ └── preset.vim │ └── utils │ ├── buffer.vim │ ├── quickfix.vim │ ├── shim.vim │ └── version.vim ├── doc └── prettier.txt ├── ftdetect ├── css.vim ├── graphql.vim ├── html.vim ├── javascript.vim ├── json.vim ├── less.vim ├── lua.vim ├── markdown.vim ├── php.vim ├── ruby.vim ├── scss.vim ├── svelte.vim ├── typescript.vim ├── vue.vim ├── xml.vim └── yaml.vim ├── ftplugin ├── css.vim ├── graphql.vim ├── html.vim ├── javascript.vim ├── json.vim ├── less.vim ├── lua.vim ├── markdown.vim ├── php.vim ├── ruby.vim ├── scss.vim ├── svelte.vim ├── typescript.vim ├── vue.vim ├── xml.vim └── yaml.vim ├── media └── vim-prettier.gif ├── package.json ├── plugin └── prettier.vim ├── tests ├── __snapshots__ │ └── formatting.test.js.snap ├── fixtures │ ├── foo.css │ ├── foo.graphql │ ├── foo.html │ ├── foo.js │ ├── foo.json │ ├── foo.less │ ├── foo.lua │ ├── foo.md │ ├── foo.php │ ├── foo.rb │ ├── foo.scss │ ├── foo.ts │ ├── foo.vue │ ├── foo.xml │ └── foo.yaml ├── formatting.test.js ├── vimrc └── vimscript │ └── version.vim └── yarn.lock /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Do you want to request a *feature* or report a *bug*?** 2 | 3 | **What is the current/expected behavior?** 4 | 5 | **What version of `vim-prettier` are you using - (output of `:PrettierVersion`) ?** 6 | 7 | **What version of `prettier` are you using - (output of `:PrettierCliVersion`) ?** 8 | 9 | **What is your `prettier` executable path - (output of `:PrettierCliPath`) ?** 10 | 11 | **Did this work in previous versions of vim-prettier and/or prettier ?** 12 | 13 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Before* submitting a pull request, please make sure the following is done... 2 | 3 | 1. Fork the repo and create your branch from `master`. 4 | 2. If you've added code that should be tested, do a sanity check on `vim8` and `neovim` 5 | 3. If you've changed APIs, update the README and documentation `./doc/prettier.txt` 6 | 7 | Please use the simple form below as a guideline for describing your pull request. 8 | 9 | Thanks for contributing to vim-prettier 10 | 11 | * * * 12 | 13 | **Summary** 14 | 15 | [...] 16 | 17 | **Test Plan** 18 | 19 | [...] 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | TODO 2 | doc/tags 3 | node_modules 4 | .yarn_lock 5 | yarn.lock 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [Unreleased](https://github.com/prettier/vim-prettier/tree/HEAD) 4 | 5 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/1.0.0...HEAD) 6 | 7 | **Closed issues:** 8 | 9 | - Keep show warning after save! [\#347](https://github.com/prettier/vim-prettier/issues/347) 10 | - Prettier auto format on Save not working. [\#342](https://github.com/prettier/vim-prettier/issues/342) 11 | 12 | ## [1.0.0](https://github.com/prettier/vim-prettier/tree/1.0.0) (2023-10-10) 13 | 14 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/1.0.0-beta...1.0.0) 15 | 16 | **Closed issues:** 17 | 18 | - Deprecated / Unknown options when using Prettier v3 [\#346](https://github.com/prettier/vim-prettier/issues/346) 19 | - Why prettier keeps adding warn messages on top of my document? [\#344](https://github.com/prettier/vim-prettier/issues/344) 20 | - plugin didn't work without installing eslint-config-prettier & eslint-plugin-prettier [\#339](https://github.com/prettier/vim-prettier/issues/339) 21 | - The same prettier doesn't work correctly on WSL [\#338](https://github.com/prettier/vim-prettier/issues/338) 22 | - Cursor position lost when multiple panes open on same buffer [\#318](https://github.com/prettier/vim-prettier/issues/318) 23 | - Formating of an object removes " from some keys [\#312](https://github.com/prettier/vim-prettier/issues/312) 24 | - Add svelte support [\#303](https://github.com/prettier/vim-prettier/issues/303) 25 | - issue with installing plugin [\#288](https://github.com/prettier/vim-prettier/issues/288) 26 | - Writing a buffer prints the current line in the command line area [\#284](https://github.com/prettier/vim-prettier/issues/284) 27 | - markdown file: an unordered list and 3 spaces between dash and item [\#283](https://github.com/prettier/vim-prettier/issues/283) 28 | - Error on NeoVim nightly [\#276](https://github.com/prettier/vim-prettier/issues/276) 29 | - ftdetect collides with default filetype settings \(specifically typescriptreact or tsx\) [\#273](https://github.com/prettier/vim-prettier/issues/273) 30 | - Configuration file not loading correctly [\#269](https://github.com/prettier/vim-prettier/issues/269) 31 | - Prettier: failed to parse buffer [\#268](https://github.com/prettier/vim-prettier/issues/268) 32 | - auto save doesn't work for typescript [\#264](https://github.com/prettier/vim-prettier/issues/264) 33 | - trailing\_comma = 'es5' setting not working [\#258](https://github.com/prettier/vim-prettier/issues/258) 34 | - :Prettier fills the default register with “x” [\#244](https://github.com/prettier/vim-prettier/issues/244) 35 | 36 | **Merged pull requests:** 37 | 38 | - Fix/consider option version [\#348](https://github.com/prettier/vim-prettier/pull/348) ([victorspt](https://github.com/victorspt)) 39 | - Improve install instruction [\#316](https://github.com/prettier/vim-prettier/pull/316) ([sharils](https://github.com/sharils)) 40 | - readme: example config: autoformat on save without pragma [\#315](https://github.com/prettier/vim-prettier/pull/315) ([aaronArinder](https://github.com/aaronArinder)) 41 | - Bump ws from 5.2.2 to 5.2.3 [\#305](https://github.com/prettier/vim-prettier/pull/305) ([dependabot[bot]](https://github.com/apps/dependabot)) 42 | - feat: Adding support for prettier svelte plugin [\#304](https://github.com/prettier/vim-prettier/pull/304) ([0x000def42](https://github.com/0x000def42)) 43 | - Update prettier to latest version [\#301](https://github.com/prettier/vim-prettier/pull/301) ([fvictorio](https://github.com/fvictorio)) 44 | - enh: save buffer marks between runs [\#300](https://github.com/prettier/vim-prettier/pull/300) ([rodrigolive](https://github.com/rodrigolive)) 45 | - fix for \#287: update dependency \(prettier-php\) to fix build [\#299](https://github.com/prettier/vim-prettier/pull/299) ([laher](https://github.com/laher)) 46 | - Bump hosted-git-info from 2.8.5 to 2.8.9 [\#297](https://github.com/prettier/vim-prettier/pull/297) ([dependabot[bot]](https://github.com/apps/dependabot)) 47 | - Bump lodash from 4.17.19 to 4.17.21 [\#296](https://github.com/prettier/vim-prettier/pull/296) ([dependabot[bot]](https://github.com/apps/dependabot)) 48 | - Bump handlebars from 4.7.2 to 4.7.7 [\#295](https://github.com/prettier/vim-prettier/pull/295) ([dependabot[bot]](https://github.com/apps/dependabot)) 49 | - Bump y18n from 3.2.1 to 3.2.2 [\#291](https://github.com/prettier/vim-prettier/pull/291) ([dependabot[bot]](https://github.com/apps/dependabot)) 50 | - docs: Fixing typo in readme [\#289](https://github.com/prettier/vim-prettier/pull/289) ([rschristian](https://github.com/rschristian)) 51 | - fix incorrect reference to PrettierFragment in readme [\#286](https://github.com/prettier/vim-prettier/pull/286) ([whatever555](https://github.com/whatever555)) 52 | - Remove Pipe [\#285](https://github.com/prettier/vim-prettier/pull/285) ([wylie39](https://github.com/wylie39)) 53 | - Add dein config to readme [\#282](https://github.com/prettier/vim-prettier/pull/282) ([Chocrates](https://github.com/Chocrates)) 54 | - Autoformat MDX [\#281](https://github.com/prettier/vim-prettier/pull/281) ([roginfarrer](https://github.com/roginfarrer)) 55 | - \#273 changed tsx filetype to typescriptreact [\#279](https://github.com/prettier/vim-prettier/pull/279) ([yzia2000](https://github.com/yzia2000)) 56 | - Return cwd as default from s:ResolveExecutable [\#274](https://github.com/prettier/vim-prettier/pull/274) ([nhynes](https://github.com/nhynes)) 57 | - Stop blowing away the BufWritePre augroup in ftplugins [\#272](https://github.com/prettier/vim-prettier/pull/272) ([johanventer](https://github.com/johanventer)) 58 | - bump @prettier/plugin-php dep [\#271](https://github.com/prettier/vim-prettier/pull/271) ([hkennyv](https://github.com/hkennyv)) 59 | - fixes \#244 [\#267](https://github.com/prettier/vim-prettier/pull/267) ([okkan](https://github.com/okkan)) 60 | 61 | ## [1.0.0-beta](https://github.com/prettier/vim-prettier/tree/1.0.0-beta) (2020-09-07) 62 | 63 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/1.0.0-alpha...1.0.0-beta) 64 | 65 | **Implemented enhancements:** 66 | 67 | - Toggle autoformat feature and/or documentation [\#170](https://github.com/prettier/vim-prettier/issues/170) 68 | - 1.0 release [\#126](https://github.com/prettier/vim-prettier/issues/126) 69 | 70 | **Fixed bugs:** 71 | 72 | - formatting by saving works only for languages of last opened file [\#185](https://github.com/prettier/vim-prettier/issues/185) 73 | - bugfix/issue-229-fixing-neovim-0-4-compatibility [\#231](https://github.com/prettier/vim-prettier/pull/231) ([mitermayer](https://github.com/mitermayer)) 74 | 75 | **Closed issues:** 76 | 77 | - Support prettier-stylelint [\#255](https://github.com/prettier/vim-prettier/issues/255) 78 | - Autoformat on save does not work on yaml files [\#245](https://github.com/prettier/vim-prettier/issues/245) 79 | - PrettierFragment not work [\#241](https://github.com/prettier/vim-prettier/issues/241) 80 | - Error when running :Prettier on gvim [\#240](https://github.com/prettier/vim-prettier/issues/240) 81 | - Installation fails in post-update hook using vim plug [\#237](https://github.com/prettier/vim-prettier/issues/237) 82 | - `autoformat_config_present` does not re-evaluate the presence of the prettier config file after vim is started [\#233](https://github.com/prettier/vim-prettier/issues/233) 83 | - Add support for `prettier 2.x` [\#232](https://github.com/prettier/vim-prettier/issues/232) 84 | - PrettierAsync moves cursor to top of buffer [\#229](https://github.com/prettier/vim-prettier/issues/229) 85 | - Autoformatting Stops Working [\#228](https://github.com/prettier/vim-prettier/issues/228) 86 | - /\* prettier-ignore \*/ inside CSS file not working [\#227](https://github.com/prettier/vim-prettier/issues/227) 87 | - How do I run prettier for markdown files for Hugo the static site generator? [\#223](https://github.com/prettier/vim-prettier/issues/223) 88 | - Package.json configuration not loaded properly \(release 1.x\) [\#221](https://github.com/prettier/vim-prettier/issues/221) 89 | - TypeScript is formatted as PHP \(1.x\) [\#219](https://github.com/prettier/vim-prettier/issues/219) 90 | - How configure [\#218](https://github.com/prettier/vim-prettier/issues/218) 91 | - Error on `:wq` [\#215](https://github.com/prettier/vim-prettier/issues/215) 92 | - Bug: failed to parse buffer. [\#214](https://github.com/prettier/vim-prettier/issues/214) 93 | - release/1.x: prettier plugins do not work when installed with pnpm [\#211](https://github.com/prettier/vim-prettier/issues/211) 94 | - .prettierignore appends a bunch of nonsense [\#189](https://github.com/prettier/vim-prettier/issues/189) 95 | - Failed to parse buffer import.meta.url [\#188](https://github.com/prettier/vim-prettier/issues/188) 96 | - Document how to add q-args [\#168](https://github.com/prettier/vim-prettier/issues/168) 97 | - Document how to add custom extensions [\#167](https://github.com/prettier/vim-prettier/issues/167) 98 | - styling over scp [\#149](https://github.com/prettier/vim-prettier/issues/149) 99 | 100 | **Merged pull requests:** 101 | 102 | - Uses default cli configs [\#260](https://github.com/prettier/vim-prettier/pull/260) ([ethan605](https://github.com/ethan605)) 103 | - Add buffer-level prettier exec command to doc [\#259](https://github.com/prettier/vim-prettier/pull/259) ([jsit](https://github.com/jsit)) 104 | - Add support for buffer-level prettier\_exec\_cmd, for prettier-stylelint for instance [\#256](https://github.com/prettier/vim-prettier/pull/256) ([jsit](https://github.com/jsit)) 105 | - Bump acorn from 5.7.3 to 5.7.4 [\#254](https://github.com/prettier/vim-prettier/pull/254) ([dependabot[bot]](https://github.com/apps/dependabot)) 106 | - Bump lodash from 4.17.15 to 4.17.19 [\#253](https://github.com/prettier/vim-prettier/pull/253) ([dependabot[bot]](https://github.com/apps/dependabot)) 107 | - Fix error when quitting Neovim with :wq [\#252](https://github.com/prettier/vim-prettier/pull/252) ([mrnugget](https://github.com/mrnugget)) 108 | - Add missing ".yml" in autocmd [\#246](https://github.com/prettier/vim-prettier/pull/246) ([raxell](https://github.com/raxell)) 109 | - Fix string concatenation typo [\#243](https://github.com/prettier/vim-prettier/pull/243) ([coolreader18](https://github.com/coolreader18)) 110 | - issue/232-adding-support-for-prettier-2.x - Adding support for prettier 2x [\#238](https://github.com/prettier/vim-prettier/pull/238) ([mitermayer](https://github.com/mitermayer)) 111 | - Add instructions for installing with vim 8+ [\#236](https://github.com/prettier/vim-prettier/pull/236) ([coolaj86](https://github.com/coolaj86)) 112 | - Autoformat .rb files [\#235](https://github.com/prettier/vim-prettier/pull/235) ([jamesbvaughan](https://github.com/jamesbvaughan)) 113 | - Force reevaluation of autoformat settings at buffer write time [\#234](https://github.com/prettier/vim-prettier/pull/234) ([cjlarose](https://github.com/cjlarose)) 114 | - Fix readme to properly reflect how to downgrade [\#225](https://github.com/prettier/vim-prettier/pull/225) ([KonnorRogers](https://github.com/KonnorRogers)) 115 | - New option: prettier\#autoformat\_require\_pragma [\#224](https://github.com/prettier/vim-prettier/pull/224) ([simnalamburt](https://github.com/simnalamburt)) 116 | 117 | ## [1.0.0-alpha](https://github.com/prettier/vim-prettier/tree/1.0.0-alpha) (2020-02-05) 118 | 119 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.7...1.0.0-alpha) 120 | 121 | **Implemented enhancements:** 122 | 123 | - Add A "Close Empty JSX Element" Option Like On VS Code's Prettier [\#202](https://github.com/prettier/vim-prettier/issues/202) 124 | - Support custom prettier plugins [\#119](https://github.com/prettier/vim-prettier/issues/119) 125 | - Add support for neovim async [\#99](https://github.com/prettier/vim-prettier/issues/99) 126 | - Formatting with visual selection doesn't respect indentation [\#75](https://github.com/prettier/vim-prettier/issues/75) 127 | - Using prettier-eslint-cli [\#42](https://github.com/prettier/vim-prettier/issues/42) 128 | - Support for 'prettier-standard-formatter' [\#20](https://github.com/prettier/vim-prettier/issues/20) 129 | 130 | **Fixed bugs:** 131 | 132 | - First undo after :Prettier takes me to the top of the file [\#184](https://github.com/prettier/vim-prettier/issues/184) 133 | - Vim-prettier doesn't use project config [\#162](https://github.com/prettier/vim-prettier/issues/162) 134 | - Error infinite loop Prettier: failed to parse buffer [\#113](https://github.com/prettier/vim-prettier/issues/113) 135 | - vim-prettier not working when editing files that have white spaces on its path [\#108](https://github.com/prettier/vim-prettier/issues/108) 136 | 137 | **Closed issues:** 138 | 139 | - Bug: Bracket spacing is ignored [\#222](https://github.com/prettier/vim-prettier/issues/222) 140 | - E121: Undefined variable: g:prettier\#autoformat [\#216](https://github.com/prettier/vim-prettier/issues/216) 141 | - Plugin should load project config if available [\#213](https://github.com/prettier/vim-prettier/issues/213) 142 | - incosistent with prettier cli and introducing syntaxt error. [\#200](https://github.com/prettier/vim-prettier/issues/200) 143 | - For "in-memory" buffers \(not saved to file system\): `Prettier: failed to parse buffer` [\#199](https://github.com/prettier/vim-prettier/issues/199) 144 | - Loading global .prettierrc from user's home ? [\#197](https://github.com/prettier/vim-prettier/issues/197) 145 | - Can I automatically disable vim-prettier if .prettierrc is doesn't exists in project folder? [\#195](https://github.com/prettier/vim-prettier/issues/195) 146 | - make prettier respect eslint [\#194](https://github.com/prettier/vim-prettier/issues/194) 147 | - Window is unexpectedly scrolled after :Prettier [\#192](https://github.com/prettier/vim-prettier/issues/192) 148 | - Autoformat not working on save [\#191](https://github.com/prettier/vim-prettier/issues/191) 149 | - fail to parse buffer? [\#187](https://github.com/prettier/vim-prettier/issues/187) 150 | - Wrong parser used for markdown files [\#186](https://github.com/prettier/vim-prettier/issues/186) 151 | - No syntax color for html files when vim-prettier is enabled [\#183](https://github.com/prettier/vim-prettier/issues/183) 152 | - Error detected while processing BufWrite Auto commands for "\*.rb" [\#180](https://github.com/prettier/vim-prettier/issues/180) 153 | - Calling Prettier error if project contains prettier configuration [\#178](https://github.com/prettier/vim-prettier/issues/178) 154 | - add groovy handling [\#177](https://github.com/prettier/vim-prettier/issues/177) 155 | - on run :Prettier command weird characters added at the beginning of the file [\#174](https://github.com/prettier/vim-prettier/issues/174) 156 | - Support prettier/prettier-ruby [\#172](https://github.com/prettier/vim-prettier/issues/172) 157 | - vim-prettier clobbering markdown files [\#166](https://github.com/prettier/vim-prettier/issues/166) 158 | - How to not always auto format by default [\#164](https://github.com/prettier/vim-prettier/issues/164) 159 | - `E121: Undefined variable: g:prettier#autoformat` when executing `vi` [\#161](https://github.com/prettier/vim-prettier/issues/161) 160 | - Error parsing Typescript [\#153](https://github.com/prettier/vim-prettier/issues/153) 161 | - Restarting development from today [\#152](https://github.com/prettier/vim-prettier/issues/152) 162 | - Unexpected cursor movement [\#151](https://github.com/prettier/vim-prettier/issues/151) 163 | - Adding support for lint tools custom executables after prettier \(like lint-staged\) [\#148](https://github.com/prettier/vim-prettier/issues/148) 164 | - Prettier: failed to parse buffer. [\#147](https://github.com/prettier/vim-prettier/issues/147) 165 | - my config single\_quote is ignored [\#146](https://github.com/prettier/vim-prettier/issues/146) 166 | - Prettier: failed to parse buffer. [\#145](https://github.com/prettier/vim-prettier/issues/145) 167 | - Prettier throws an invalid expression ' --print-width ' when I run in vim [\#143](https://github.com/prettier/vim-prettier/issues/143) 168 | - Re-enable .editorconfig support [\#141](https://github.com/prettier/vim-prettier/issues/141) 169 | - saving a file ignored in .prettierignore outputs part of the file back to the buffer [\#140](https://github.com/prettier/vim-prettier/issues/140) 170 | - Prettierrc support/default usage [\#137](https://github.com/prettier/vim-prettier/issues/137) 171 | - Update DOC's and README [\#106](https://github.com/prettier/vim-prettier/issues/106) 172 | 173 | **Merged pull requests:** 174 | 175 | - Use `get()` to check `g:prettier#autoformat` safely in ftplugin [\#217](https://github.com/prettier/vim-prettier/pull/217) ([hankchiutw](https://github.com/hankchiutw)) 176 | - Toggle the autoformat setting based on config file presence. [\#212](https://github.com/prettier/vim-prettier/pull/212) ([atomdmac](https://github.com/atomdmac)) 177 | - making-auto-format-disabled-by-default - Making autoformat disabled by [\#208](https://github.com/prettier/vim-prettier/pull/208) ([mitermayer](https://github.com/mitermayer)) 178 | - Issues/184 fixing undo step [\#207](https://github.com/prettier/vim-prettier/pull/207) ([mitermayer](https://github.com/mitermayer)) 179 | - Adding support for require-pragma and depracting previous naive implemenation [\#206](https://github.com/prettier/vim-prettier/pull/206) ([mitermayer](https://github.com/mitermayer)) 180 | - moving-build-to-make-file - Adding build file [\#203](https://github.com/prettier/vim-prettier/pull/203) ([mitermayer](https://github.com/mitermayer)) 181 | - enabling-tests-on-ci - Enabling tests as part of the CI run [\#201](https://github.com/prettier/vim-prettier/pull/201) ([mitermayer](https://github.com/mitermayer)) 182 | - updating-travis-to-use-docker - Moving to use vint from docker image [\#198](https://github.com/prettier/vim-prettier/pull/198) ([mitermayer](https://github.com/mitermayer)) 183 | - Shore/master rebasing [\#196](https://github.com/prettier/vim-prettier/pull/196) ([mitermayer](https://github.com/mitermayer)) 184 | - Added some file extensions [\#193](https://github.com/prettier/vim-prettier/pull/193) ([hrkw00](https://github.com/hrkw00)) 185 | - improve Requirement's message clearness [\#190](https://github.com/prettier/vim-prettier/pull/190) ([jonathan-soifer](https://github.com/jonathan-soifer)) 186 | - Ignore generated help tags file [\#181](https://github.com/prettier/vim-prettier/pull/181) ([mikesep](https://github.com/mikesep)) 187 | - Fix README markdown. [\#179](https://github.com/prettier/vim-prettier/pull/179) ([Onra](https://github.com/Onra)) 188 | - Integrating vim driver [\#176](https://github.com/prettier/vim-prettier/pull/176) ([mitermayer](https://github.com/mitermayer)) 189 | - Release/1.x [\#175](https://github.com/prettier/vim-prettier/pull/175) ([mitermayer](https://github.com/mitermayer)) 190 | - Make markdown check more resilient [\#173](https://github.com/prettier/vim-prettier/pull/173) ([rivertam](https://github.com/rivertam)) 191 | - Fix markdown mangling issue [\#169](https://github.com/prettier/vim-prettier/pull/169) ([rivertam](https://github.com/rivertam)) 192 | - Add option for html whitespace sensitivity [\#165](https://github.com/prettier/vim-prettier/pull/165) ([dewyze](https://github.com/dewyze)) 193 | - Handle file paths with whitespace [\#163](https://github.com/prettier/vim-prettier/pull/163) ([jason0x43](https://github.com/jason0x43)) 194 | - Set default "config\_precendence" to "file-override" [\#160](https://github.com/prettier/vim-prettier/pull/160) ([shuLhan](https://github.com/shuLhan)) 195 | - Added html support using the latest prettier 1.15 version [\#159](https://github.com/prettier/vim-prettier/pull/159) ([premithk](https://github.com/premithk)) 196 | - space for --use-tabs [\#158](https://github.com/prettier/vim-prettier/pull/158) ([andreiglingeanu](https://github.com/andreiglingeanu)) 197 | - On python3.6 we dont need those extra pip deps to be declared [\#157](https://github.com/prettier/vim-prettier/pull/157) ([mitermayer](https://github.com/mitermayer)) 198 | - Fixing linting rules [\#156](https://github.com/prettier/vim-prettier/pull/156) ([mitermayer](https://github.com/mitermayer)) 199 | - Rebasing vim-prettier plugin Pull Request 120 to 1.0 branch [\#155](https://github.com/prettier/vim-prettier/pull/155) ([mitermayer](https://github.com/mitermayer)) 200 | - Add YAML support [\#150](https://github.com/prettier/vim-prettier/pull/150) ([bracki](https://github.com/bracki)) 201 | - Enable the default editorconfig support again [\#144](https://github.com/prettier/vim-prettier/pull/144) ([oskarrough](https://github.com/oskarrough)) 202 | - Fix PrettierAsync ignored file contents mangling [\#142](https://github.com/prettier/vim-prettier/pull/142) ([SamHowie](https://github.com/SamHowie)) 203 | - Remove wrong comment on README.md comment example [\#139](https://github.com/prettier/vim-prettier/pull/139) ([vieiralucas](https://github.com/vieiralucas)) 204 | - use buffered mode for neovim job [\#136](https://github.com/prettier/vim-prettier/pull/136) ([chemzqm](https://github.com/chemzqm)) 205 | - Start using prettier default arguments [\#130](https://github.com/prettier/vim-prettier/pull/130) ([docwhat](https://github.com/docwhat)) 206 | 207 | ## [0.2.7](https://github.com/prettier/vim-prettier/tree/0.2.7) (2018-05-25) 208 | 209 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.6...0.2.7) 210 | 211 | **Fixed bugs:** 212 | 213 | - Vim crashes with segmentation fault with PrettierAsync [\#135](https://github.com/prettier/vim-prettier/issues/135) 214 | - Deletes file contents of files ignored by .prettierignore [\#92](https://github.com/prettier/vim-prettier/issues/92) 215 | 216 | **Closed issues:** 217 | 218 | - Upgraded to Node v10 - Pretter:Failed to parse buffer [\#134](https://github.com/prettier/vim-prettier/issues/134) 219 | - \\(Prettier\) doesn't work [\#132](https://github.com/prettier/vim-prettier/issues/132) 220 | - Caught deadly signal SEGV when :PrettierAsync with large file [\#128](https://github.com/prettier/vim-prettier/issues/128) 221 | - bash: no job control in this shell [\#123](https://github.com/prettier/vim-prettier/issues/123) 222 | - Support for language-specific settings [\#121](https://github.com/prettier/vim-prettier/issues/121) 223 | - Can't spot why prettier fails to parse css: "1 col 6| Unexpected token, expected ;" [\#118](https://github.com/prettier/vim-prettier/issues/118) 224 | - Is there a prettier.eslintIntegration config [\#117](https://github.com/prettier/vim-prettier/issues/117) 225 | - Format without saving [\#116](https://github.com/prettier/vim-prettier/issues/116) 226 | - Error on autosave [\#114](https://github.com/prettier/vim-prettier/issues/114) 227 | - Use prettier config for formatting rules [\#112](https://github.com/prettier/vim-prettier/issues/112) 228 | - Unexpected token @ [\#109](https://github.com/prettier/vim-prettier/issues/109) 229 | - Overwrite default configs patterns not found [\#102](https://github.com/prettier/vim-prettier/issues/102) 230 | - Ignored unknown options appearing at top of file [\#100](https://github.com/prettier/vim-prettier/issues/100) 231 | - Neovim unstable async formatting bugs [\#96](https://github.com/prettier/vim-prettier/issues/96) 232 | - How do I enable trailing commas? [\#95](https://github.com/prettier/vim-prettier/issues/95) 233 | - Ignoring unknown option --loglevel, --no-editorconfig and --config-precedence [\#89](https://github.com/prettier/vim-prettier/issues/89) 234 | - Override for proseWrap option [\#88](https://github.com/prettier/vim-prettier/issues/88) 235 | 236 | **Merged pull requests:** 237 | 238 | - Fix PrettierAsync segmentation fault [\#138](https://github.com/prettier/vim-prettier/pull/138) ([SamHowie](https://github.com/SamHowie)) 239 | - Adding discord link [\#131](https://github.com/prettier/vim-prettier/pull/131) ([mitermayer](https://github.com/mitermayer)) 240 | - git: ignore unix yarn.lock file [\#129](https://github.com/prettier/vim-prettier/pull/129) ([docwhat](https://github.com/docwhat)) 241 | - Amend syntax in documentation around config overrides [\#127](https://github.com/prettier/vim-prettier/pull/127) ([chris-kobrzak](https://github.com/chris-kobrzak)) 242 | - Updating the logic for controlling the quickfix flag [\#125](https://github.com/prettier/vim-prettier/pull/125) ([mitermayer](https://github.com/mitermayer)) 243 | - doc: typo for quickfix option [\#124](https://github.com/prettier/vim-prettier/pull/124) ([docwhat](https://github.com/docwhat)) 244 | - don't change focus to the quicklist [\#122](https://github.com/prettier/vim-prettier/pull/122) ([docwhat](https://github.com/docwhat)) 245 | - Fix space in autocmd breaking autosave [\#115](https://github.com/prettier/vim-prettier/pull/115) ([LinuCC](https://github.com/LinuCC)) 246 | - Fixing empty spaces directory for async [\#111](https://github.com/prettier/vim-prettier/pull/111) ([mitermayer](https://github.com/mitermayer)) 247 | - Fix \#108 spaces in executable path problem [\#110](https://github.com/prettier/vim-prettier/pull/110) ([nelsyeung](https://github.com/nelsyeung)) 248 | - Updating docs with vue support reference [\#107](https://github.com/prettier/vim-prettier/pull/107) ([mitermayer](https://github.com/mitermayer)) 249 | - Adding vue file detect [\#105](https://github.com/prettier/vim-prettier/pull/105) ([mitermayer](https://github.com/mitermayer)) 250 | - Bumping prettier dependencie to 1.10.2 [\#104](https://github.com/prettier/vim-prettier/pull/104) ([mitermayer](https://github.com/mitermayer)) 251 | - Add vue file format to README [\#103](https://github.com/prettier/vim-prettier/pull/103) ([corburn](https://github.com/corburn)) 252 | - Support the `--arrow-parens` configuration option [\#101](https://github.com/prettier/vim-prettier/pull/101) ([nthurow](https://github.com/nthurow)) 253 | - Disabling nvim async by default under feature flag [\#98](https://github.com/prettier/vim-prettier/pull/98) ([mitermayer](https://github.com/mitermayer)) 254 | - Fixing lint [\#97](https://github.com/prettier/vim-prettier/pull/97) ([mitermayer](https://github.com/mitermayer)) 255 | - Add default option values from Prettier for configuration [\#94](https://github.com/prettier/vim-prettier/pull/94) ([maurobringolf](https://github.com/maurobringolf)) 256 | - bugfix - making sure we do not replace content with empty buffer [\#93](https://github.com/prettier/vim-prettier/pull/93) ([mitermayer](https://github.com/mitermayer)) 257 | - fix typo in pathogen install method [\#91](https://github.com/prettier/vim-prettier/pull/91) ([nicoder](https://github.com/nicoder)) 258 | - Add --prose-wrap option [\#90](https://github.com/prettier/vim-prettier/pull/90) ([frankychung](https://github.com/frankychung)) 259 | - Just a simple documentation for vim-pathogen [\#87](https://github.com/prettier/vim-prettier/pull/87) ([gustavo-gimenez](https://github.com/gustavo-gimenez)) 260 | - Add async support for neovim [\#81](https://github.com/prettier/vim-prettier/pull/81) ([chemzqm](https://github.com/chemzqm)) 261 | 262 | ## [0.2.6](https://github.com/prettier/vim-prettier/tree/0.2.6) (2017-12-08) 263 | 264 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.5...0.2.6) 265 | 266 | **Closed issues:** 267 | 268 | - Single quote option not working [\#84](https://github.com/prettier/vim-prettier/issues/84) 269 | - no semicolon not working [\#83](https://github.com/prettier/vim-prettier/issues/83) 270 | - Slow [\#82](https://github.com/prettier/vim-prettier/issues/82) 271 | 272 | **Merged pull requests:** 273 | 274 | - Bumping prettier dep to 1.9.1 [\#86](https://github.com/prettier/vim-prettier/pull/86) ([mitermayer](https://github.com/mitermayer)) 275 | - issues-83-and-84 - Fixing prettier 1.9 regression [\#85](https://github.com/prettier/vim-prettier/pull/85) ([mitermayer](https://github.com/mitermayer)) 276 | 277 | ## [0.2.5](https://github.com/prettier/vim-prettier/tree/0.2.5) (2017-11-08) 278 | 279 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.4...0.2.5) 280 | 281 | **Implemented enhancements:** 282 | 283 | - Add support for prettier 1.8 [\#77](https://github.com/prettier/vim-prettier/issues/77) 284 | 285 | **Fixed bugs:** 286 | 287 | - Prettier: failed to parse buffer. Prettier fails on css files. [\#76](https://github.com/prettier/vim-prettier/issues/76) 288 | 289 | **Closed issues:** 290 | 291 | - prepends `Ignored unknown option: --config-precedence` in buffer [\#73](https://github.com/prettier/vim-prettier/issues/73) 292 | 293 | **Merged pull requests:** 294 | 295 | - Issue 77/adding support for prettier 1.8 [\#80](https://github.com/prettier/vim-prettier/pull/80) ([mitermayer](https://github.com/mitermayer)) 296 | - issues/76 - the shellescapping util function was breaking async [\#79](https://github.com/prettier/vim-prettier/pull/79) ([mitermayer](https://github.com/mitermayer)) 297 | - Add shellescape for file path [\#74](https://github.com/prettier/vim-prettier/pull/74) ([chemzqm](https://github.com/chemzqm)) 298 | 299 | ## [0.2.4](https://github.com/prettier/vim-prettier/tree/0.2.4) (2017-10-20) 300 | 301 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.3...0.2.4) 302 | 303 | **Implemented enhancements:** 304 | 305 | - No references to getting help or support [\#67](https://github.com/prettier/vim-prettier/issues/67) 306 | 307 | **Fixed bugs:** 308 | 309 | - Incorrect resolving of prettier config [\#71](https://github.com/prettier/vim-prettier/issues/71) 310 | 311 | **Closed issues:** 312 | 313 | - SyntaxError: Unexpected token [\#69](https://github.com/prettier/vim-prettier/issues/69) 314 | 315 | **Merged pull requests:** 316 | 317 | - Fixing bug where config was not being correctly loaded based on file [\#72](https://github.com/prettier/vim-prettier/pull/72) ([mitermayer](https://github.com/mitermayer)) 318 | - Including extra information on the autoload header and doc header [\#70](https://github.com/prettier/vim-prettier/pull/70) ([mitermayer](https://github.com/mitermayer)) 319 | 320 | ## [0.2.3](https://github.com/prettier/vim-prettier/tree/0.2.3) (2017-10-08) 321 | 322 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.2...0.2.3) 323 | 324 | **Merged pull requests:** 325 | 326 | - adding suppor for vim8 versions older than 8.0.0015 to use async job API [\#66](https://github.com/prettier/vim-prettier/pull/66) ([mitermayer](https://github.com/mitermayer)) 327 | 328 | ## [0.2.2](https://github.com/prettier/vim-prettier/tree/0.2.2) (2017-10-07) 329 | 330 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.1...0.2.2) 331 | 332 | **Merged pull requests:** 333 | 334 | - Making sure we can still save the results of last prettier async run on [\#65](https://github.com/prettier/vim-prettier/pull/65) ([mitermayer](https://github.com/mitermayer)) 335 | 336 | ## [0.2.1](https://github.com/prettier/vim-prettier/tree/0.2.1) (2017-10-07) 337 | 338 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.0...0.2.1) 339 | 340 | **Fixed bugs:** 341 | 342 | - Overwrites Buffer1 with contents of Buffer2 [\#62](https://github.com/prettier/vim-prettier/issues/62) 343 | - Confused by file type overrides [\#60](https://github.com/prettier/vim-prettier/issues/60) 344 | 345 | **Merged pull requests:** 346 | 347 | - bugfix: Fixing auto command params to use extensions instead of magic [\#64](https://github.com/prettier/vim-prettier/pull/64) ([mitermayer](https://github.com/mitermayer)) 348 | - bugfix: fixing race condition incorrect buffer formating [\#63](https://github.com/prettier/vim-prettier/pull/63) ([mitermayer](https://github.com/mitermayer)) 349 | 350 | ## [0.2.0](https://github.com/prettier/vim-prettier/tree/0.2.0) (2017-10-04) 351 | 352 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.3...0.2.0) 353 | 354 | **Fixed bugs:** 355 | 356 | - `--parser` with value `postcss` is deprecated [\#59](https://github.com/prettier/vim-prettier/issues/59) 357 | 358 | **Merged pull requests:** 359 | 360 | - bug: Fixing config overwrite value for non js by levaraging --stdin-f… [\#61](https://github.com/prettier/vim-prettier/pull/61) ([mitermayer](https://github.com/mitermayer)) 361 | 362 | ## [0.1.3](https://github.com/prettier/vim-prettier/tree/0.1.3) (2017-09-30) 363 | 364 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.2...0.1.3) 365 | 366 | ## [0.1.2](https://github.com/prettier/vim-prettier/tree/0.1.2) (2017-09-26) 367 | 368 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.1...0.1.2) 369 | 370 | **Implemented enhancements:** 371 | 372 | - Allow configuration to set lookup path for `prettier` cli on `.vimrc` [\#56](https://github.com/prettier/vim-prettier/issues/56) 373 | 374 | **Merged pull requests:** 375 | 376 | - issue/56 - Allowing user path overwrite configuration [\#57](https://github.com/prettier/vim-prettier/pull/57) ([mitermayer](https://github.com/mitermayer)) 377 | - Fixed some typos in the README [\#55](https://github.com/prettier/vim-prettier/pull/55) ([Haegin](https://github.com/Haegin)) 378 | 379 | ## [0.1.1](https://github.com/prettier/vim-prettier/tree/0.1.1) (2017-09-18) 380 | 381 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.0...0.1.1) 382 | 383 | **Implemented enhancements:** 384 | 385 | - Upgrade to support prettier 1.6 [\#51](https://github.com/prettier/vim-prettier/issues/51) 386 | 387 | **Merged pull requests:** 388 | 389 | - feature: Adding more commands [\#54](https://github.com/prettier/vim-prettier/pull/54) ([mitermayer](https://github.com/mitermayer)) 390 | 391 | ## [0.1.0](https://github.com/prettier/vim-prettier/tree/0.1.0) (2017-09-14) 392 | 393 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.15...0.1.0) 394 | 395 | **Merged pull requests:** 396 | 397 | - Issue/51 adding support for prettier 1.7 [\#52](https://github.com/prettier/vim-prettier/pull/52) ([mitermayer](https://github.com/mitermayer)) 398 | 399 | ## [0.0.15](https://github.com/prettier/vim-prettier/tree/0.0.15) (2017-08-30) 400 | 401 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.14...0.0.15) 402 | 403 | **Fixed bugs:** 404 | 405 | - PrettierAsync does not work on Windows [\#46](https://github.com/prettier/vim-prettier/issues/46) 406 | 407 | **Closed issues:** 408 | 409 | - :Prettier make cursor history wrong when navigating with \ [\#48](https://github.com/prettier/vim-prettier/issues/48) 410 | 411 | **Merged pull requests:** 412 | 413 | - Making sure that after formatting we preserve in the same line [\#50](https://github.com/prettier/vim-prettier/pull/50) ([mitermayer](https://github.com/mitermayer)) 414 | - Added extensions to vim configuration example [\#49](https://github.com/prettier/vim-prettier/pull/49) ([niftylettuce](https://github.com/niftylettuce)) 415 | 416 | ## [0.0.14](https://github.com/prettier/vim-prettier/tree/0.0.14) (2017-08-24) 417 | 418 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.13...0.0.14) 419 | 420 | **Fixed bugs:** 421 | 422 | - :Prettier causes :Ggrep to lose history [\#39](https://github.com/prettier/vim-prettier/issues/39) 423 | 424 | **Closed issues:** 425 | 426 | - Trailing comma is causing issues with IE10/11 [\#45](https://github.com/prettier/vim-prettier/issues/45) 427 | 428 | **Merged pull requests:** 429 | 430 | - Async command was not working for windows this patch will make sure it [\#47](https://github.com/prettier/vim-prettier/pull/47) ([mitermayer](https://github.com/mitermayer)) 431 | - Add instructions on changing the mapping to README [\#43](https://github.com/prettier/vim-prettier/pull/43) ([eddiezane](https://github.com/eddiezane)) 432 | 433 | ## [0.0.13](https://github.com/prettier/vim-prettier/tree/0.0.13) (2017-08-13) 434 | 435 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.12...0.0.13) 436 | 437 | **Implemented enhancements:** 438 | 439 | - Include changelog [\#35](https://github.com/prettier/vim-prettier/issues/35) 440 | 441 | **Merged pull requests:** 442 | 443 | - bugfix: should not clear quickfix unless opened by vim-prettier itself [\#40](https://github.com/prettier/vim-prettier/pull/40) ([mitermayer](https://github.com/mitermayer)) 444 | 445 | ## [0.0.12](https://github.com/prettier/vim-prettier/tree/0.0.12) (2017-08-06) 446 | 447 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.11...0.0.12) 448 | 449 | **Implemented enhancements:** 450 | 451 | - Bump internal plugin dependencie to use prettier to 1.5.3 [\#34](https://github.com/prettier/vim-prettier/issues/34) 452 | - Add MIT license [\#33](https://github.com/prettier/vim-prettier/issues/33) 453 | 454 | **Closed issues:** 455 | 456 | - Unable to disable 'single-quote' [\#32](https://github.com/prettier/vim-prettier/issues/32) 457 | - "failed to parse buffer", but prettier from console works well [\#31](https://github.com/prettier/vim-prettier/issues/31) 458 | - Autoformat "all" files by default. [\#30](https://github.com/prettier/vim-prettier/issues/30) 459 | - Neovim support for job/channel to allow async formatting [\#25](https://github.com/prettier/vim-prettier/issues/25) 460 | 461 | **Merged pull requests:** 462 | 463 | - Adding changelog file [\#38](https://github.com/prettier/vim-prettier/pull/38) ([mitermayer](https://github.com/mitermayer)) 464 | - Adding MIT license [\#37](https://github.com/prettier/vim-prettier/pull/37) ([mitermayer](https://github.com/mitermayer)) 465 | - Bumping prettier internal dependencie plugin to 1.5.3 [\#36](https://github.com/prettier/vim-prettier/pull/36) ([mitermayer](https://github.com/mitermayer)) 466 | 467 | ## [0.0.11](https://github.com/prettier/vim-prettier/tree/0.0.11) (2017-07-12) 468 | 469 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.10...0.0.11) 470 | 471 | **Fixed bugs:** 472 | 473 | - Json parser should not include comma at the end [\#26](https://github.com/prettier/vim-prettier/issues/26) 474 | 475 | **Merged pull requests:** 476 | 477 | - adding-support-for-vim7 - adding support for vim7 [\#29](https://github.com/prettier/vim-prettier/pull/29) ([mitermayer](https://github.com/mitermayer)) 478 | 479 | ## [0.0.10](https://github.com/prettier/vim-prettier/tree/0.0.10) (2017-07-02) 480 | 481 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.9...0.0.10) 482 | 483 | **Implemented enhancements:** 484 | 485 | - should support filetype detection when none is available [\#23](https://github.com/prettier/vim-prettier/issues/23) 486 | 487 | ## [0.0.9](https://github.com/prettier/vim-prettier/tree/0.0.9) (2017-07-01) 488 | 489 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.8...0.0.9) 490 | 491 | **Implemented enhancements:** 492 | 493 | - bump plugin dependency to prettier 1.5 [\#22](https://github.com/prettier/vim-prettier/issues/22) 494 | - add support for GraphQL parsing [\#21](https://github.com/prettier/vim-prettier/issues/21) 495 | 496 | **Merged pull requests:** 497 | 498 | - feature/add-filetype-support - Adding filetype detection support when [\#24](https://github.com/prettier/vim-prettier/pull/24) ([mitermayer](https://github.com/mitermayer)) 499 | 500 | ## [0.0.8](https://github.com/prettier/vim-prettier/tree/0.0.8) (2017-06-30) 501 | 502 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.7...0.0.8) 503 | 504 | **Implemented enhancements:** 505 | 506 | - Partial formatting support [\#14](https://github.com/prettier/vim-prettier/issues/14) 507 | 508 | **Closed issues:** 509 | 510 | - prettier add extra comma at the last parameter of function [\#18](https://github.com/prettier/vim-prettier/issues/18) 511 | 512 | **Merged pull requests:** 513 | 514 | - Add JSON/GraphQL parser \(prettier 1.5\) [\#17](https://github.com/prettier/vim-prettier/pull/17) ([vutran](https://github.com/vutran)) 515 | - Fix default settings [\#16](https://github.com/prettier/vim-prettier/pull/16) ([vutran](https://github.com/vutran)) 516 | 517 | ## [0.0.7](https://github.com/prettier/vim-prettier/tree/0.0.7) (2017-06-20) 518 | 519 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.6...0.0.7) 520 | 521 | **Merged pull requests:** 522 | 523 | - feature: enabling partial buffer conversion [\#15](https://github.com/prettier/vim-prettier/pull/15) ([mitermayer](https://github.com/mitermayer)) 524 | - fixed typo [\#13](https://github.com/prettier/vim-prettier/pull/13) ([casprwang](https://github.com/casprwang)) 525 | 526 | ## [0.0.6](https://github.com/prettier/vim-prettier/tree/0.0.6) (2017-06-07) 527 | 528 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.5...0.0.6) 529 | 530 | **Merged pull requests:** 531 | 532 | - Adding async command and configuration controls [\#12](https://github.com/prettier/vim-prettier/pull/12) ([mitermayer](https://github.com/mitermayer)) 533 | 534 | ## [0.0.5](https://github.com/prettier/vim-prettier/tree/0.0.5) (2017-06-06) 535 | 536 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.4...0.0.5) 537 | 538 | **Implemented enhancements:** 539 | 540 | - Populate quickfix with prettier parsing errors [\#5](https://github.com/prettier/vim-prettier/issues/5) 541 | 542 | **Merged pull requests:** 543 | 544 | - Bumping support to latest prettier ^1.4.X and enabling support for [\#11](https://github.com/prettier/vim-prettier/pull/11) ([mitermayer](https://github.com/mitermayer)) 545 | 546 | ## [0.0.4](https://github.com/prettier/vim-prettier/tree/0.0.4) (2017-05-31) 547 | 548 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.3...0.0.4) 549 | 550 | **Fixed bugs:** 551 | 552 | - Prettier CLI expects params 'false' instead of 0 [\#9](https://github.com/prettier/vim-prettier/issues/9) 553 | 554 | ## [0.0.3](https://github.com/prettier/vim-prettier/tree/0.0.3) (2017-05-28) 555 | 556 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.2...0.0.3) 557 | 558 | **Implemented enhancements:** 559 | 560 | - Make the prettier command run async [\#4](https://github.com/prettier/vim-prettier/issues/4) 561 | 562 | **Fixed bugs:** 563 | 564 | - Fallback plugins not working [\#7](https://github.com/prettier/vim-prettier/issues/7) 565 | 566 | **Merged pull requests:** 567 | 568 | - Prettier CLI seems to expect 'false' for some parameters instead of 0 [\#10](https://github.com/prettier/vim-prettier/pull/10) ([mitermayer](https://github.com/mitermayer)) 569 | - bugfix: fixing bug where prettier installation of the plugin was never [\#8](https://github.com/prettier/vim-prettier/pull/8) ([mitermayer](https://github.com/mitermayer)) 570 | - Adding support for async formating and making it default for autosave [\#6](https://github.com/prettier/vim-prettier/pull/6) ([mitermayer](https://github.com/mitermayer)) 571 | 572 | ## [0.0.2](https://github.com/prettier/vim-prettier/tree/0.0.2) (2017-05-26) 573 | 574 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.1...0.0.2) 575 | 576 | **Fixed bugs:** 577 | 578 | - Should not overwrite buffer when prettier fails to parse file [\#2](https://github.com/prettier/vim-prettier/issues/2) 579 | 580 | **Merged pull requests:** 581 | 582 | - bugfix: Making sure that when prettier fail to parse buffer we do not [\#3](https://github.com/prettier/vim-prettier/pull/3) ([mitermayer](https://github.com/mitermayer)) 583 | - Adding working example GIF [\#1](https://github.com/prettier/vim-prettier/pull/1) ([mitermayer](https://github.com/mitermayer)) 584 | 585 | ## [0.0.1](https://github.com/prettier/vim-prettier/tree/0.0.1) (2017-05-24) 586 | 587 | [Full Changelog](https://github.com/prettier/vim-prettier/compare/a53ffa1ba81c76d0b2c29afe55ab131c6cc9a0e3...0.0.1) 588 | 589 | 590 | 591 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 592 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.8 as builder 2 | 3 | WORKDIR /tmp 4 | 5 | RUN apk add --no-cache \ 6 | build-base \ 7 | ctags \ 8 | git \ 9 | libx11-dev \ 10 | libxpm-dev \ 11 | libxt-dev \ 12 | libxtst-dev \ 13 | make \ 14 | ncurses-dev \ 15 | python3 \ 16 | python3-dev \ 17 | perl-dev \ 18 | ruby-dev 19 | 20 | RUN git clone https://github.com/vim/vim && cd vim \ 21 | && ./configure \ 22 | --with-features=huge \ 23 | --with-x \ 24 | --with-compiledby=mitermayer.reis@gmail.com \ 25 | && make install 26 | 27 | FROM testbed/vim:latest 28 | 29 | COPY --from=builder /usr/local/bin /usr/local/bin 30 | COPY --from=builder /usr/local/share/vim /usr/local/share/vim 31 | 32 | # install pip 33 | ENV PACKAGES="\ 34 | bash \ 35 | git \ 36 | ruby \ 37 | ruby-dev \ 38 | ruby-json \ 39 | python \ 40 | python3 \ 41 | py-pip \ 42 | nodejs \ 43 | npm \ 44 | libxt \ 45 | libx11 \ 46 | " 47 | 48 | RUN apk --update add $PACKAGES && \ 49 | rm -rf /var/cache/apk/* /tmp/* /var/tmp/* 50 | 51 | # install supported vim8 and neovim 52 | RUN install_vim -tag v7.4.052 -name vim7 -build \ 53 | -tag v8.1.0519 -name vim8 -build \ 54 | -tag neovim:v0.4.3 -name neovim -build 55 | 56 | # set default vim install 57 | RUN cp /vim-build/bin/vim8 /usr/local/bin/vim 58 | 59 | # upgrade node and yarn 60 | RUN npm install -g npm yarn 61 | 62 | # copy vimrc 63 | ADD tests/vimrc /root/.vimrc 64 | 65 | # install vint 66 | RUN pip install typing>=4.6.2 pathlib==1.0.1 enum34>=1.0.4 vim-vint==0.3.19 67 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Mitermayer Reis 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME=vim-prettier 2 | 3 | VERSION=1.0.0 4 | 5 | build: 6 | docker build -t mitermayer/vim-test-bed . 7 | 8 | test: 9 | echo "Running tests..." 10 | docker run \ 11 | -t \ 12 | --rm \ 13 | -v ${PWD}:/testplugin \ 14 | -v ${PWD}/tests:/home \ 15 | "mitermayer/vim-test-bed" \ 16 | yarn --cwd testplugin test 17 | 18 | test-update-snapshot: 19 | echo "Running tests..." 20 | docker run \ 21 | -t \ 22 | --rm \ 23 | -v ${PWD}:/testplugin \ 24 | -v ${PWD}/tests:/home \ 25 | "mitermayer/vim-test-bed" \ 26 | yarn --cwd testplugin test -u 27 | 28 | lint: 29 | echo "Running linter..." 30 | docker run \ 31 | -t \ 32 | --rm \ 33 | -v ${PWD}:/testplugin \ 34 | -v ${PWD}/tests:/home \ 35 | "mitermayer/vim-test-bed" \ 36 | yarn --cwd testplugin lint 37 | 38 | tag: 39 | git tag $(VERSION) 40 | 41 | chroot: 42 | docker run \ 43 | -it \ 44 | -v ${PWD}:/testplugin \ 45 | -v ${PWD}/tests:/home \ 46 | "mitermayer/vim-test-bed" \ 47 | bash 48 | 49 | run: 50 | docker run \ 51 | -it \ 52 | -v ${PWD}:/testplugin \ 53 | -v ${PWD}/tests:/home \ 54 | "mitermayer/vim-test-bed" \ 55 | ${VIM_VERSION} -u /home/vimrc 56 | 57 | changelog: 58 | docker run -it --rm -v "${PWD}":/usr/local/src/your-app ferrarimarco/github-changelog-generator -u prettier -p vim-prettier -t ${GITHUB_REPO_READ_TOKEN} 59 | 60 | release: 61 | git push --tags 62 | 63 | .PHONY: build test lint tag chroot run changelog release 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## vim-prettier 2 | 3 | A vim plugin wrapper for prettier, pre-configured with custom default prettier 4 | settings. 5 | 6 | --- 7 | 8 | **NOTE**: If you want to fallback to older version of prettier/vim-prettier please add this to your `.vimrc`: 9 | 10 | ```vim 11 | Plug 'prettier/vim-prettier', { 12 | \ 'do': 'yarn install --frozen-lockfile --production', 13 | \ 'branch': 'release/0.x' 14 | \ } 15 | ``` 16 | 17 | --- 18 | 19 | By default it will auto format **javascript**, **typescript**, **less**, 20 | **scss**, **css**, **json**, **graphql** and **markdown** files if they 21 | have/support the "@format" pragma annotation in the header of the file. 22 | 23 | ![vim-prettier](/media/vim-prettier.gif?raw=true 'vim-prettier') 24 | 25 | ### INSTALL 26 | 27 | To install with vim 8+ plugins, simply clone to your `~/.vim/pack/plugins/start` directory, and add `packloadall` to your `.vimrc` (if you haven't already). 28 | 29 | ```bash 30 | mkdir -p ~/.vim/pack/plugins/start 31 | git clone https://github.com/prettier/vim-prettier ~/.vim/pack/plugins/start/vim-prettier 32 | ``` 33 | 34 | `.vimrc`: 35 | ```vim 36 | packloadall 37 | ``` 38 | 39 | Install with [vim-plug](https://github.com/junegunn/vim-plug), assumes node and 40 | yarn|npm installed globally. 41 | 42 | ```vim 43 | " post install (yarn install | npm install) then load plugin only for editing supported files 44 | Plug 'prettier/vim-prettier', { 45 | \ 'do': 'yarn install --frozen-lockfile --production', 46 | \ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'svelte', 'yaml', 'html'] } 47 | ``` 48 | 49 | or simply enable for all formats by: 50 | 51 | ```vim 52 | " post install (yarn install | npm install) then load plugin only for editing supported files 53 | Plug 'prettier/vim-prettier', { 'do': 'yarn install --frozen-lockfile --production' } 54 | ``` 55 | 56 | For those using [vim-pathogen](https://github.com/tpope/vim-pathogen), you can run the following in a terminal: 57 | 58 | ``` 59 | cd ~/.vim/bundle 60 | git clone https://github.com/prettier/vim-prettier 61 | ``` 62 | 63 | If using [dein](https://github.com/Shougo/dein.vim), add the following to your dein config: 64 | 65 | ```vim 66 | call dein#add('prettier/vim-prettier', {'build': 'npm install'}) 67 | ``` 68 | 69 | If using other vim plugin managers or doing manual setup make sure to have 70 | `prettier` installed globally or go to your vim-prettier directory and either do 71 | `npm install` or `yarn install --frozen-lockfile` 72 | 73 | ### Prettier Executable resolution 74 | 75 | When installed via vim-plug, a default prettier executable is installed inside 76 | vim-prettier. 77 | 78 | vim-prettier executable resolution: 79 | 80 | 1. Look for user defined prettier cli path from vim configuration file 81 | 2. Traverse parents and search for Prettier installation inside `node_modules` 82 | 3. Look for a global prettier installation 83 | 4. Use locally installed vim-prettier prettier executable 84 | 85 | ### Prettier Stylelint 86 | 87 | To use an alternative command, like 88 | [`prettier-stylelint`](https://github.com/hugomrdias/prettier-stylelint), set 89 | this at the buffer level, e.g.: 90 | 91 | ```vim 92 | au FileType css,scss let b:prettier_exec_cmd = "prettier-stylelint" 93 | ``` 94 | 95 | vim-prettier will look for the executable in the same places it looks for 96 | `prettier`, and will fall back to `prettier` if it can't find 97 | `b:prettier_exec_cmd` 98 | 99 | ### USAGE 100 | 101 | Prettier by default will run on auto save but can also be manually triggered by: 102 | 103 | ```vim 104 | p 105 | ``` 106 | 107 | or 108 | 109 | ```vim 110 | :Prettier 111 | ``` 112 | 113 | If your are on vim 8+ you can also trigger async formatting by: 114 | 115 | ```vim 116 | :PrettierAsync 117 | ``` 118 | 119 | You can send to prettier your entire buffer but ensure that it formats only your selection. 120 | 121 | **note:** differs from `:PrettierFragment` by sending the entire buffer to prettier, allowing identation level to be preserved, but it requires the whole file to be valid. 122 | 123 | ```vim 124 | :PrettierPartial 125 | ``` 126 | 127 | You can send to prettier your current selection as a fragment of same type as the file being edited. 128 | 129 | **note:** differs from `:PrettierPartial` by sending only the current selection to prettier, this allows for faster formatting but wont preserve indentation. 130 | 131 | ```vim 132 | :PrettierFragment 133 | ``` 134 | 135 | You can check what is the `vim-prettier` plugin version by: 136 | 137 | ```vim 138 | :PrettierVersion 139 | ``` 140 | 141 | You can send commands to the resolved `prettier` cli by: 142 | 143 | ``` 144 | :PrettierCli 145 | ``` 146 | 147 | You can check what is the resolved `prettier` cli path by: 148 | 149 | ```vim 150 | :PrettierCliPath 151 | ``` 152 | 153 | You can check what is the resolved `prettier` cli version by: 154 | 155 | ```vim 156 | :PrettierCliVersion 157 | ``` 158 | 159 | ### Configuration 160 | 161 | Change the mapping to run from the default of `p` 162 | 163 | ```vim 164 | nmap py (Prettier) 165 | ``` 166 | 167 | Enable auto formatting of files that have "@format" or "@prettier" tag 168 | 169 | ```vim 170 | let g:prettier#autoformat = 1 171 | ``` 172 | 173 | Allow auto formatting for files without "@format" or "@prettier" tag 174 | 175 | ```vim 176 | let g:prettier#autoformat_require_pragma = 0 177 | ``` 178 | 179 | **NOTE** The previous two options can be used together for autoformatting files on save without `@format` or `@prettier` tags 180 | 181 | ```vim 182 | let g:prettier#autoformat = 1 183 | let g:prettier#autoformat_require_pragma = 0 184 | ``` 185 | 186 | Toggle the `g:prettier#autoformat` setting based on whether a config file can be found in the current directory or any parent directory. Note that this will override the `g:prettier#autoformat` setting! 187 | 188 | ```vim 189 | let g:prettier#autoformat_config_present = 1 190 | ``` 191 | 192 | A list containing all config file names to search for when using the `g:prettier#autoformat_config_present` option. 193 | 194 | ```vim 195 | let g:prettier#autoformat_config_files = [...] 196 | ``` 197 | 198 | Set the prettier CLI executable path 199 | 200 | ```vim 201 | let g:prettier#exec_cmd_path = "~/path/to/cli/prettier" 202 | ``` 203 | 204 | The command `:Prettier` by default is synchronous but can also be forced async 205 | 206 | ```vim 207 | let g:prettier#exec_cmd_async = 1 208 | ``` 209 | 210 | By default parsing errors will open the quickfix but can also be disabled 211 | 212 | ```vim 213 | let g:prettier#quickfix_enabled = 0 214 | ``` 215 | 216 | By default selection formatting will be running `:PrettierFragment` but we can set 217 | `:PrettierPartial` as the default selection formatting by: 218 | 219 | ```vim 220 | let g:prettier#partial_format=1 221 | ``` 222 | 223 | By default we auto focus on the quickfix when there are errors but can also be disabled 224 | 225 | ```vim 226 | let g:prettier#quickfix_auto_focus = 0 227 | ``` 228 | 229 | To run vim-prettier not only before saving, but also after changing text or leaving insert mode: 230 | 231 | ```vim 232 | " when running at every change you may want to disable quickfix 233 | let g:prettier#quickfix_enabled = 0 234 | 235 | autocmd TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html PrettierAsync 236 | ``` 237 | 238 | ### Overwrite default prettier configuration 239 | 240 | **Note:** vim-prettier default settings differ from prettier intentionally. 241 | However they can be configured by: 242 | 243 | ```vim 244 | " Max line length that prettier will wrap on: a number or 'auto' (use 245 | " textwidth). 246 | " default: 'auto' 247 | let g:prettier#config#print_width = 'auto' 248 | 249 | " number of spaces per indentation level: a number or 'auto' (use 250 | " softtabstop) 251 | " default: 'auto' 252 | let g:prettier#config#tab_width = 'auto' 253 | 254 | " use tabs instead of spaces: true, false, or auto (use the expandtab setting). 255 | " default: 'auto' 256 | let g:prettier#config#use_tabs = 'auto' 257 | 258 | " flow|babylon|typescript|css|less|scss|json|graphql|markdown or empty string 259 | " (let prettier choose). 260 | " default: '' 261 | let g:prettier#config#parser = '' 262 | 263 | " cli-override|file-override|prefer-file 264 | " default: 'file-override' 265 | let g:prettier#config#config_precedence = 'file-override' 266 | 267 | " always|never|preserve 268 | " default: 'preserve' 269 | let g:prettier#config#prose_wrap = 'preserve' 270 | 271 | " css|strict|ignore 272 | " default: 'css' 273 | let g:prettier#config#html_whitespace_sensitivity = 'css' 274 | 275 | " false|true 276 | " default: 'false' 277 | let g:prettier#config#require_pragma = 'false' 278 | 279 | " Define the flavor of line endings 280 | " lf|crlf|cr|all 281 | " defaut: 'lf' 282 | let g:prettier#config#end_of_line = get(g:, 'prettier#config#end_of_line', 'lf') 283 | ``` 284 | 285 | ### REQUIREMENT(S) 286 | 287 | If the `prettier` executable can't be found by Vim, no code formatting will happen 288 | -------------------------------------------------------------------------------- /autoload/prettier.vim: -------------------------------------------------------------------------------- 1 | " vim-prettier: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings. 2 | " 3 | " Script Info {{{ 4 | "========================================================================================================== 5 | " Name Of File: prettier.vim 6 | " Description: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings. 7 | " Maintainer: Mitermayer Reis 8 | " Version: 1.0.0 9 | " Usage: Use :help vim-prettier-usage, or visit https://github.com/prettier/vim-prettier 10 | " 11 | "========================================================================================================== 12 | " }}} 13 | 14 | " Displays the resolve prettier CLI path 15 | function! prettier#PrettierCliPath() abort 16 | let l:execCmd = prettier#resolver#executable#getPath() 17 | 18 | if l:execCmd != -1 19 | echom l:execCmd 20 | else 21 | call prettier#logging#error#log('EXECUTABLE_NOT_FOUND_ERROR') 22 | endif 23 | endfunction 24 | 25 | " Allows user commands to be passed straight to the prettier CLI 26 | function! prettier#PrettierCli(user_input) abort 27 | let l:execCmd = prettier#resolver#executable#getPath() 28 | 29 | if l:execCmd != -1 30 | let l:out = system(l:execCmd. ' ' . a:user_input) 31 | echom l:out 32 | else 33 | call prettier#logging#error#log('EXECUTABLE_NOT_FOUND_ERROR') 34 | endif 35 | endfunction 36 | 37 | " Allows @format and @prettier pragma support upon saving 38 | function! prettier#Autoformat(...) abort 39 | let l:autoformat = g:prettier#autoformat_config_present ? 40 | \ prettier#IsConfigPresent(g:prettier#autoformat_config_files) : 41 | \ g:prettier#autoformat 42 | 43 | if l:autoformat 44 | call prettier#Prettier(1, 1, line('$'), 0, { 45 | \ 'requirePragma': g:prettier#autoformat_require_pragma ? 'true' : 'false' 46 | \ }) 47 | endif 48 | endfunction 49 | 50 | " Main prettier command 51 | function! prettier#Prettier(...) abort 52 | let l:execCmd = prettier#resolver#executable#getPath() 53 | let l:async = a:0 > 0 ? a:1 : 0 54 | let l:startSelection = a:0 > 1 ? a:2 : 1 55 | let l:endSelection = a:0 > 2 ? a:3 : line('$') 56 | let l:hasSelection = a:0 > 2 ? 1 : 0 57 | let l:partialFormat = a:0 > 3 && a:4 ? a:4 : 0 58 | let l:partialFormatEnabled = l:hasSelection && l:partialFormat 59 | 60 | let l:overWrite = a:0 > 4 ? a:5 : {} 61 | let l:bufferConfig = getbufvar(bufnr('%'), 'prettier_ft_default_args', {}) 62 | let l:config = extend(l:bufferConfig, l:overWrite) 63 | 64 | if l:execCmd != -1 65 | " TODO 66 | " => we should make sure we can resolve --range-start and --range-end when required 67 | " => when the above is required we should also update l:startSelection to '1' and l:endSelection to line('$') 68 | let l:cmd = l:execCmd . prettier#resolver#config#resolve( 69 | \ prettier#resolver#preset#resolve(l:config), 70 | \ l:partialFormatEnabled, 71 | \ l:startSelection, 72 | \ l:endSelection) 73 | 74 | " close quickfix if it is opened 75 | call prettier#utils#quickfix#close() 76 | 77 | " we will be using portion formatting, so we need to send entire buffer to prettier 78 | if l:partialFormatEnabled 79 | let l:startSelection = 1 80 | let l:endSelection = line('$') 81 | endif 82 | 83 | " format buffer 84 | call prettier#job#runner#run(l:cmd, l:startSelection, l:endSelection, l:async) 85 | else 86 | call prettier#logging#error#log('EXECUTABLE_NOT_FOUND_ERROR') 87 | endif 88 | endfunction 89 | 90 | " Set autoformat toggle based on whether config file was found. 91 | function! prettier#IsConfigPresent(config_files) abort 92 | for config_file in a:config_files 93 | if filereadable(findfile(config_file, '.;')) 94 | return 1 95 | endif 96 | endfor 97 | return 0 98 | endfunction 99 | -------------------------------------------------------------------------------- /autoload/prettier/bridge/parser.vim: -------------------------------------------------------------------------------- 1 | " TODO 2 | " this function should just returns the parsed errors list instead 3 | " of opening the quickfix 4 | function! prettier#bridge#parser#onError(out, autoFocus) abort 5 | let l:errors = [] 6 | 7 | for l:line in a:out 8 | " matches: 9 | " file.ext: SyntaxError: Unexpected token (2:8)sd 10 | " stdin: SyntaxError: Unexpected token (2:8) 11 | " [error] file.ext: SyntaxError: Unexpected token (2:8) 12 | let l:match = matchlist(l:line, '^.*: \(.*\) (\(\d\{1,}\):\(\d\{1,}\)*)') 13 | if !empty(l:match) 14 | call add(l:errors, { 'bufnr': bufnr('%'), 15 | \ 'text': l:match[1], 16 | \ 'lnum': l:match[2], 17 | \ 'col': l:match[3] }) 18 | endif 19 | endfor 20 | 21 | if len(l:errors) 22 | call prettier#utils#quickfix#open(l:errors, a:autoFocus) 23 | endif 24 | endfunction 25 | -------------------------------------------------------------------------------- /autoload/prettier/job/async/neovim.vim: -------------------------------------------------------------------------------- 1 | let s:prettier_job_running = 0 2 | 3 | function! prettier#job#async#neovim#run(cmd, startSelection, endSelection) abort 4 | if s:prettier_job_running == 1 5 | return 6 | endif 7 | let s:prettier_job_running = 1 8 | 9 | let l:lines = getline(a:startSelection, a:endSelection) 10 | let l:dict = { 11 | \ 'start': a:startSelection - 1, 12 | \ 'end': a:endSelection, 13 | \ 'buf_nr': bufnr('%'), 14 | \ 'content': l:lines, 15 | \} 16 | let l:out = [] 17 | let l:err = [] 18 | 19 | let l:job = jobstart([&shell, &shellcmdflag, a:cmd], { 20 | \ 'stdout_buffered': 1, 21 | \ 'stderr_buffered': 1, 22 | \ 'on_stdout': {job_id, data, event -> extend(l:out, data)}, 23 | \ 'on_stderr': {job_id, data, event -> extend(l:err, data)}, 24 | \ 'on_exit': {job_id, status, event -> s:onExit(status, l:dict, l:out, l:err)}, 25 | \ }) 26 | call jobsend(l:job, l:lines) 27 | call jobclose(l:job, 'stdin') 28 | endfunction 29 | 30 | " todo 31 | " Lets refactor this onExit to work similar to our solution for vim8 32 | " at the moment an info json object is been passed with some cached data 33 | " that is than used to do the formatting, its not following the same convetion 34 | " as the vim8 one and is error prone 35 | " 36 | " we should: 37 | " 38 | " 1. make it similar to the vim8 approach 39 | " 2. extract common functionality either above to the runner or to some other module 40 | " 41 | " to test this it rellies on using nvim and having the flag 42 | " 43 | " note that somehow we exectuing both async and sync on nvim when using the autoformat 44 | function! s:onExit(status, info, out, err) abort 45 | if len(a:out) == 0 | return | endif 46 | 47 | let l:currentBufferNumber = bufnr('%') 48 | let l:isInsideAnotherBuffer = a:info.buf_nr != l:currentBufferNumber ? 1 : 0 49 | let l:last = a:out[len(a:out) - 1] 50 | let l:out = l:last ==? '' ? a:out[0:len(a:out) - 2] : a:out 51 | 52 | " parsing errors 53 | if a:status != 0 54 | call prettier#job#runner#onError(a:err) 55 | let s:prettier_job_running = 0 56 | return 57 | endif 58 | 59 | " we have no prettier output so lets exit 60 | if len(l:out) == 0 | return | endif 61 | 62 | " nothing to update 63 | if (prettier#utils#buffer#willUpdatedLinesChangeBuffer(l:out, a:info.start, a:info.end) == 0) 64 | let s:prettier_job_running = 0 65 | redraw! 66 | return 67 | endif 68 | 69 | " This is required due to race condition when user quickly switch buffers while the async 70 | " cli has not finished running, vim 8.0.1039 has introduced setbufline() which can be used 71 | " to fix this issue in a cleaner way, however since we still need to support older vim versions 72 | " we will apply a more generic solution 73 | if (l:isInsideAnotherBuffer) 74 | " Do no try to format buffers that have been closed 75 | if (bufloaded(a:info.buf_nr)) 76 | try 77 | silent exec 'sp '. escape(bufname(a:info.buf_nr), ' \') 78 | call prettier#utils#buffer#replaceAndSave(l:out, a:info.start, a:info.end) 79 | catch 80 | call prettier#logging#error#log('PARSING_ERROR') 81 | finally 82 | " we should then hide this buffer again 83 | if a:info.buf_nr == bufnr('%') 84 | silent hide 85 | endif 86 | endtry 87 | endif 88 | else 89 | call prettier#utils#buffer#replaceAndSave(l:out, a:info.start, a:info.end) 90 | endif 91 | let s:prettier_job_running = 0 92 | endfunction 93 | -------------------------------------------------------------------------------- /autoload/prettier/job/async/vim.vim: -------------------------------------------------------------------------------- 1 | let s:prettier_job_running = 0 2 | 3 | function! prettier#job#async#vim#run(cmd, startSelection, endSelection) abort 4 | if s:prettier_job_running == 1 5 | return 6 | endif 7 | let s:prettier_job_running = 1 8 | 9 | let l:bufferName = bufname('%') 10 | 11 | let l:job = job_start([&shell, &shellcmdflag, a:cmd], { 12 | \ 'out_io': 'buffer', 13 | \ 'err_cb': {channel, msg -> s:onError(msg)}, 14 | \ 'close_cb': {channel -> s:onClose(channel, a:startSelection, a:endSelection, l:bufferName)}}) 15 | 16 | let l:stdin = job_getchannel(l:job) 17 | 18 | call ch_sendraw(l:stdin, join(getbufline(bufnr(l:bufferName), a:startSelection, a:endSelection), "\n")) 19 | call ch_close_in(l:stdin) 20 | endfunction 21 | 22 | function! s:onError(msg) abort 23 | call prettier#job#runner#onError(split(a:msg, '\n')) 24 | let s:prettier_job_running = 0 25 | endfunction 26 | 27 | function! s:onClose(channel, startSelection, endSelection, bufferName) abort 28 | let l:out = [] 29 | let l:currentBufferName = bufname('%') 30 | let l:isInsideAnotherBuffer = a:bufferName != l:currentBufferName ? 1 : 0 31 | 32 | let l:buff = ch_getbufnr(a:channel, 'out') 33 | let l:out = getbufline(l:buff, 2, '$') 34 | execute 'bd!' . l:buff 35 | 36 | " we have no prettier output so lets exit 37 | if len(l:out) == 0 | return | endif 38 | 39 | " nothing to update 40 | if (prettier#utils#buffer#willUpdatedLinesChangeBuffer(l:out, a:startSelection, a:endSelection) == 0) 41 | let s:prettier_job_running = 0 42 | redraw! 43 | return 44 | endif 45 | 46 | " This is required due to race condition when user quickly switch buffers while the async 47 | " cli has not finished running, vim 8.0.1039 has introduced setbufline() which can be used 48 | " to fix this issue in a cleaner way, however since we still need to support older vim versions 49 | " we will apply a more generic solution 50 | if (l:isInsideAnotherBuffer) 51 | " Do no try to format buffers that have been closed 52 | if (bufloaded(str2nr(a:bufferName))) 53 | try 54 | silent exec 'sp '. escape(bufname(bufnr(a:bufferName)), ' \') 55 | call prettier#utils#buffer#replaceAndSave(l:out, a:startSelection, a:endSelection) 56 | catch 57 | call prettier#logging#error#log('PARSING_ERROR', a:bufferName) 58 | finally 59 | " we should then hide this buffer again 60 | if a:bufferName == bufname('%') 61 | silent hide 62 | endif 63 | endtry 64 | endif 65 | else 66 | call prettier#utils#buffer#replaceAndSave(l:out, a:startSelection, a:endSelection) 67 | endif 68 | let s:prettier_job_running = 0 69 | endfunction 70 | -------------------------------------------------------------------------------- /autoload/prettier/job/runner.vim: -------------------------------------------------------------------------------- 1 | " TODO 2 | " move the bellow vim checks to UTILS 3 | let s:isLegacyVim = v:version < 800 4 | let s:isNeoVim = has('nvim') 5 | let s:isAsyncVim = !s:isLegacyVim && exists('*job_start') 6 | 7 | function! prettier#job#runner#run(cmd, startSelection, endSelection, async) abort 8 | if a:async && (s:isAsyncVim || s:isNeoVim) 9 | call s:asyncFormat(a:cmd, a:startSelection, a:endSelection) 10 | else 11 | call s:format(a:cmd, a:startSelection, a:endSelection) 12 | endif 13 | endfunction 14 | 15 | function! prettier#job#runner#onError(errors) abort 16 | call prettier#logging#error#log('PARSING_ERROR') 17 | if g:prettier#quickfix_enabled 18 | call prettier#bridge#parser#onError(a:errors, g:prettier#quickfix_auto_focus) 19 | endif 20 | endfunction 21 | 22 | function! s:asyncFormat(cmd, startSelection, endSelection) abort 23 | if !s:isAsyncVim && !s:isNeoVim 24 | call s:format(a:cmd, a:startSelection, a:endSelection) 25 | endif 26 | 27 | " required for Windows support on async operations 28 | let l:cmd = a:cmd 29 | if has('win32') || has('win64') 30 | let l:cmd = 'cmd.exe /c ' . a:cmd 31 | endif 32 | 33 | if s:isAsyncVim 34 | call prettier#job#async#vim#run(l:cmd, a:startSelection, a:endSelection) 35 | else 36 | call prettier#job#async#neovim#run(l:cmd, a:startSelection, a:endSelection) 37 | endif 38 | endfunction 39 | 40 | function! s:format(cmd, startSelection, endSelection) abort 41 | let l:bufferLinesList = getbufline(bufnr('%'), a:startSelection, a:endSelection) 42 | 43 | " vim 7 does not have support for passing a list to system() 44 | let l:bufferLines = s:isLegacyVim ? join(l:bufferLinesList, "\n") : l:bufferLinesList 45 | 46 | " TODO 47 | " since we are using two different types for system, maybe we should move it to utils shims 48 | let l:out = split(system(a:cmd, l:bufferLines), '\n') 49 | 50 | " check system exit code 51 | if v:shell_error 52 | call prettier#job#runner#onError(l:out) 53 | return 54 | endif 55 | 56 | " TODO 57 | " doing 0 checks seems weird can we do this bellow differently ? 58 | if (prettier#utils#buffer#willUpdatedLinesChangeBuffer(l:out, a:startSelection, a:endSelection) == 0) 59 | return 60 | endif 61 | 62 | call prettier#utils#buffer#replace(l:out, a:startSelection, a:endSelection) 63 | endfunction 64 | -------------------------------------------------------------------------------- /autoload/prettier/logging/error.vim: -------------------------------------------------------------------------------- 1 | let s:PREFIX_MSG = 'Prettier: ' 2 | let s:ERRORS = { 3 | \ 'EXECUTABLE_NOT_FOUND_ERROR': 'no prettier executable installation found', 4 | \ 'PARSING_ERROR': 'failed to parse buffer', 5 | \ } 6 | let s:DEFAULT_ERROR = get(s:, 'PARSING_ERROR') 7 | 8 | function! prettier#logging#error#log(...) abort 9 | let l:error = a:0 > 0 ? a:1 : s:DEFAULT_ERROR 10 | let l:msg = a:0 > 1 ? ': ' . a:2 : '' 11 | echohl WarningMsg | echom s:PREFIX_MSG . get(s:ERRORS, l:error, s:DEFAULT_ERROR) . l:msg | echohl NONE 12 | endfunction 13 | -------------------------------------------------------------------------------- /autoload/prettier/presets/fb.vim: -------------------------------------------------------------------------------- 1 | " Return facebook style config overwrite presets 2 | function! prettier#presets#fb#config() abort 3 | return { 4 | \ 'bracketSpacing': 'false', 5 | \ 'jsxBracketSameLine': 'true', 6 | \ 'printWidth': 80, 7 | \ 'parser': 'flow', 8 | \ 'singleQuote': 'true', 9 | \ 'tabWidth': 2, 10 | \ 'trailingComma': 'all', 11 | \ 'useTabs': 'false', 12 | \ } 13 | endfunction 14 | -------------------------------------------------------------------------------- /autoload/prettier/resolver/config.vim: -------------------------------------------------------------------------------- 1 | " By default we will default to our internal 2 | " configuration settings for prettier 3 | function! prettier#resolver#config#resolve(config, hasSelection, start, end) abort 4 | " Allow params to be passed as json format 5 | " convert bellow usage of globals to a get function o the params defaulting to global 6 | let l:config_and_sel = { 7 | \ 'config': a:config, 8 | \ 'hasSelection': a:hasSelection, 9 | \ 'start': a:start, 10 | \ 'end': a:end} 11 | 12 | let l:cmd = ' ' . s:Get_current_version_flags(s:FLAGS) 13 | \ ->map(function('s:Map_flag_to_cmd_part', [l:config_and_sel])) 14 | \ ->values() 15 | \ ->join(' ') 16 | 17 | return l:cmd 18 | endfunction 19 | 20 | " Mapper functions: {{{ 21 | " Returns either '--range-start X' or an empty string. 22 | function! s:Flag_range_start(config_and_sel, ...) abort 23 | if (!a:config_and_sel.hasSelection) 24 | return '' 25 | endif 26 | 27 | let l:rangeStart = 28 | \ prettier#utils#buffer#getCharRangeStart(a:config_and_sel.start) 29 | 30 | return '--range-start=' . l:rangeStart 31 | endfunction 32 | 33 | " Returns either '--range-end Y' or an empty string. 34 | function! s:Flag_range_end(config_and_sel, ...) abort 35 | if (!a:config_and_sel.hasSelection) 36 | return '' 37 | endif 38 | 39 | let l:rangeEnd = 40 | \ prettier#utils#buffer#getCharRangeEnd(a:config_and_sel.end) 41 | 42 | return '--range-end=' . l:rangeEnd 43 | endfunction 44 | 45 | " Returns '--tab-width=NN' 46 | function! s:Flag_tab_width(config_and_sel, ...) abort 47 | let l:value = get( 48 | \ a:config_and_sel.config, 49 | \ 'tabWidth', 50 | \ g:prettier#config#tab_width) 51 | 52 | if (l:value ==# 'auto') 53 | let l:value = prettier#utils#shim#shiftwidth() 54 | endif 55 | 56 | return '--tab-width=' . l:value 57 | endfunction 58 | 59 | " Returns either '--use-tabs' or an empty string. 60 | function! s:Flag_use_tabs(config_and_sel, ...) abort 61 | let l:value = get( 62 | \ a:config_and_sel.config, 63 | \ 'useTabs', 64 | \ g:prettier#config#use_tabs) 65 | 66 | if (l:value ==# 'auto') 67 | let l:value = &expandtab ? 'false' : 'true' 68 | endif 69 | 70 | if ( l:value ==# 'true' ) 71 | return ' --use-tabs' 72 | else 73 | return '' 74 | endif 75 | endfunction 76 | 77 | " Returns '--print-width=NN' or '' 78 | function! s:Flag_print_width(config_and_sel, ...) abort 79 | let l:value = get( 80 | \ a:config_and_sel.config, 81 | \ 'printWidth', 82 | \ g:prettier#config#print_width) 83 | 84 | if (l:value ==# 'auto') 85 | let l:value = &textwidth 86 | endif 87 | 88 | if (l:value > 0) 89 | return '--print-width=' . l:value 90 | else 91 | return '' 92 | endif 93 | endfunction 94 | 95 | " Returns '--parser=PARSER' or '' 96 | function! s:Flag_parser(config_and_sel, ...) abort 97 | let l:value = get( 98 | \ a:config_and_sel.config, 99 | \ 'parser', 100 | \ g:prettier#config#parser) 101 | 102 | if (l:value !=# '') 103 | return '--parser=' . l:value 104 | else 105 | return '' 106 | endif 107 | endfunction 108 | 109 | " Returns '--stdin-filepath=' concatenated with the full path of the opened 110 | " file. 111 | function! s:Flag_stdin_filepath(...) abort 112 | let l:current_file = simplify(expand('%:p')) 113 | return '--stdin-filepath="' . l:current_file . '"' 114 | endfunction 115 | 116 | " Returns '--loglevel error' or '--log-level error'. 117 | function! s:Flag_loglevel(config_and_sel, flag, props) abort 118 | let l:level = 'error' 119 | return a:flag . ' ' . l:level 120 | endfunction 121 | 122 | " Returns '--stdin'. 123 | function! s:Flag_stdin(...) abort 124 | return '--stdin ' 125 | endfunction 126 | 127 | " Returns a flag name concantenated with its value in the JSON config object or 128 | " in the default global Prettier config. 129 | function! s:Concat_value_to_flag(config_and_sel, flag, props) abort 130 | let l:global_value = get(g:, 'prettier#config#' . a:props.global_name, "") 131 | 132 | let l:value = get(a:config_and_sel.config, a:props.json_name, l:global_value) 133 | 134 | return a:flag . '=' . l:value 135 | endfunction 136 | 137 | " Maps a flag name to a part of a command. 138 | function! s:Map_flag_to_cmd_part(config_and_sel, flag, props) abort 139 | return a:props.mapper(a:config_and_sel, a:flag, a:props) 140 | endfunction 141 | " }}} 142 | 143 | " Constants: {{{ 144 | let s:concat_value = function('s:Concat_value_to_flag') 145 | 146 | let s:FLAGS = { 147 | \ '--use-tabs': { 148 | \ 'json_name': 'useTabs', 149 | \ 'global_name': 'use_tabs', 150 | \ 'mapper': function('s:Flag_use_tabs')}, 151 | \ '--tab-width': { 152 | \ 'json_name': 'tabWidth', 153 | \ 'global_name': 'tab_width', 154 | \ 'mapper': function('s:Flag_tab_width')}, 155 | \ '--print-width': { 156 | \ 'json_name': 'printWidth', 157 | \ 'global_name': 'print_width', 158 | \ 'mapper': function('s:Flag_print_width')}, 159 | \ '--parser': { 160 | \ 'json_name': 'parser', 161 | \ 'global_name': 'parser', 162 | \ 'mapper': function('s:Flag_parser')}, 163 | \ '--range-start': { 164 | \ 'json_name': '', 165 | \ 'global_name': '', 166 | \ 'mapper': function('s:Flag_range_start')}, 167 | \ '--range-end': { 168 | \ 'json_name': '', 169 | \ 'global_name': '', 170 | \ 'mapper': function('s:Flag_range_end')}, 171 | \ '--semi': { 172 | \ 'json_name': 'semi', 173 | \ 'global_name': 'semi', 174 | \ 'mapper': s:concat_value}, 175 | \ '--single-quote': { 176 | \ 'json_name': 'singleQuote', 177 | \ 'global_name': 'single_quote', 178 | \ 'mapper': s:concat_value}, 179 | \ '--bracket-spacing': { 180 | \ 'json_name': 'bracketSpacing', 181 | \ 'global_name': 'bracket_spacing', 182 | \ 'mapper': s:concat_value}, 183 | \ '--bracket-same-line': { 184 | \ 'json_name': 'bracketSameLine', 185 | \ 'global_name': 'bracket_same_line', 186 | \ 'mapper': s:concat_value, 187 | \ 'since': '2.4.0'}, 188 | \ '--jsx-bracket-same-line': { 189 | \ 'json_name': 'jsxBracketSameLine', 190 | \ 'global_name': 'jsx_bracket_same_line', 191 | \ 'mapper': s:concat_value, 192 | \ 'deprecated': '2.4.0'}, 193 | \ '--arrow-parens': { 194 | \ 'json_name': 'arrowParens', 195 | \ 'global_name': 'arrow_parens', 196 | \ 'mapper': s:concat_value, 197 | \ 'since': '1.9.0'}, 198 | \ '--trailing-comma': { 199 | \ 'json_name': 'trailingComma', 200 | \ 'global_name': 'trailing_comma', 201 | \ 'mapper': s:concat_value}, 202 | \ '--config-precedence': { 203 | \ 'json_name': 'configPrecedence', 204 | \ 'global_name': 'config_precedence', 205 | \ 'mapper': s:concat_value}, 206 | \ '--prose-wrap': { 207 | \ 'json_name': 'proseWrap', 208 | \ 'global_name': 'prose_wrap', 209 | \ 'mapper': s:concat_value, 210 | \ 'since': '1.8.2'}, 211 | \ '--html-whitespace-sensitivity': { 212 | \ 'json_name': 'htmlWhitespaceSensitivity', 213 | \ 'global_name': 'html_whitespace_sensitivity', 214 | \ 'mapper': s:concat_value, 215 | \ 'since': '1.15.0'}, 216 | \ '--stdin-filepath': { 217 | \ 'json_name': '', 218 | \ 'global_name': '', 219 | \ 'mapper': function('s:Flag_stdin_filepath')}, 220 | \ '--require-pragma': { 221 | \ 'json_name': 'requirePragma', 222 | \ 'global_name': 'require_pragma', 223 | \ 'mapper': s:concat_value, 224 | \ 'since': '1.7.0'}, 225 | \ '--end-of-line': { 226 | \ 'json_name': 'endOfLine', 227 | \ 'global_name': 'end_of_line', 228 | \ 'mapper': s:concat_value, 229 | \ 'since': '1.15.0'}, 230 | \ '--loglevel': { 231 | \ 'json_name': '', 232 | \ 'global_name': '', 233 | \ 'mapper': function('s:Flag_loglevel'), 234 | \ 'deprecated': '3.0.0'}, 235 | \ '--log-level': { 236 | \ 'json_name': '', 237 | \ 'global_name': '', 238 | \ 'mapper': function('s:Flag_loglevel'), 239 | \ 'since': '3.0.0'}, 240 | \ '--stdin': { 241 | \ 'json_name': '', 242 | \ 'global_name': '', 243 | \ 'mapper': function('s:Flag_stdin'), 244 | \ 'deprecated': '2.0.0'}} 245 | " }}} 246 | 247 | " Flags selector: {{{ 248 | " Returns the argument string with unprintable characters represented in Vim 249 | " internal format removed from both ends. 250 | function! s:Trim_internal_unprintable(text) abort 251 | let l:char_patt = '\%(\%(\^\m.\)\|\%(<\x\x>\)\)\{}' 252 | let l:patt_at_ends = '^' . l:char_patt . '\|' . l:char_patt . '$' 253 | let l:trimmed_text = a:text->substitute(l:patt_at_ends, '', 'g') 254 | return l:trimmed_text 255 | endfunction 256 | 257 | " Returns the version of the Prettier CLI as a string. 258 | function! s:Get_prettier_cli_version() abort 259 | let l:output = '' 260 | redir => l:output 261 | silent call prettier#PrettierCli('--version') 262 | redir END 263 | " The shell sends the string with whitespaces at both ends. 264 | let l:prettier_cli_version = s:Trim_internal_unprintable(trim(l:output)) 265 | return l:prettier_cli_version 266 | endfunction 267 | 268 | " Returns 1 if the version of the flag argument is compatible with the 269 | " version argument, otherwise returns 0. 270 | function! s:Filter_uncompatible_flag(version, _, flag) abort 271 | let l:is_deprecated = exists('a:flag.deprecated') 272 | \ && prettier#utils#version#Is_greater_or_equal_version( 273 | \ a:version, a:flag.deprecated) 274 | if l:is_deprecated 275 | return 0 276 | endif 277 | 278 | let l:is_added = !exists('a:flag.since') 279 | \ || prettier#utils#version#Is_greater_or_equal_version( 280 | \ a:version, a:flag.since) 281 | if !l:is_added 282 | return 0 283 | endif 284 | return 1 285 | endfunction 286 | 287 | " Returns an object with the flags from the argument object that are compatible 288 | " with the version of the Prettier CLI being used. 289 | function! s:Get_current_version_flags(flags) abort 290 | let l:prettier_version = s:Get_prettier_cli_version() 291 | 292 | let l:is_cached = exists('b:prettier_cached_flags') 293 | \ && exists('b:prettier_last_used_cli_version') 294 | \ && b:prettier_last_used_cli_version ==# l:prettier_version 295 | if l:is_cached 296 | return b:prettier_cached_flags->copy() 297 | endif 298 | 299 | let l:compatible_flags = a:flags->copy()->filter( 300 | \ function('s:Filter_uncompatible_flag', [l:prettier_version])) 301 | let b:prettier_cached_flags = l:compatible_flags 302 | let b:prettier_last_used_cli_version = l:prettier_version 303 | return l:compatible_flags->copy() 304 | endfunction 305 | " }}} 306 | 307 | " vim:foldmethod=marker:foldmarker={{{,}}}: 308 | -------------------------------------------------------------------------------- /autoload/prettier/resolver/executable.vim: -------------------------------------------------------------------------------- 1 | let s:ROOT_DIR = fnamemodify(resolve(expand(':p')), ':h') 2 | 3 | " By default we will search for the following 4 | " => user defined prettier cli path from vim configuration file 5 | " => locally installed prettier inside node_modules on any parent folder 6 | " => globally installed prettier 7 | " => vim-prettier prettier installation 8 | " => if all fails suggest install 9 | function! prettier#resolver#executable#getPath() abort 10 | let l:user_defined_exec_path = fnamemodify(g:prettier#exec_cmd_path, ':p') 11 | if executable(l:user_defined_exec_path) 12 | return l:user_defined_exec_path 13 | endif 14 | 15 | let l:localExec = s:ResolveExecutable(getcwd()) 16 | if executable(l:localExec) 17 | return fnameescape(l:localExec) 18 | endif 19 | 20 | let l:globalExec = s:ResolveExecutable() 21 | if executable(l:globalExec) 22 | return fnameescape(l:globalExec) 23 | endif 24 | 25 | let l:pluginExec = s:ResolveExecutable(s:ROOT_DIR) 26 | if executable(l:pluginExec) 27 | return fnameescape(l:pluginExec) 28 | endif 29 | 30 | return -1 31 | endfunction 32 | 33 | function! s:GetExecPath(...) abort 34 | let l:rootDir = a:0 > 0 ? a:1 : -1 35 | let l:dir = l:rootDir != -1 ? l:rootDir . '/.bin/' : '' 36 | let l:path = l:dir . get(b:, 'prettier_exec_cmd', 'prettier') 37 | if executable(l:path) 38 | return l:path 39 | else 40 | return l:dir . 'prettier' 41 | endif 42 | endfunction 43 | 44 | " Searches for the existence of a directory accross 45 | " ancestral parents 46 | function! s:TraverseAncestorDirSearch(rootDir) abort 47 | let l:root = a:rootDir 48 | let l:dir = 'node_modules' 49 | 50 | while 1 51 | let l:searchDir = l:root . '/' . l:dir 52 | if isdirectory(l:searchDir) 53 | return l:searchDir 54 | endif 55 | 56 | let l:parent = fnamemodify(l:root, ':h') 57 | if l:parent == l:root 58 | return -1 59 | endif 60 | 61 | let l:root = l:parent 62 | endwhile 63 | endfunction 64 | 65 | function! s:ResolveExecutable(...) abort 66 | let l:rootDir = a:0 > 0 ? a:1 : 0 67 | let l:exec = "." 68 | 69 | if isdirectory(l:rootDir) 70 | let l:dir = s:TraverseAncestorDirSearch(l:rootDir) 71 | if l:dir != -1 72 | let l:exec = s:GetExecPath(l:dir) 73 | endif 74 | else 75 | let l:exec = s:GetExecPath() 76 | endif 77 | 78 | return l:exec 79 | endfunction 80 | -------------------------------------------------------------------------------- /autoload/prettier/resolver/preset.vim: -------------------------------------------------------------------------------- 1 | " Build config using predefined preset 2 | function! prettier#resolver#preset#resolve(fileTypeConfigOverwrites) abort 3 | if ( g:prettier#preset#config ==# 'fb' ) 4 | return extend(prettier#presets#fb#config(), a:fileTypeConfigOverwrites) 5 | endif 6 | 7 | return a:fileTypeConfigOverwrites 8 | endfunction 9 | -------------------------------------------------------------------------------- /autoload/prettier/utils/buffer.vim: -------------------------------------------------------------------------------- 1 | function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abort 2 | " store view 3 | let l:winview = winsaveview() 4 | let l:newBuffer = prettier#utils#buffer#createBufferFromUpdatedLines(a:lines, a:startSelection, a:endSelection) 5 | 6 | " we should not replace contents if the newBuffer is empty 7 | if empty(l:newBuffer) 8 | return 9 | endif 10 | 11 | " https://vim.fandom.com/wiki/Restore_the_cursor_position_after_undoing_text_change_made_by_a_script 12 | " create a fake change entry and merge with undo stack prior to do formating 13 | execute "normal! i " 14 | execute "normal! a\" 15 | try | silent undojoin | catch | endtry 16 | 17 | " delete all lines on the current buffer 18 | silent! execute 'lockmarks %delete _' 19 | 20 | " replace all lines from the current buffer with output from prettier 21 | let l:idx = 0 22 | for l:line in l:newBuffer 23 | silent! lockmarks call append(l:idx, l:line) 24 | let l:idx += 1 25 | endfor 26 | 27 | " delete trailing newline introduced by the above append procedure 28 | silent! lockmarks execute '$delete _' 29 | 30 | " Restore view 31 | call winrestview(l:winview) 32 | 33 | endfunction 34 | 35 | " Replace and save the buffer 36 | function! prettier#utils#buffer#replaceAndSave(lines, startSelection, endSelection) abort 37 | call prettier#utils#buffer#replace(a:lines, a:startSelection, a:endSelection) 38 | noautocmd write 39 | endfunction 40 | 41 | " Returns 1 if content has changed 42 | function! prettier#utils#buffer#willUpdatedLinesChangeBuffer(lines, start, end) abort 43 | return getbufline(bufnr('%'), 1, line('$')) == prettier#utils#buffer#createBufferFromUpdatedLines(a:lines, a:start, a:end) ? 0 : 1 44 | endfunction 45 | 46 | " Returns a new buffer with lines replacing start and end of the contents of the current buffer 47 | function! prettier#utils#buffer#createBufferFromUpdatedLines(lines, start, end) abort 48 | return getbufline(bufnr('%'), 1, a:start - 1) + a:lines + getbufline(bufnr('%'), a:end + 1, '$') 49 | endfunction 50 | 51 | " Adapted from https://github.com/farazdagi/vim-go-ide 52 | function! s:getCharPosition(line, col) abort 53 | if &encoding !=# 'utf-8' 54 | " On utf-8 enconding we can't just use bytes so we need to make sure we can count the 55 | " characters, we do that by adding the text into a temporary buffer and counting the chars 56 | let l:buf = a:line == 1 ? '' : (join(getline(1, a:line - 1), "\n") . "\n") 57 | let l:buf .= a:col == 1 ? '' : getline('.')[:a:col - 2] 58 | return len(iconv(l:buf, &encoding, 'utf-8')) 59 | endif 60 | " On non utf-8 the line byte should match the character 61 | return line2byte(a:line) + (a:col - 2) 62 | endfun 63 | 64 | " Return the start byte when on visual mode 65 | function! prettier#utils#buffer#getCharRangeStart(startSelection) abort 66 | return s:getCharPosition(a:startSelection, col("'<")) 67 | endfunction 68 | 69 | " Return the end byte when on visual mode 70 | function! prettier#utils#buffer#getCharRangeEnd(endSelection) abort 71 | return s:getCharPosition(a:endSelection, col("'>")) 72 | endfunction 73 | -------------------------------------------------------------------------------- /autoload/prettier/utils/quickfix.vim: -------------------------------------------------------------------------------- 1 | " We use this flag so that we ensure only clearing quickfix if it was created by prettier itself 2 | let s:prettier_quickfix_open = 0 3 | 4 | function! prettier#utils#quickfix#close() abort 5 | " close quickfix if it is opened 6 | if s:prettier_quickfix_open 7 | call setqflist([], 'r') 8 | cclose 9 | let s:prettier_quickfix_open = 0 10 | endif 11 | endfunction 12 | 13 | function! prettier#utils#quickfix#open(errors, focus) abort 14 | let s:prettier_quickfix_open = 1 15 | let l:winnr = winnr() 16 | call setqflist(a:errors, 'r') 17 | botright copen 18 | if !a:focus 19 | " Return the cursor back to the main buffer. 20 | exe l:winnr . 'wincmd w' 21 | endif 22 | endfunction 23 | -------------------------------------------------------------------------------- /autoload/prettier/utils/shim.vim: -------------------------------------------------------------------------------- 1 | " Backwards compatable version of shiftwidth() 2 | function! prettier#utils#shim#shiftwidth() abort 3 | if exists('*shiftwidth') 4 | return shiftwidth() 5 | else 6 | return &shiftwidth 7 | endif 8 | endfunction 9 | -------------------------------------------------------------------------------- /autoload/prettier/utils/version.vim: -------------------------------------------------------------------------------- 1 | " Returns 1 if the first argument is the greater version, returns 0 if the 2 | " arguments are the same version, or returns -1 if the first argument is the 3 | " lesser version. 4 | function! prettier#utils#version#Compare_versions(a, b) abort 5 | let [l:a_major, l:a_minor, l:a_patch; l:rest] = a:a->split('\D') 6 | \ ->map('str2nr(v:val)') 7 | let [l:b_major, l:b_minor, l:b_patch; l:rest] = a:b->split('\D') 8 | \ ->map('str2nr(v:val)') 9 | let l:is_a_greater = 10 | \ l:a_major > l:b_major 11 | \ || (l:a_major == l:b_major && l:a_minor > l:b_minor) 12 | \ || (l:a_major == l:b_major && l:a_minor == l:b_minor 13 | \ && l:a_patch > l:b_patch) 14 | let l:is_a_equal_b = 15 | \ l:a_major == l:b_major 16 | \ && l:a_minor == l:b_minor 17 | \ && l:a_patch == l:b_patch 18 | return l:is_a_greater ? 1 : (l:is_a_equal_b ? 0 : -1) 19 | endfunction 20 | 21 | " Returns 1 if the first argument is greater than or equal to the second, 22 | " otherwise returns 0. 23 | function! prettier#utils#version#Is_greater_or_equal_version(a, b) abort 24 | return prettier#utils#version#Compare_versions(a:a, a:b) != -1 25 | endfunction 26 | -------------------------------------------------------------------------------- /doc/prettier.txt: -------------------------------------------------------------------------------- 1 | *vim-prettier.txt* A prettier plugin for vim. 2 | 3 | ------------------------------------------------------- 4 | vim-prettier: plugin wrapper for prettier 5 | ------------------------------------------------------- 6 | 7 | Author: Mitermayer Reis 8 | WebSite: https://prettier.io/ 9 | Repository: https://github.com/prettier/vim-prettier 10 | License: MIT style license 11 | Version: 1.0.0 12 | 13 | ============================================================================== 14 | CONTENTS *vim-prettier-contents* 15 | 16 | Introduction |vim-prettier-introduction| 17 | Install |vim-prettier-install| 18 | Usage |vim-prettier-usage| 19 | Configuration |vim-prettier-configuration| 20 | Requirements |vim-prettier-requirements| 21 | 22 | ============================================================================== 23 | INTRODUCTION *vim-prettier-introduction* 24 | 25 | A vim plugin wrapper for prettier, pre-configured with 26 | custom default prettier settings. 27 | 28 | By default it will auto format javascript, typescript, less, scss, css, 29 | json, and graphql files that have '@format' annotation in the header of the file. 30 | 31 | When installed via vim-plug, a default prettier executable is installed inside 32 | vim-prettier. 33 | 34 | vim-prettier executable resolution: 35 | 36 | 1. Look for user defined prettier cli path from vim configuration file 37 | 2. Traverse parents and search for Prettier installation inside `node_modules` 38 | 3. Look for a global prettier installation 39 | 4. Use locally installed vim-prettier prettier executable 40 | 41 | ============================================================================== 42 | INSTALL *vim-prettier-install* 43 | 44 | Install with [vim-plug](https://github.com/junegunn/vim-plug), assumes 45 | node and yarn|npm installed globally. 46 | > 47 | Plug 'prettier/vim-prettier', { 48 | \ 'do': 'yarn install', 49 | \ 'for': ['javascript', 'typescript', 'css', 50 | \ 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'svelte', 'yaml', 51 | 'html'] } 52 | < 53 | or simply enable for all formats by: 54 | > 55 | Plug 'prettier/vim-prettier', { 'do': 'yarn install' } 56 | < 57 | 58 | If using other vim plugin managers or doing manual setup make sure to have 59 | `prettier` installed globally or go to your vim-prettier directory and 60 | either do `npm install` or `yarn install` 61 | 62 | ============================================================================== 63 | USAGE *vim-prettier-usage* 64 | 65 | Prettier by default will run on auto save but can also 66 | be manually triggered by: 67 | > 68 | p 69 | < 70 | or 71 | > 72 | :Prettier 73 | < 74 | If your are on vim 8+ you can also trigger async formatting by: 75 | > 76 | :PrettierAsync 77 | < 78 | You can check what is the `vim-prettier` plugin version by: 79 | > 80 | :PrettierVersion 81 | < 82 | You can send commands to the resolved `prettier` cli by: 83 | > 84 | :PrettierCli 85 | < 86 | You can check what is the resolved `prettier` cli path by: 87 | > 88 | :PrettierCliPath 89 | < 90 | You can check what is the resolved `prettier` cli version by: 91 | > 92 | :PrettierCliVersion 93 | 94 | You can send to prettier your entire buffer but ensure that it 95 | formats only your selection. 96 | 97 | **note:** differs from `:PrettierFragment` by sending the entire buffer 98 | to prettier, allowing identation level to be preserved, but it requires 99 | the whole file to be valid. 100 | > 101 | :PrettierPartial 102 | 103 | You can send to prettier your current selection as a fragment of same type as 104 | the file being edited. 105 | 106 | **note:** differs from `:PrettierPartial` by sending only the current selection 107 | to prettier, this allows for faster formatting but wont preserve indentation. 108 | > 109 | :PrettierFragment 110 | 111 | ============================================================================== 112 | CONFIGURATION *vim-prettier-configuration* 113 | 114 | Enable auto formatting of files that have "@format" or "@prettier" tag 115 | > 116 | let g:prettier#autoformat = 1 117 | 118 | Enable auto formatting of files based on whether a Prettier configuration file has been 119 | found in the project directory or any parent directories. 120 | > 121 | let g:prettier#autoformat_config_present = 1 122 | 123 | Configuration file names to search for when attempting to find an appropriate 124 | Prettier configuration file for the current project. 125 | > 126 | let g:prettier#autoformat_config_files = [...] 127 | < 128 | Set the prettier CLI executable path 129 | > 130 | let g:prettier#exec_cmd_path = "~/path/to/cli/prettier" 131 | < 132 | The command `:Prettier` by default is synchronous but can also be forced async 133 | > 134 | let g:prettier#exec_cmd_async = 1 135 | < 136 | By default parsing errors will open the quickfix but can also be disabled 137 | > 138 | let g:prettier#quickfix_enabled = 1 139 | < 140 | By default we auto focus on the quickfix when there are errors but can also be disabled 141 | > 142 | let g:prettier#quickfix_auto_focus = 0 143 | < 144 | To enable vim-prettier to auto run in files without requiring the "@format" or "@prettier" doc tag. 145 | First ensure that `g:prettier#autoformat` is not enabled on your `vimrc` (it should be disabled by default), then update to your own custom behaviour 146 | 147 | Running before saving sync: 148 | > 149 | autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html Prettier 150 | < 151 | Running before saving async (vim 8+): 152 | > 153 | autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html PrettierAsync 154 | < 155 | Running before saving, changing text or leaving insert mode: 156 | > 157 | " when running at every change you may want to disable quickfix 158 | let g:prettier#quickfix_enabled = 0 159 | autocmd BufWritePre,TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html PrettierAsync 160 | < 161 | Buffer-level custom commands 162 | 163 | To use an alternative command, like `prettier-stylelint`, set this at the 164 | buffer level with `b:prettier_exec_cmd`, e.g.: 165 | > 166 | au FileType css,scss let b:prettier_exec_cmd = "prettier-stylelint" 167 | < 168 | vim-prettier will look for the executable in the same places it looks for 169 | `prettier`, and will fall back to `prettier` if it can't find 170 | `b:prettier_exec_cmd` 171 | 172 | Overwrite default prettier configuration 173 | 174 | **Note:** vim-prettier default settings differ from prettier intentionally. 175 | However they can be configured by: 176 | > 177 | " Max line length that prettier will wrap on: a number or 'auto' (use 178 | " textwidth). 179 | " default: 'auto' 180 | let g:prettier#config#print_width = 'auto' 181 | 182 | " number of spaces per indentation level: a number or 'auto' (use 183 | " softtabstop) 184 | " default: 'auto' 185 | let g:prettier#config#tab_width = 'auto' 186 | 187 | " use tabs instead of spaces: true, false, or auto (use the expandtab setting). 188 | " default: 'auto' 189 | let g:prettier#config#use_tabs = 'auto' 190 | 191 | " flow|babylon|typescript|css|less|scss|json|graphql|markdown or empty string 192 | " (let prettier choose). 193 | " default: '' 194 | let g:prettier#config#parser = '' 195 | 196 | " cli-override|file-override|prefer-file 197 | " default: 'file-override' 198 | let g:prettier#config#config_precedence = 'file-override' 199 | 200 | " always|never|preserve 201 | " default: 'preserve' 202 | let g:prettier#config#prose_wrap = 'preserve' 203 | 204 | " css|strict|ignore 205 | let g:prettier#config#html_whitespace_sensitivity = 'css' 206 | 207 | " false|true 208 | " default: 'false' 209 | " let g:prettier#config#require_pragma = 'false' 210 | 211 | " Define the flavor of line endings 212 | " lf|crlf|cr|all 213 | " defaut: 'lf' 214 | let g:prettier#config#end_of_line = get(g:, 'prettier#config#end_of_line', 'lf') 215 | 216 | ============================================================================== 217 | REQUIREMENT(S) *vim-prettier-requirements* 218 | 219 | If prettier is not installed locally, globally or inside vim-prettier project 220 | no code formatting will happen 221 | 222 | ============================================================================== 223 | vim:tw=78:ts=4:ft=help:norl:noet:fen:noet: 224 | -------------------------------------------------------------------------------- /ftdetect/css.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.css setfiletype css 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/graphql.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.graphql,*.gql setfiletype graphql 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/html.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.html setfiletype html 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/javascript.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.js,*jsx setfiletype javascript 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/json.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.json setfiletype json 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/less.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.less setfiletype less 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/lua.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.lua setfiletype lua 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/markdown.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.markdown,*.md,*.mdown,*.mkd,*.mkdn setfiletype markdown 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/php.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.php setfiletype php 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/ruby.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.rb setfiletype ruby 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/scss.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.scss setfiletype scss 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/svelte.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.svelte setfiletype svelte 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/typescript.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.ts setfiletype typescript 3 | autocmd BufNewFile,BufReadPost *.tsx setfiletype typescriptreact 4 | augroup end 5 | -------------------------------------------------------------------------------- /ftdetect/vue.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.vue setfiletype vue 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/xml.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.xml setfiletype xml 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftdetect/yaml.vim: -------------------------------------------------------------------------------- 1 | augroup PrettierFileDetect 2 | autocmd BufNewFile,BufReadPost *.yaml,*.yml setfiletype yaml 3 | augroup end 4 | -------------------------------------------------------------------------------- /ftplugin/css.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'css', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/graphql.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'graphql', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/html.vim: -------------------------------------------------------------------------------- 1 | " markdown/php files run this as well 2 | " https://stackoverflow.com/questions/22839269/why-does-vim-default-markdown-ftplugin-source-html-ftplugins-is-there-any-ways 3 | if expand('%:e') ==# 'html' 4 | let b:prettier_ft_default_args = { 5 | \ 'parser': 'html', 6 | \ } 7 | endif 8 | -------------------------------------------------------------------------------- /ftplugin/javascript.vim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prettier/vim-prettier/7dbdbb12c50a9f4ba72390cce2846248e4368fd0/ftplugin/javascript.vim -------------------------------------------------------------------------------- /ftplugin/json.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'json', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/less.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'less', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/lua.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'lua', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/markdown.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'markdown', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/php.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'php', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/ruby.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'ruby', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/scss.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'scss', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/svelte.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'svelte', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/typescript.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'typescript', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/vue.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'vue', 3 | \ } 4 | -------------------------------------------------------------------------------- /ftplugin/xml.vim: -------------------------------------------------------------------------------- 1 | " markdown/php files run this as well 2 | " https://stackoverflow.com/questions/22839269/why-does-vim-default-markdown-ftplugin-source-html-ftplugins-is-there-any-ways 3 | if expand('%:e') ==# 'xml' 4 | let b:prettier_ft_default_args = { 5 | \ 'parser': 'xml', 6 | \ } 7 | endif 8 | -------------------------------------------------------------------------------- /ftplugin/yaml.vim: -------------------------------------------------------------------------------- 1 | let b:prettier_ft_default_args = { 2 | \ 'parser': 'yaml', 3 | \ } 4 | -------------------------------------------------------------------------------- /media/vim-prettier.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prettier/vim-prettier/7dbdbb12c50a9f4ba72390cce2846248e4368fd0/media/vim-prettier.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vim-prettier", 3 | "author": "Mitermayer Reis ", 4 | "version": "1.0.0", 5 | "description": "Vim plugin for prettier", 6 | "license": "MIT", 7 | "repository": { 8 | "type": "git", 9 | "url": "git://github.com/prettier/vim-prettier.git" 10 | }, 11 | "scripts": { 12 | "test": "vim --version && LOG_LEVEL=error jest", 13 | "lint": "vint --version && vint ." 14 | }, 15 | "dependencies": { 16 | "@prettier/plugin-lua": "0.0.1", 17 | "@prettier/plugin-php": "^0.16.3", 18 | "@prettier/plugin-ruby": "^0.8.0", 19 | "@prettier/plugin-xml": "^0.7.2", 20 | "prettier": "^3.0.3", 21 | "prettier-plugin-svelte": "^2.3.1" 22 | }, 23 | "devDependencies": { 24 | "colors": "^1.3.2", 25 | "jest": "^23.6.0", 26 | "vim-driver": "^1.0.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /plugin/prettier.vim: -------------------------------------------------------------------------------- 1 | " vim-prettier: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings. 2 | " 3 | " Script Info {{{ 4 | "========================================================================================================== 5 | " Name Of File: prettier.vim 6 | " Description: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings. 7 | " Maintainer: Mitermayer Reis 8 | " Version: 1.0.0 9 | " Usage: Use :help vim-prettier-usage, or visit https://github.com/prettier/vim-prettier 10 | " 11 | "========================================================================================================== 12 | " }}} 13 | 14 | if exists('g:loaded_prettier') 15 | finish 16 | endif 17 | let g:loaded_prettier = 1 18 | 19 | " => Plugin config 20 | " autoformating disabled by default upon saving 21 | let g:prettier#autoformat = get(g:, 'prettier#autoformat', 0) 22 | 23 | " autoformating requires pragma by default 24 | let g:prettier#autoformat_require_pragma = get(g:, 'prettier#autoformat_require_pragma', 1) 25 | 26 | " whether to turn autoformatting on if a prettier config file is found 27 | let g:prettier#autoformat_config_present = get(g:, 'prettier#autoformat_config_present', 0) 28 | 29 | " prettier config files to search current directory and parent directories for 30 | let g:prettier#autoformat_config_files = get(g:, 'prettier#autoformat_config_files', [ 31 | \'.prettierrc', 32 | \'.prettierrc.yml', 33 | \'.prettierrc.yaml', 34 | \'.prettierrc.js', 35 | \'.prettierrc.config.js', 36 | \'.prettierrc.json', 37 | \'.prettierrc.toml']) 38 | 39 | " path to prettier cli 40 | let g:prettier#exec_cmd_path = get(g:, 'prettier#exec_cmd_path', 0) 41 | 42 | " calling :Prettier by default runs synchronous 43 | let g:prettier#exec_cmd_async = get(g:, 'prettier#exec_cmd_async', 0) 44 | 45 | " when having formatting errors will open the quickfix by default 46 | let g:prettier#quickfix_enabled = get(g:, 'prettier#quickfix_enabled', 1) 47 | 48 | " Don't leave the quicklist focused on error. 49 | let g:prettier#quickfix_auto_focus = get(g:, 'prettier#quickfix_auto_focus', 1) 50 | 51 | " Send to prettier entire buffer and use --range-start and --range-end as delimter 52 | let g:prettier#partial_format = get(g:, 'prettier#partial_format', 0) 53 | 54 | " default|fb 55 | " Use prettier defaults 56 | let g:prettier#preset#config = get(g:,'prettier#preset#config', 'default') 57 | 58 | " => Prettier CLI config 59 | " Max line length that prettier will wrap on: a number or 'auto' (use 60 | " textwidth). 61 | " default: 'auto' 62 | " See more: https://prettier.io/docs/en/options.html#print-width 63 | let g:prettier#config#print_width = get(g:, 'prettier#config#print_width', 'auto') 64 | 65 | " number of spaces per indentation level: a number or 'auto' (use 66 | " softtabstop) 67 | " default: 'auto' 68 | " See more: https://prettier.io/docs/en/options.html#tab-width 69 | let g:prettier#config#tab_width = get(g:,'prettier#config#tab_width', 'auto') 70 | 71 | " use tabs instead of spaces: true, false, or auto (use the expandtab setting). 72 | " default: 'auto' 73 | " See more: https://prettier.io/docs/en/options.html#tabs 74 | let g:prettier#config#use_tabs = get(g:,'prettier#config#use_tabs', 'auto') 75 | 76 | " flow|babylon|typescript|css|less|scss|json|graphql|markdown or empty string 77 | " (let prettier choose). 78 | " default: '' 79 | " See more: https://prettier.io/docs/en/options.html#parser 80 | let g:prettier#config#parser = get(g:,'prettier#config#parser', '') 81 | 82 | " cli-override|file-override|prefer-file 83 | " default: 'file-override' 84 | " See more: https://prettier.io/docs/en/cli.html#--config-precedence 85 | let g:prettier#config#config_precedence = get(g:, 'prettier#config#config_precedence', 'file-override') 86 | 87 | " always|never|preserve 88 | " default: 'preserve' 89 | " See more: https://prettier.io/docs/en/options.html#prose-wrap 90 | let g:prettier#config#prose_wrap = get(g:, 'prettier#config#prose_wrap', 'preserve') 91 | 92 | " css|strict|ignore 93 | " default: 'css' 94 | " See more: https://prettier.io/docs/en/options.html#html-whitespace-sensitivity 95 | let g:prettier#config#html_whitespace_sensitivity = get(g:, 'prettier#config#html_whitespace_sensitivity', 'css') 96 | 97 | " print semicolons 98 | " default: 'true' 99 | " See more: https://prettier.io/docs/en/options.html#semicolons 100 | let g:prettier#config#semi = get(g:,'prettier#config#semi', 'true') 101 | 102 | " Use single quotes instead of double quotes. 103 | " default: 'false' 104 | " See more: https://prettier.io/docs/en/options.html#quotes 105 | let g:prettier#config#single_quote = get(g:,'prettier#config#single_quote', 'false') 106 | 107 | " print spaces between brackets 108 | " default: 'true' 109 | " See more: https://prettier.io/docs/en/options.html#bracket-spacing 110 | let g:prettier#config#bracket_spacing = get(g:,'prettier#config#bracket_spacing', 'true') 111 | 112 | " put > on the last line instead of new line 113 | " default: 'false' 114 | " See more: https://prettier.io/docs/en/options.html#jsx-brackets 115 | let g:prettier#config#jsx_bracket_same_line = get(g:,'prettier#config#jsx_bracket_same_line', 'false') 116 | " This option has another name for Prettier versions 2.4.0 and higher: 117 | let g:prettier#config#bracket_same_line = get(g:, 'prettier#config#bracket_same_line', 'false') 118 | 119 | " avoid wrapping a single arrow function param in parens 120 | " avoid|always 121 | " default: 'always' 122 | " See more: https://prettier.io/docs/en/options.html#arrow-function-parentheses 123 | let g:prettier#config#arrow_parens = get(g:,'prettier#config#arrow_parens', 'always') 124 | 125 | " Define the flavor of line endings 126 | " lf|crlf|cr|all 127 | " defaut: 'lf' 128 | let g:prettier#config#end_of_line = get(g:, 'prettier#config#end_of_line', 'lf') 129 | 130 | " Print trailing commas wherever possible when multi-line. 131 | " none|es5|all 132 | " default: 'es5' 133 | " See more: https://prettier.io/docs/en/options.html#trailing-commas 134 | let g:prettier#config#trailing_comma = get(g:,'prettier#config#trailing_comma', 'es5') 135 | 136 | " restrict itself to only format files that contain a special comment @prettier or @format 137 | " See more: https://prettier.io/docs/en/options.html#require-pragma 138 | let g:prettier#config#require_pragma= get(g:, 'prettier#config#require_pragma', 'false') 139 | 140 | " synchronous by default 141 | command! -nargs=? -range=% Prettier call prettier#Prettier(g:prettier#exec_cmd_async, , , g:prettier#partial_format) 142 | 143 | " prettier async 144 | command! -nargs=? -range=% PrettierAsync call prettier#Prettier(1, , , g:prettier#partial_format) 145 | 146 | " prints vim-prettier version 147 | command! -nargs=? -range=% PrettierVersion echom '1.0.0' 148 | 149 | " call prettier cli 150 | command! -nargs=? -range=% PrettierCli call prettier#PrettierCli() 151 | 152 | " call prettier cli to get its version 153 | command! -nargs=? -range=% PrettierCliVersion call prettier#PrettierCli('--version') 154 | 155 | " prints prettier resolved cli path 156 | command! -nargs=? -range=% PrettierCliPath call prettier#PrettierCliPath() 157 | 158 | " sends selected text to prettier cli for formatting 159 | command! -nargs=? -range=% PrettierFragment call prettier#Prettier(g:prettier#exec_cmd_async, , , 0) 160 | 161 | " sends entire buffer to prettier cli but format just selection 162 | command! -nargs=? -range=% PrettierPartial call prettier#Prettier(g:prettier#exec_cmd_async, , , 1) 163 | 164 | " map command 165 | if !hasmapto('(Prettier)') && maparg('p', 'n') ==# '' 166 | nmap p (Prettier) 167 | endif 168 | nnoremap (Prettier) :Prettier 169 | nnoremap (PrettierAsync) :PrettierAsync 170 | nnoremap (PrettierFragment) :PrettierFragment 171 | nnoremap (PrettierPartial) :PrettierPartial 172 | nnoremap (PrettierVersion) :PrettierVersion 173 | nnoremap (PrettierCli) :PrettierCli 174 | nnoremap (PrettierCliVersion) :PrettierCliVersion 175 | nnoremap (PrettierCliPath) :PrettierCliPath 176 | 177 | augroup Prettier 178 | autocmd! 179 | autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.gql,*.markdown,*.md,*.mdown,*.mkd,*.mkdn,*.mdx,*.vue,*.svelte,*.yml,*.yaml,*.html,*.php,*.rb,*.ruby,*.xml noautocmd call prettier#Autoformat() 180 | augroup end 181 | -------------------------------------------------------------------------------- /tests/__snapshots__/formatting.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Prettier formats foo.css file with :Prettier command 1`] = ` 4 | ".redClass { 5 | background: \\"red\\"; 6 | } 7 | #redId { 8 | background: \\"red\\"; 9 | }" 10 | `; 11 | 12 | exports[`Prettier formats foo.css file with :PrettierAsync command 1`] = ` 13 | ".redClass { 14 | background: \\"red\\"; 15 | } 16 | #redId { 17 | background: \\"red\\"; 18 | }" 19 | `; 20 | 21 | exports[`Prettier formats foo.graphql file with :Prettier command 1`] = ` 22 | "{ 23 | baz { 24 | blah 25 | ...name 26 | } 27 | bean { 28 | foo 29 | blah 30 | bleh 31 | } 32 | bar { 33 | ...name 34 | } 35 | }" 36 | `; 37 | 38 | exports[`Prettier formats foo.graphql file with :PrettierAsync command 1`] = ` 39 | "{ 40 | baz { 41 | blah 42 | ...name 43 | } 44 | bean { 45 | foo 46 | blah 47 | bleh 48 | } 49 | bar { 50 | ...name 51 | } 52 | }" 53 | `; 54 | 55 | exports[`Prettier formats foo.html file with :Prettier command 1`] = ` 56 | " 57 | 58 | foo 59 | 60 | 61 |

foo

62 | 63 | " 64 | `; 65 | 66 | exports[`Prettier formats foo.html file with :PrettierAsync command 1`] = ` 67 | " 68 | 69 | foo 70 | 71 | 72 |

foo

73 | 74 | " 75 | `; 76 | 77 | exports[`Prettier formats foo.js file with :Prettier command 1`] = ` 78 | "const a = () => { 79 | return 2; 80 | };" 81 | `; 82 | 83 | exports[`Prettier formats foo.js file with :PrettierAsync command 1`] = ` 84 | "const a = () => { 85 | return 2; 86 | };" 87 | `; 88 | 89 | exports[`Prettier formats foo.json file with :Prettier command 1`] = ` 90 | "{ 91 | \\"name\\": \\"foo\\", 92 | \\"bar\\": \\"baz\\" 93 | }" 94 | `; 95 | 96 | exports[`Prettier formats foo.json file with :PrettierAsync command 1`] = ` 97 | "{ 98 | \\"name\\": \\"foo\\", 99 | \\"bar\\": \\"baz\\" 100 | }" 101 | `; 102 | 103 | exports[`Prettier formats foo.less file with :Prettier command 1`] = ` 104 | ".redClass { 105 | background: \\"red\\"; 106 | } 107 | #redId { 108 | background: \\"red\\"; 109 | }" 110 | `; 111 | 112 | exports[`Prettier formats foo.less file with :PrettierAsync command 1`] = ` 113 | ".redClass { 114 | background: \\"red\\"; 115 | } 116 | #redId { 117 | background: \\"red\\"; 118 | }" 119 | `; 120 | 121 | exports[`Prettier formats foo.lua file with :Prettier command 1`] = ` 122 | "function deepcopy(orig) 123 | local orig_type = type(orig) 124 | local copy 125 | 126 | return copy 127 | end" 128 | `; 129 | 130 | exports[`Prettier formats foo.lua file with :PrettierAsync command 1`] = ` 131 | "function deepcopy(orig) 132 | local orig_type = type(orig) 133 | local copy 134 | 135 | return copy 136 | end" 137 | `; 138 | 139 | exports[`Prettier formats foo.md file with :Prettier command 1`] = ` 140 | "## foo 141 | 142 | Lorem ipsum dolor amet 143 | 144 | ### bar 145 | 146 | - a 147 | - b 148 | - c" 149 | `; 150 | 151 | exports[`Prettier formats foo.md file with :PrettierAsync command 1`] = ` 152 | "## foo 153 | 154 | Lorem ipsum dolor amet 155 | 156 | ### bar 157 | 158 | - a 159 | - b 160 | - c" 161 | `; 162 | 163 | exports[`Prettier formats foo.php file with :Prettier command 1`] = ` 164 | " number = () => { 209 | return 2; 210 | };" 211 | `; 212 | 213 | exports[`Prettier formats foo.ts file with :PrettierAsync command 1`] = ` 214 | "const a: () => number = () => { 215 | return 2; 216 | };" 217 | `; 218 | 219 | exports[`Prettier formats foo.vue file with :Prettier command 1`] = ` 220 | " 223 | 224 | 231 | 232 | 237 | 238 | 239 | This could be e.g. documentation for the component. 240 | " 241 | `; 242 | 243 | exports[`Prettier formats foo.vue file with :PrettierAsync command 1`] = ` 244 | " 247 | 248 | 255 | 256 | 261 | 262 | 263 | This could be e.g. documentation for the component. 264 | " 265 | `; 266 | 267 | exports[`Prettier formats foo.xml file with :Prettier command 1`] = ` 268 | " 269 | 271 | 272 | 273 | 280 | foo 281 | 282 | bar 283 | 284 | 285 | 286 | " 287 | `; 288 | 289 | exports[`Prettier formats foo.xml file with :PrettierAsync command 1`] = ` 290 | " 291 | 293 | 294 | 295 | 302 | foo 303 | 304 | bar 305 | 306 | 307 | 308 | " 309 | `; 310 | 311 | exports[`Prettier formats foo.yaml file with :Prettier command 1`] = ` 312 | "foo: 313 | bar: 314 | baz: 315 | bleh: ./foo 316 | foobar: foobar 317 | args: 318 | buildno: 1" 319 | `; 320 | 321 | exports[`Prettier formats foo.yaml file with :PrettierAsync command 1`] = ` 322 | "foo: 323 | bar: 324 | baz: 325 | bleh: ./foo 326 | foobar: foobar 327 | args: 328 | buildno: 1" 329 | `; 330 | -------------------------------------------------------------------------------- /tests/fixtures/foo.css: -------------------------------------------------------------------------------- 1 | .redClass { background: 'red';} 2 | #redId { 3 | background: 'red';} 4 | -------------------------------------------------------------------------------- /tests/fixtures/foo.graphql: -------------------------------------------------------------------------------- 1 | { 2 | baz { 3 | blah, ...name } 4 | bean{foo, blah,bleh} 5 | bar { 6 | ...name 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/fixtures/foo.html: -------------------------------------------------------------------------------- 1 | 2 | foo 3 |

foo

4 | -------------------------------------------------------------------------------- /tests/fixtures/foo.js: -------------------------------------------------------------------------------- 1 | const a = () => { return 2; }; 2 | -------------------------------------------------------------------------------- /tests/fixtures/foo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo", "bar": "baz" 3 | } 4 | -------------------------------------------------------------------------------- /tests/fixtures/foo.less: -------------------------------------------------------------------------------- 1 | .redClass { background: 'red';} 2 | #redId { 3 | background: 'red';} 4 | -------------------------------------------------------------------------------- /tests/fixtures/foo.lua: -------------------------------------------------------------------------------- 1 | function deepcopy(orig) 2 | local orig_type = type(orig) 3 | local copy 4 | 5 | return copy 6 | end 7 | -------------------------------------------------------------------------------- /tests/fixtures/foo.md: -------------------------------------------------------------------------------- 1 | ## foo 2 | Lorem ipsum dolor amet 3 | 4 | 5 | ### bar 6 | 7 | 8 | 9 | - a 10 | - b 11 | - c 12 | -------------------------------------------------------------------------------- /tests/fixtures/foo.php: -------------------------------------------------------------------------------- 1 | number = () => { return 2; }; 2 | -------------------------------------------------------------------------------- /tests/fixtures/foo.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 11 | 12 | 13 | This could be e.g. documentation for the component. 14 | 15 | -------------------------------------------------------------------------------- /tests/fixtures/foo.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 13 | foo 14 | 15 | bar 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/fixtures/foo.yaml: -------------------------------------------------------------------------------- 1 | foo: 2 | 3 | bar: 4 | 5 | baz: 6 | 7 | bleh: ./foo 8 | foobar: foobar 9 | args: 10 | 11 | buildno: 1 12 | -------------------------------------------------------------------------------- /tests/formatting.test.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const HeadlessRemoteClient = require('vim-driver/dist/HeadlessRemoteClient'); 4 | const Server = require('vim-driver/dist/Server'); 5 | 6 | const HOST = '127.0.0.1'; 7 | const PORT = 1337; 8 | const FIXTURES_DIR = `${__dirname}/fixtures`; 9 | 10 | let server; 11 | let remote; 12 | 13 | jest.setTimeout(15000); 14 | 15 | const getBufferContents = async remote => 16 | (await remote.call('getline', [1, '$'])).join('\n'); 17 | 18 | const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); 19 | const waitUntil = (condition, timeout = 2000) => { 20 | return new Promise(resolve => { 21 | let isTimedOut = false; 22 | let timeoutId = null; 23 | 24 | const check = () => { 25 | const promise = condition(); 26 | promise.then(result => { 27 | if (!isTimedOut && result === true) { 28 | clearTimeout(timeoutId); 29 | resolve(); 30 | } else if (!isTimedOut) { 31 | check(); 32 | } 33 | }); 34 | }; 35 | 36 | timeoutId = setTimeout(() => { 37 | isTimedOut = true; 38 | resolve(); 39 | }, timeout); 40 | }); 41 | }; 42 | 43 | const assertFormatting = (file) => { 44 | const filename = path.basename(file); 45 | test(`Prettier formats ${filename} file with :Prettier command`, async () => { 46 | await remote.edit(`${FIXTURES_DIR}/${file}`); 47 | 48 | const lines = await getBufferContents(remote); 49 | 50 | // run sync formatting 51 | await remote.execute('Prettier'); 52 | 53 | const updatedLines = await getBufferContents(remote); 54 | 55 | // we now check that we have indeed formatted the code 56 | expect(updatedLines).not.toBe(lines); 57 | 58 | // check snapshot 59 | expect(updatedLines).toMatchSnapshot(); 60 | }); 61 | 62 | test(`Prettier formats ${filename} file with :PrettierAsync command`, async () => { 63 | await remote.edit(`${FIXTURES_DIR}/${file}`); 64 | 65 | const lines = await getBufferContents(remote); 66 | 67 | // run async formatting 68 | await remote.execute('PrettierAsync'); 69 | 70 | const unmodifiedLines = await getBufferContents(remote); 71 | 72 | // async should not happen immediatly so content should still remain the same 73 | expect(unmodifiedLines).toBe(lines); 74 | 75 | // we now will wait until prettier has finally updated the content async 76 | await waitUntil(async () => (await getBufferContents(remote)) !== lines); 77 | 78 | const updatedLines = await getBufferContents(remote); 79 | 80 | // we now check that we have indeed formatted the code 81 | expect(lines).not.toBe(updatedLines); 82 | 83 | // check snapshot 84 | expect(updatedLines).toMatchSnapshot(); 85 | }); 86 | }; 87 | 88 | beforeAll(async () => { 89 | server = new Server(); 90 | await server.listen(HOST, PORT); 91 | }); 92 | 93 | afterAll(async () => { 94 | await server.close(); 95 | }); 96 | 97 | // should ensure that we cache original fixture contents and 98 | // restore it on the afterEach 99 | beforeEach(async () => { 100 | remote = new HeadlessRemoteClient({host: HOST, port: PORT}); 101 | await remote.connect(server); 102 | }); 103 | 104 | afterEach(async () => { 105 | if (remote.isConnected()) { 106 | try { 107 | const filename = await remote.call('expand', ['%:p']); 108 | 109 | if (filename) { 110 | // restore the file 111 | await remote.execute('earlier 1d | noautocmd | write'); 112 | } 113 | } catch (e) { 114 | } finally { 115 | await remote.close(); 116 | } 117 | } 118 | }); 119 | 120 | //test('PrettierVersion returns pluggin version', async () => { 121 | // const result = await remote.execute('PrettierVersion'); 122 | // expect(result).toMatchSnapshot(); 123 | //}); 124 | 125 | // run formatting tests in all fixtures 126 | fs.readdirSync(FIXTURES_DIR).forEach(file => assertFormatting(file)); 127 | -------------------------------------------------------------------------------- /tests/vimrc: -------------------------------------------------------------------------------- 1 | " vint: -ProhibitSetNoCompatible 2 | 3 | source /rtp.vim 4 | 5 | " Load builtin plugins 6 | " We need this because run_vim.sh sets -i NONE 7 | if has('win32') 8 | set runtimepath=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,C:\vader,C:\testplugin 9 | else 10 | set runtimepath=/home/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,/testplugin,/vader 11 | endif 12 | 13 | " The following is just an example 14 | filetype plugin indent on 15 | syntax on 16 | 17 | if !has('win32') 18 | set shell=/bin/sh 19 | set shellcmdflag=-c 20 | endif 21 | 22 | set nocompatible 23 | set tabstop=4 24 | set softtabstop=4 25 | set shiftwidth=4 26 | set expandtab 27 | set backspace=2 28 | set nofoldenable 29 | set foldmethod=syntax 30 | set foldlevelstart=10 31 | set foldnestmax=10 32 | set ttimeoutlen=0 33 | 34 | " The encoding must be explicitly set for tests for Windows. 35 | execute 'set encoding=utf-8' 36 | -------------------------------------------------------------------------------- /tests/vimscript/version.vim: -------------------------------------------------------------------------------- 1 | " To run the tests in this script, first add the vim-prettier plugin and let 2 | " Vim load it, then uncomment the last line in this script, and source this 3 | " file in Vim with the command 4 | " ":source " where is the path to this file, e.g. 5 | " ":source %". 6 | 7 | function! s:Test_version_comparison_greater_case() abort 8 | echomsg 'Testing version comparison, greater case.' 9 | 10 | let l:ver_1 = '2.7.3' 11 | let l:ver_2 = '0.9.8' 12 | let l:value = prettier#utils#version#Compare_versions(l:ver_1, l:ver_2) 13 | let l:expected = 1 14 | return assert_equal( 15 | \ l:value, 16 | \ l:expected, 17 | \ 'Expected ' . l:expected . ' but received ' . l:value 18 | \ . ' instead.') 19 | endfunction 20 | 21 | function! s:Test_version_comparison_lesser_case() abort 22 | echomsg 'Testing version comparison, lesser case.' 23 | 24 | let l:ver_1 = '3.9.5' 25 | let l:ver_2 = '10.5.2' 26 | let l:value = prettier#utils#version#Compare_versions(l:ver_1, l:ver_2) 27 | let l:expected = -1 28 | return assert_equal( 29 | \ l:value, 30 | \ l:expected, 31 | \ 'Expected ' . l:expected . ' but received ' . l:value 32 | \ . ' instead.') 33 | endfunction 34 | 35 | function! s:Test_version_comparison_equal_case() abort 36 | echomsg 'Testing version comparison, equal case.' 37 | 38 | let l:ver_1 = '8.2.4' 39 | let l:ver_2 = '8.2.4' 40 | let l:value = prettier#utils#version#Compare_versions(l:ver_1, l:ver_2) 41 | let l:expected = 0 42 | return assert_equal( 43 | \ l:value, 44 | \ l:expected, 45 | \ 'Expected ' . l:expected . ' but received ' . l:value 46 | \ . ' instead.') 47 | endfunction 48 | 49 | function! s:Test_is_greater_or_equal_version_greater_case() abort 50 | echomsg 'Testing function that checks if is lesser version, greater case.' 51 | 52 | let l:ver_1 = '3.8.1' 53 | let l:ver_2 = '0.2.9' 54 | let l:value = prettier#utils#version#Is_greater_or_equal_version( 55 | \ l:ver_1, l:ver_2) 56 | let l:expected = 1 57 | return assert_equal( 58 | \ l:value, 59 | \ l:expected, 60 | \ 'Expected ' . l:expected . ' but received ' . l:value 61 | \ . ' instead.') 62 | endfunction 63 | 64 | function! s:Test_is_greater_or_equal_version_lesser_case() abort 65 | echomsg 'Testing function that checks if is lesser version, lesser case.' 66 | 67 | let l:ver_1 = '7.2.8' 68 | let l:ver_2 = '15.1.6' 69 | let l:value = prettier#utils#version#Is_greater_or_equal_version( 70 | \ l:ver_1, l:ver_2) 71 | let l:expected = 0 72 | return assert_equal( 73 | \ l:value, 74 | \ l:expected, 75 | \ 'Expected ' . l:expected . ' but received ' . l:value 76 | \ . ' instead.') 77 | endfunction 78 | 79 | function! s:Test_is_greater_or_equal_version_equal_case() abort 80 | echomsg 'Testing function that checks if is lesser version, lesser case.' 81 | 82 | let l:ver_1 = '4.12.185' 83 | let l:ver_2 = '4.12.185' 84 | let l:value = prettier#utils#version#Is_greater_or_equal_version( 85 | \ l:ver_1, l:ver_2) 86 | let l:expected = 1 87 | return assert_equal( 88 | \ l:value, 89 | \ l:expected, 90 | \ 'Expected ' . l:expected . ' but received ' . l:value 91 | \ . ' instead.') 92 | endfunction 93 | 94 | function! s:Run_tests() abort 95 | let v:errors = [] 96 | 97 | let l:test_functions = [ 98 | \ function('s:Test_version_comparison_greater_case'), 99 | \ function('s:Test_version_comparison_lesser_case'), 100 | \ function('s:Test_version_comparison_equal_case'), 101 | \ function('s:Test_is_greater_or_equal_version_greater_case'), 102 | \ function('s:Test_is_greater_or_equal_version_lesser_case'), 103 | \ function('s:Test_is_greater_or_equal_version_equal_case')] 104 | 105 | let l:results_as_returned = l:test_functions->copy()->map('v:val()') 106 | let l:results_as_text = l:results_as_returned 107 | \ ->copy() 108 | \ ->map('v:key + 1 .. '': '' .. (v:val ? "failed" : "passed")') 109 | 110 | let l:has_failed_test = v:errors->len() > 0 111 | \ || l:results_as_returned->index(1) >= 0 112 | if l:has_failed_test 113 | echoerr 'The tests failed.' 114 | echoerr 'Results:' 115 | echoerr l:results_as_text->join('; ') 116 | echoerr 'Errors:' 117 | echoerr v:errors->join('; ') 118 | else 119 | echomsg 'The tests were completed successfully.' 120 | echomsg 'Results:' 121 | echomsg l:results_as_text->join('; ') 122 | endif 123 | endfunction 124 | 125 | " Uncomment the next line to run the tests. 126 | " call s:Run_tests() 127 | --------------------------------------------------------------------------------