Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/oxfmt/src-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type FormatOptions = {
experimentalSortImports?: SortImportsOptions;
/** Experimental: Sort `package.json` keys. (Default: `true`) */
experimentalSortPackageJson?: boolean;
};
} & Record<string, unknown>; // Also allow additional options for we don't have typed yet.

/**
* Configuration options for sort imports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ export default {name:"Test",data(){return {foo:"bar",baz:123}}}
</template>

<script>
export default {
name: 'Test',
data() {
return { foo: 'bar', baz: 123 };
},
};
export default {
name: 'Test',
data() {
return { foo: 'bar', baz: 123 };
},
};
</script>

<style>
.foo {
color: red;
background: blue;
}
.foo {
color: red;
background: blue;
}
</style>

--------------------"
Expand Down
31 changes: 31 additions & 0 deletions apps/oxfmt/test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,35 @@ describe("API Tests", () => {
});
expect(errors.length).toBe(1);
});

test("should `format()` with options work", async () => {
const pkgJSON = JSON.stringify({
version: "1.0.0",
name: "my-package",
});
const result1 = await format("package.json", pkgJSON);
expect(result1.code).toBe(`{\n "name": "my-package",\n "version": "1.0.0"\n}\n`);
expect(result1.errors).toStrictEqual([]);

const result2 = await format("package.json", pkgJSON, { experimentalSortPackageJson: false });
expect(result2.code).toBe(`{\n "version": "1.0.0",\n "name": "my-package"\n}\n`);
expect(result2.errors).toStrictEqual([]);

const vueCode = `
<template><div>Vue</div></template>
<style>div{color:red;}</style>
`.trim();
const result3 = await format("Component.vue", vueCode, {
vueIndentScriptAndStyle: true,
});
expect(result3.code).toBe(
`
<template><div>Vue</div></template>
<style>
div{color:red;}
</style>
`.trimStart(),
);
expect(result3.errors).toStrictEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"printWidth": 40,
"useTabs": true,
"singleQuote": true,
"embeddedLanguageFormatting": "auto"
"embeddedLanguageFormatting": "auto",
"vueIndentScriptAndStyle": true
}
Loading