Skip to content

Commit

Permalink
fix tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Weis committed Jul 7, 2023
1 parent f15c65a commit a9f7cb4
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 121 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ The `prettier` executable is now installed and ready for use:

Below are the options (from [`src/plugin.js`](src/plugin.js)) that `@prettier/plugin-xml` currently supports:

| API Option | CLI Option | Default | Description |
| -------------------------- | ------------------------------ | :--------: | ------------------------------------------------------------------------------------------------------------------------ | --- |
| `bracketSameLine` | `--bracket-same-line` | `true` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#bracket-same-line)) |
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
| `singleAttributePerLine` | `--single-attribute-per-line` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#single-attribute-per-line)) | |
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
| API Option | CLI Option | Default | Description |
| -------------------------- | ------------------------------ | :----------: | ------------------------------------------------------------------------------------------------------------------------ | --- |
| `bracketSameLine` | `--bracket-same-line` | `true` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#bracket-same-line)) |
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
| `singleAttributePerLine` | `--single-attribute-per-line` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#single-attribute-per-line)) | |
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
| `xmlQuoteAttributes` | `--xml-quote-attributes` | `"preserve"` | Options are `"preserve"`, `"single"`, and `"double"` |
| `xmlSelfClosingSpace` | `--xml-self-closing-space` | `true` | Adds a space before self-closing tags. |
| `xmlSortAttributesByKey` | `--xml-sort-attributes-by-key` | `false` | Orders XML attributes by key alphabetically while prioritizing xmlns attributes. |
| `xmlWhitespaceSensitivity` | `--xml-whitespace-sensitivity` | `"strict"` | Options are `"strict"`, `"preserve"`, and `"ignore"`. You may want `"ignore"` or `"preserve"`, [see below](#whitespace). |
| `xmlSelfClosingSpace` | `--xml-self-closing-space` | `true` | Adds a space before self-closing tags. |
| `xmlSortAttributesByKey` | `--xml-sort-attributes-by-key` | `false` | Orders XML attributes by key alphabetically while prioritizing xmlns attributes. |
| `xmlWhitespaceSensitivity` | `--xml-whitespace-sensitivity` | `"strict"` | Options are `"strict"`, `"preserve"`, and `"ignore"`. You may want `"ignore"` or `"preserve"`, [see below](#whitespace). |

Any of these can be added to your existing [prettier configuration
file](https://prettier.io/docs/en/configuration.html). For example:
Expand Down
193 changes: 81 additions & 112 deletions test/__snapshots__/format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,33 @@ use {
<div attr1="singleQuotes" att2="doubleQuotes" />
<!-- Basic sorting of xml attributes -->
<div z="third" y="second" x="first" />
<container xmlns:ios="iosURI" xmlns:android="androidURI">
<foo
xmlns:tools="toolsURI"
android:d="d"
android:c="c"
some="non-ns-ed-attributes"
here="!"
tools:other="thing"
android:b="b"
xmlns="highest priority"
android:a="a"
>
<bar
xmlns:otherTools="otherToolsURI"
ios:d="d"
ios:c="c"
tools:other="thing"
another="one"
android:b="b"
otherTools:baz="bing"
ios:a="a"
/>
</foo>
</container>
<EscapeNeeded name="Pete &quot;Maverick&quot; Mitchell" />
<NoEscapeNeeded>He said, "Don't quote me."</NoEscapeNeeded>
Expand Down Expand Up @@ -687,6 +714,33 @@ use {
<div attr1='singleQuotes' att2="doubleQuotes" />
<!-- Basic sorting of xml attributes -->
<div z="third" y="second" x="first" />
<container xmlns:ios="iosURI" xmlns:android="androidURI">
<foo
xmlns:tools="toolsURI"
android:d="d"
android:c="c"
some="non-ns-ed-attributes"
here="!"
tools:other="thing"
android:b="b"
xmlns="highest priority"
android:a="a"
>
<bar
xmlns:otherTools="otherToolsURI"
ios:d="d"
ios:c="c"
tools:other="thing"
another="one"
android:b="b"
otherTools:baz="bing"
ios:a="a"
/>
</foo>
</container>
<EscapeNeeded name="Pete &quot;Maverick&quot; Mitchell" />
<NoEscapeNeeded>He said, "Don't quote me."</NoEscapeNeeded>
Expand Down Expand Up @@ -779,6 +833,33 @@ use {
<div attr1='singleQuotes' att2='doubleQuotes' />
<!-- Basic sorting of xml attributes -->
<div z='third' y='second' x='first' />
<container xmlns:ios='iosURI' xmlns:android='androidURI'>
<foo
xmlns:tools='toolsURI'
android:d='d'
android:c='c'
some='non-ns-ed-attributes'
here='!'
tools:other='thing'
android:b='b'
xmlns='highest priority'
android:a='a'
>
<bar
xmlns:otherTools='otherToolsURI'
ios:d='d'
ios:c='c'
tools:other='thing'
another='one'
android:b='b'
otherTools:baz='bing'
ios:a='a'
/>
</foo>
</container>
<EscapeNeeded name='Pete &quot;Maverick&quot; Mitchell' />
<NoEscapeNeeded>He said, "Don't quote me."</NoEscapeNeeded>
Expand Down Expand Up @@ -907,118 +988,6 @@ use {
/>
</foo>
</container>
</svg>
<!-- bar -->
"
`;

exports[`xmlSortAttributesByKey => true 1`] = `
"<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<?xml-model href="project.rnc" type="application/relax-ng-compact-syntax"?>
<!-- foo -->
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
height="100"
viewBox="0 0 200 100"
width="200"
>
<title>Style inheritance and the use element</title>
<desc _attr="attr">
&anp; &#12345;
<![CDATA[
foo
]]>
bar
</desc>
<?pagebreak?>
<style />
<style> </style>
<style type="text/css">
circle {
stroke-opacity: 0.7;
}
.special circle {
stroke: green;
}
use {
stroke: purple;
fill: orange;
}
</style>
<script value="lint" />
<yaml
myveryveryveryverylongattributename="myveryveryveryverylongattributevalue"
>
- 1
- 2
- 3
</yaml>
<!-- inner comment -->
<?pagebreak?>
<g class="special" style="fill: blue">
<circle cx="50" cy="50" id="c" r="40" stroke-width="20" />
</g>
<use xlink:href="#c" x="100" />
<ignored>
<!-- prettier-ignore-start -->
< ignored />
<!-- prettier-ignore-end -->
</ignored>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at est eget enim consectetur accumsan. Aliquam pretium sodales ipsum quis dignissim. Sed id sem vel diam luctus fringilla. Aliquam quis egestas magna. Curabitur molestie lorem et odio porta, et molestie libero laoreet. Morbi rhoncus sagittis cursus. Nullam vehicula pretium consequat. Praesent porta ante at posuere sollicitudin. Nullam commodo tempor arcu, at condimentum neque elementum ut.
</p>
<span>
content
</span>
<div> text with space<div><hr /></div> </div>
<div>
even more
<content />
</div>
<div
anotherverylongattribute="anotherverylongvalue"
verylongattribute="verylongvalue"
/>
<div att2="doubleQuotes" attr1='singleQuotes' />
<!-- Basic sorting of xml attributes -->
<div x="first" y="second" z="third" />
<container xmlns:android="androidURI" xmlns:ios="iosURI">
<foo
xmlns="highest priority"
xmlns:tools="toolsURI"
android:a="a"
android:b="b"
android:c="c"
android:d="d"
tools:other="thing"
here="!"
some="non-ns-ed-attributes"
>
<bar
xmlns:otherTools="otherToolsURI"
android:b="b"
ios:a="a"
ios:c="c"
ios:d="d"
otherTools:baz="bing"
tools:other="thing"
another="one"
/>
</foo>
</container>
<EscapeNeeded name="Pete &quot;Maverick&quot; Mitchell"/>
<NoEscapeNeeded>He said, "Don't quote me."</NoEscapeNeeded>
Expand Down
2 changes: 2 additions & 0 deletions test/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ test("xmlSortAttributesByKey => true", async () => {
const formatted = await format(fixture, {
xmlSortAttributesByKey: true
});
});

test("xmlQuoteAttributes => preserve", async () => {
const formatted = await format(fixture, {
Expand All @@ -97,5 +98,6 @@ test("xmlQuoteAttributes => double", async () => {
const formatted = await format(fixture, {
xmlQuoteAttributes: "double"
});

expect(formatted).toMatchSnapshot();
});

0 comments on commit a9f7cb4

Please sign in to comment.