From 66c1a7c8fcba6ef118469e0845ddd8638069d35a Mon Sep 17 00:00:00 2001 From: mitermayer Date: Sat, 15 Feb 2020 09:49:17 +0000 Subject: Added support for prettier xml plugin - updated package.json deps - added tests - updated lock file --- ftdetect/xml.vim | 3 ++ ftplugin/html.vim | 2 +- ftplugin/xml.vim | 14 +++++++++ package.json | 1 + tests/__snapshots__/formatting.test.js.snap | 44 +++++++++++++++++++++++++++++ tests/fixtures/foo.xml | 19 +++++++++++++ tests/formatting.test.js | 2 +- yarn.lock | 29 ++++++++++++++++++- 8 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 ftdetect/xml.vim create mode 100644 ftplugin/xml.vim create mode 100644 tests/fixtures/foo.xml diff --git a/ftdetect/xml.vim b/ftdetect/xml.vim new file mode 100644 index 0000000..302b4aa --- /dev/null +++ b/ftdetect/xml.vim @@ -0,0 +1,3 @@ +augroup PrettierFileDetect + autocmd BufNewFile,BufReadPost *.xml setfiletype xml +augroup end diff --git a/ftplugin/html.vim b/ftplugin/html.vim index 4d37544..c0c39b4 100644 --- a/ftplugin/html.vim +++ b/ftplugin/html.vim @@ -1,6 +1,6 @@ " markdown/php files run this as well " https://stackoverflow.com/questions/22839269/why-does-vim-default-markdown-ftplugin-source-html-ftplugins-is-there-any-ways -if &ft ==# 'html' +if expand("%:e") ==# 'html' let b:prettier_ft_default_args = { \ 'parser': 'html', \ } diff --git a/ftplugin/xml.vim b/ftplugin/xml.vim new file mode 100644 index 0000000..70aec32 --- /dev/null +++ b/ftplugin/xml.vim @@ -0,0 +1,14 @@ +" markdown/php files run this as well +" https://stackoverflow.com/questions/22839269/why-does-vim-default-markdown-ftplugin-source-html-ftplugins-is-there-any-ways +if expand("%:e") ==# 'xml' + let b:prettier_ft_default_args = { + \ 'parser': 'xml', + \ } +endif + +augroup Prettier + autocmd! + if get(g:, 'prettier#autoformat') + autocmd BufWritePre *.xml call prettier#Autoformat() + endif +augroup end diff --git a/package.json b/package.json index 9ab9d9d..dfb5298 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@prettier/plugin-php": "^0.10.2", "@prettier/plugin-python": "prettier/plugin-python", "@prettier/plugin-ruby": "^0.8.0", + "@prettier/plugin-xml": "^0.7.2", "prettier": "^1.18.2" }, "devDependencies": { diff --git a/tests/__snapshots__/formatting.test.js.snap b/tests/__snapshots__/formatting.test.js.snap index cfa24bf..fafb3e7 100644 --- a/tests/__snapshots__/formatting.test.js.snap +++ b/tests/__snapshots__/formatting.test.js.snap @@ -282,6 +282,50 @@ export default { " `; +exports[`Prettier formats foo.xml file with :Prettier command 1`] = ` +" + + + + + foo + + bar + + + +" +`; + +exports[`Prettier formats foo.xml file with :PrettierAsync command 1`] = ` +" + + + + + foo + + bar + + + +" +`; + exports[`Prettier formats foo.yaml file with :Prettier command 1`] = ` "foo: bar: diff --git a/tests/fixtures/foo.xml b/tests/fixtures/foo.xml new file mode 100644 index 0000000..93d6e9b --- /dev/null +++ b/tests/fixtures/foo.xml @@ -0,0 +1,19 @@ + + + + + + foo + + bar + + + + diff --git a/tests/formatting.test.js b/tests/formatting.test.js index 2a3e373..4ea2906 100644 --- a/tests/formatting.test.js +++ b/tests/formatting.test.js @@ -10,7 +10,7 @@ const FIXTURES_DIR = `${__dirname}/fixtures`; let server; let remote; -jest.setTimeout(10000); +jest.setTimeout(15000); const getBufferContents = async remote => (await remote.call('getline', [1, '$'])).join('\n'); diff --git a/yarn.lock b/yarn.lock index c683cdb..d2c5c19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -85,11 +85,26 @@ dependencies: prettier "^1.16.4" +"@prettier/plugin-xml@^0.7.2": + version "0.7.2" + resolved "https://registry.yarnpkg.com/@prettier/plugin-xml/-/plugin-xml-0.7.2.tgz#f4b6e7c45a9e36663d403828e380e8a4c6a12106" + integrity sha512-c6i6OQ2y9kvWeUTrfkwHy+jdJXI3bpO8TT9EoVjJIEAApj5gLtJ/O2D9qthxWXh5zbipngueDEC2CT6tBZzBdA== + dependencies: + "@xml-tools/parser" "^1.0.2" + prettier ">=1.10" + "@types/node@*": version "13.7.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.0.tgz#b417deda18cf8400f278733499ad5547ed1abec4" integrity sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ== +"@xml-tools/parser@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@xml-tools/parser/-/parser-1.0.2.tgz#f70ba24be0c06999c132bff304d15959d7f946a8" + integrity sha512-jFkywQ7reQETLDrOtiRzb7JvzZsbhHlTYKAJbByxb4osSRFtR5CCa9BV5uPPXJrQJ8K5MfLXN+TRd4K8eq5A+g== + dependencies: + chevrotain "6.5.0" + abab@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.3.tgz#623e2075e02eb2d3f2475e49f99c91846467907a" @@ -631,6 +646,13 @@ character-reference-invalid@^1.0.0: resolved "https://registry.yarnpkg.com/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz#083329cda0eae272ab3dbbf37e9a382c13af1560" integrity sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg== +chevrotain@6.5.0: + version "6.5.0" + resolved "https://registry.yarnpkg.com/chevrotain/-/chevrotain-6.5.0.tgz#dcbef415516b0af80fd423cc0d96b28d3f11374e" + integrity sha512-BwqQ/AgmKJ8jcMEjaSnfMybnKMgGTrtDKowfTP3pX4jwVy0kNjRsT/AP6h+wC3+3NC+X8X15VWBnTCQlX+wQFg== + dependencies: + regexp-to-ast "0.4.0" + ci-info@^1.5.0: version "1.6.0" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497" @@ -3095,7 +3117,7 @@ preserve@^0.2.0: resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks= -prettier@^1.16.4, prettier@^1.18.2: +prettier@>=1.10, prettier@^1.16.4, prettier@^1.18.2: version "1.19.1" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== @@ -3292,6 +3314,11 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" +regexp-to-ast@0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/regexp-to-ast/-/regexp-to-ast-0.4.0.tgz#f3dbcb42726cd71902ba50193f63eab5325cd7cb" + integrity sha512-4qf/7IsIKfSNHQXSwial1IFmfM1Cc/whNBQqRwe0V2stPe7KmN1U0tWQiIx6JiirgSrisjE0eECdNf7Tav1Ntw== + remark-frontmatter@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/remark-frontmatter/-/remark-frontmatter-1.1.0.tgz#9d23c2b376f56617bdb5c5560f1b56e45b19788b" -- cgit v1.3