From 85f7f935af8714c0571d633dd1f6cd3849db68c4 Mon Sep 17 00:00:00 2001 From: Antony Faris Date: Mon, 8 Nov 2021 15:03:50 -0500 Subject: [PATCH] Add support for prettier options (#47) --- .changeset/witty-badgers-shave.md | 5 + .prettierignore | 3 +- src/printer.ts | 9 +- test/astro-prettier.test.ts | 159 ++++++++++-------- .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../{in/basic.astro => basic/input.astro} | 0 .../{out/basic.astro => basic/output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 6 +- .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 6 +- .../input.md} | 2 +- .../output.md} | 6 +- .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../option-arrow-parens-always/input.astro | 7 + .../option-arrow-parens-always/options.json | 3 + .../option-arrow-parens-always/output.astro | 7 + .../option-arrow-parens-avoid/input.astro | 7 + .../option-arrow-parens-avoid/options.json | 3 + .../option-arrow-parens-avoid/output.astro | 7 + .../input.astro | 11 ++ .../options.json | 3 + .../output.astro | 11 ++ .../input.astro | 10 ++ .../options.json | 3 + .../output.astro | 11 ++ .../input.astro | 15 ++ .../options.json | 3 + .../output.astro | 16 ++ .../option-bracket-same-line-true/input.astro | 15 ++ .../options.json | 3 + .../output.astro | 15 ++ .../option-bracket-spacing-false/input.astro | 7 + .../option-bracket-spacing-false/options.json | 3 + .../option-bracket-spacing-false/output.astro | 7 + .../option-bracket-spacing-true/input.astro | 7 + .../option-bracket-spacing-true/options.json | 3 + .../option-bracket-spacing-true/output.astro | 7 + .../input.astro | 8 + .../options.json | 3 + .../output.astro | 31 ++++ .../input.astro | 9 + .../options.json | 3 + .../output.astro | 35 ++++ .../input.astro | 9 + .../options.json | 3 + .../output.astro | 32 ++++ .../option-jsx-single-quote-false/input.astro | 10 ++ .../options.json | 3 + .../output.astro | 11 ++ .../option-jsx-single-quote-true/input.astro | 10 ++ .../option-jsx-single-quote-true/options.json | 3 + .../option-jsx-single-quote-true/output.astro | 11 ++ test/fixtures/option-print-width/input.astro | 14 ++ test/fixtures/option-print-width/options.json | 3 + test/fixtures/option-print-width/output.astro | 25 +++ .../option-prose-wrap-always/input.md | 9 + .../option-prose-wrap-always/options.json | 4 + .../option-prose-wrap-always/output.md | 11 ++ .../fixtures/option-prose-wrap-never/input.md | 9 + .../option-prose-wrap-never/options.json | 4 + .../option-prose-wrap-never/output.md | 7 + .../option-prose-wrap-preserve/input.md | 8 + .../option-prose-wrap-preserve/options.json | 4 + .../option-prose-wrap-preserve/output.md | 9 + .../option-quote-props-as-needed/input.astro | 9 + .../option-quote-props-as-needed/options.json | 3 + .../option-quote-props-as-needed/output.astro | 9 + .../option-quote-props-consistent/input.astro | 9 + .../options.json | 3 + .../output.astro | 9 + .../option-quote-props-preserve/input.astro | 9 + .../option-quote-props-preserve/options.json | 3 + .../option-quote-props-preserve/output.astro | 9 + .../option-semicolon-false/input.astro | 9 + .../option-semicolon-false/options.json | 3 + .../option-semicolon-false/output.astro | 10 ++ .../option-semicolon-true/input.astro | 9 + .../option-semicolon-true/options.json | 3 + .../option-semicolon-true/output.astro | 10 ++ .../option-single-quote-false/input.astro | 9 + .../option-single-quote-false/options.json | 3 + .../option-single-quote-false/output.astro | 10 ++ .../option-single-quote-true/input.astro | 9 + .../option-single-quote-true/options.json | 3 + .../option-single-quote-true/output.astro | 10 ++ test/fixtures/option-tab-width/input.astro | 8 + test/fixtures/option-tab-width/options.json | 3 + test/fixtures/option-tab-width/output.astro | 9 + .../option-trailing-comma-es5/input.astro | 12 ++ .../option-trailing-comma-es5/options.json | 3 + .../option-trailing-comma-es5/output.astro | 15 ++ .../option-trailing-comma-none/input.astro | 12 ++ .../option-trailing-comma-none/options.json | 3 + .../option-trailing-comma-none/output.astro | 15 ++ .../option-use-tabs-false/input.astro | 8 + .../option-use-tabs-false/options.json | 3 + .../option-use-tabs-false/output.astro | 9 + .../fixtures/option-use-tabs-true/input.astro | 8 + .../option-use-tabs-true/options.json | 3 + .../option-use-tabs-true/output.astro | 9 + .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../with-sass.astro => with-sass/input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 .../with-scss.astro => with-scss/input.astro} | 0 .../output.astro} | 0 .../input.astro} | 0 .../output.astro} | 0 test/test-utils.ts | 93 +++++++++- 138 files changed, 947 insertions(+), 85 deletions(-) create mode 100644 .changeset/witty-badgers-shave.md rename test/fixtures/{in/attribute-with-embedded-expr.astro => attribute-with-embedded-expr/input.astro} (100%) rename test/fixtures/{out/attribute-with-embedded-expr.astro => attribute-with-embedded-expr/output.astro} (100%) rename test/fixtures/{in/autocloses-open-tags.astro => autocloses-open-tags/input.astro} (100%) rename test/fixtures/{out/autocloses-open-tags.astro => autocloses-open-tags/output.astro} (100%) rename test/fixtures/{in/basic.astro => basic/input.astro} (100%) rename test/fixtures/{out/basic.astro => basic/output.astro} (100%) rename test/fixtures/{in/converts-to-shorthand.astro => converts-to-shorthand/input.astro} (100%) rename test/fixtures/{out/converts-to-shorthand.astro => converts-to-shorthand/output.astro} (100%) rename test/fixtures/{in/doctype-with-embedded-expr.astro => doctype-with-embedded-expr/input.astro} (100%) rename test/fixtures/{out/doctype-with-embedded-expr.astro => doctype-with-embedded-expr/output.astro} (85%) rename test/fixtures/{in/doctype-with-extra-attributes.astro => doctype-with-extra-attributes/input.astro} (100%) rename test/fixtures/{out/doctype-with-extra-attributes.astro => doctype-with-extra-attributes/output.astro} (100%) rename test/fixtures/{in/embedded-expr.astro => embedded-expr/input.astro} (100%) rename test/fixtures/{out/embedded-expr.astro => embedded-expr/output.astro} (85%) rename test/fixtures/{in/embedded-in-markdown.md => embedded-in-markdown/input.md} (99%) rename test/fixtures/{out/embedded-in-markdown.md => embedded-in-markdown/output.md} (99%) rename test/fixtures/{in/expr-and-html-comment.astro => expr-and-html-comment/input.astro} (100%) rename test/fixtures/{out/expr-and-html-comment.astro => expr-and-html-comment/output.astro} (100%) rename test/fixtures/{in/frontmatter.astro => frontmatter/input.astro} (100%) rename test/fixtures/{out/frontmatter.astro => frontmatter/output.astro} (100%) rename test/fixtures/{in/html-comment.astro => html-comment/input.astro} (100%) rename test/fixtures/{out/html-comment.astro => html-comment/output.astro} (100%) create mode 100644 test/fixtures/option-arrow-parens-always/input.astro create mode 100644 test/fixtures/option-arrow-parens-always/options.json create mode 100644 test/fixtures/option-arrow-parens-always/output.astro create mode 100644 test/fixtures/option-arrow-parens-avoid/input.astro create mode 100644 test/fixtures/option-arrow-parens-avoid/options.json create mode 100644 test/fixtures/option-arrow-parens-avoid/output.astro create mode 100644 test/fixtures/option-astro-sort-order-markup-styles/input.astro create mode 100644 test/fixtures/option-astro-sort-order-markup-styles/options.json create mode 100644 test/fixtures/option-astro-sort-order-markup-styles/output.astro create mode 100644 test/fixtures/option-astro-sort-order-styles-markup/input.astro create mode 100644 test/fixtures/option-astro-sort-order-styles-markup/options.json create mode 100644 test/fixtures/option-astro-sort-order-styles-markup/output.astro create mode 100644 test/fixtures/option-bracket-same-line-false/input.astro create mode 100644 test/fixtures/option-bracket-same-line-false/options.json create mode 100644 test/fixtures/option-bracket-same-line-false/output.astro create mode 100644 test/fixtures/option-bracket-same-line-true/input.astro create mode 100644 test/fixtures/option-bracket-same-line-true/options.json create mode 100644 test/fixtures/option-bracket-same-line-true/output.astro create mode 100644 test/fixtures/option-bracket-spacing-false/input.astro create mode 100644 test/fixtures/option-bracket-spacing-false/options.json create mode 100644 test/fixtures/option-bracket-spacing-false/output.astro create mode 100644 test/fixtures/option-bracket-spacing-true/input.astro create mode 100644 test/fixtures/option-bracket-spacing-true/options.json create mode 100644 test/fixtures/option-bracket-spacing-true/output.astro create mode 100644 test/fixtures/option-html-whitespace-sensitivity-css/input.astro create mode 100644 test/fixtures/option-html-whitespace-sensitivity-css/options.json create mode 100644 test/fixtures/option-html-whitespace-sensitivity-css/output.astro create mode 100644 test/fixtures/option-html-whitespace-sensitivity-ignore/input.astro create mode 100644 test/fixtures/option-html-whitespace-sensitivity-ignore/options.json create mode 100644 test/fixtures/option-html-whitespace-sensitivity-ignore/output.astro create mode 100644 test/fixtures/option-html-whitespace-sensitivity-strict/input.astro create mode 100644 test/fixtures/option-html-whitespace-sensitivity-strict/options.json create mode 100644 test/fixtures/option-html-whitespace-sensitivity-strict/output.astro create mode 100644 test/fixtures/option-jsx-single-quote-false/input.astro create mode 100644 test/fixtures/option-jsx-single-quote-false/options.json create mode 100644 test/fixtures/option-jsx-single-quote-false/output.astro create mode 100644 test/fixtures/option-jsx-single-quote-true/input.astro create mode 100644 test/fixtures/option-jsx-single-quote-true/options.json create mode 100644 test/fixtures/option-jsx-single-quote-true/output.astro create mode 100644 test/fixtures/option-print-width/input.astro create mode 100644 test/fixtures/option-print-width/options.json create mode 100644 test/fixtures/option-print-width/output.astro create mode 100644 test/fixtures/option-prose-wrap-always/input.md create mode 100644 test/fixtures/option-prose-wrap-always/options.json create mode 100644 test/fixtures/option-prose-wrap-always/output.md create mode 100644 test/fixtures/option-prose-wrap-never/input.md create mode 100644 test/fixtures/option-prose-wrap-never/options.json create mode 100644 test/fixtures/option-prose-wrap-never/output.md create mode 100644 test/fixtures/option-prose-wrap-preserve/input.md create mode 100644 test/fixtures/option-prose-wrap-preserve/options.json create mode 100644 test/fixtures/option-prose-wrap-preserve/output.md create mode 100644 test/fixtures/option-quote-props-as-needed/input.astro create mode 100644 test/fixtures/option-quote-props-as-needed/options.json create mode 100644 test/fixtures/option-quote-props-as-needed/output.astro create mode 100644 test/fixtures/option-quote-props-consistent/input.astro create mode 100644 test/fixtures/option-quote-props-consistent/options.json create mode 100644 test/fixtures/option-quote-props-consistent/output.astro create mode 100644 test/fixtures/option-quote-props-preserve/input.astro create mode 100644 test/fixtures/option-quote-props-preserve/options.json create mode 100644 test/fixtures/option-quote-props-preserve/output.astro create mode 100644 test/fixtures/option-semicolon-false/input.astro create mode 100644 test/fixtures/option-semicolon-false/options.json create mode 100644 test/fixtures/option-semicolon-false/output.astro create mode 100644 test/fixtures/option-semicolon-true/input.astro create mode 100644 test/fixtures/option-semicolon-true/options.json create mode 100644 test/fixtures/option-semicolon-true/output.astro create mode 100644 test/fixtures/option-single-quote-false/input.astro create mode 100644 test/fixtures/option-single-quote-false/options.json create mode 100644 test/fixtures/option-single-quote-false/output.astro create mode 100644 test/fixtures/option-single-quote-true/input.astro create mode 100644 test/fixtures/option-single-quote-true/options.json create mode 100644 test/fixtures/option-single-quote-true/output.astro create mode 100644 test/fixtures/option-tab-width/input.astro create mode 100644 test/fixtures/option-tab-width/options.json create mode 100644 test/fixtures/option-tab-width/output.astro create mode 100644 test/fixtures/option-trailing-comma-es5/input.astro create mode 100644 test/fixtures/option-trailing-comma-es5/options.json create mode 100644 test/fixtures/option-trailing-comma-es5/output.astro create mode 100644 test/fixtures/option-trailing-comma-none/input.astro create mode 100644 test/fixtures/option-trailing-comma-none/options.json create mode 100644 test/fixtures/option-trailing-comma-none/output.astro create mode 100644 test/fixtures/option-use-tabs-false/input.astro create mode 100644 test/fixtures/option-use-tabs-false/options.json create mode 100644 test/fixtures/option-use-tabs-false/output.astro create mode 100644 test/fixtures/option-use-tabs-true/input.astro create mode 100644 test/fixtures/option-use-tabs-true/options.json create mode 100644 test/fixtures/option-use-tabs-true/output.astro rename test/fixtures/{in/preserve-tag-case.astro => preserve-tag-case/input.astro} (100%) rename test/fixtures/{out/preserve-tag-case.astro => preserve-tag-case/output.astro} (100%) rename test/fixtures/{in/prettier-ignore-html.astro => prettier-ignore-html/input.astro} (100%) rename test/fixtures/{out/prettier-ignore-html.astro => prettier-ignore-html/output.astro} (100%) rename test/fixtures/{in/prettier-ignore-js.astro => prettier-ignore-js/input.astro} (100%) rename test/fixtures/{out/prettier-ignore-js.astro => prettier-ignore-js/output.astro} (100%) rename test/fixtures/{in/single-style-element.astro => single-style-element/input.astro} (100%) rename test/fixtures/{out/single-style-element.astro => single-style-element/output.astro} (100%) rename test/fixtures/{in/style-tag-attributes.astro => style-tag-attributes/input.astro} (100%) rename test/fixtures/{out/style-tag-attributes.astro => style-tag-attributes/output.astro} (100%) rename test/fixtures/{in/unclosed-tag.astro => unclosed-tag/input.astro} (100%) rename test/fixtures/{out/unclosed-tag.astro => unclosed-tag/output.astro} (100%) rename test/fixtures/{in/with-codespans.astro => with-codespans/input.astro} (100%) rename test/fixtures/{out/with-codespans.astro => with-codespans/output.astro} (100%) rename test/fixtures/{in/with-indented-sass.astro => with-indented-sass/input.astro} (100%) rename test/fixtures/{out/with-indented-sass.astro => with-indented-sass/output.astro} (100%) rename test/fixtures/{in/with-sass.astro => with-sass/input.astro} (100%) rename test/fixtures/{out/with-sass.astro => with-sass/output.astro} (100%) rename test/fixtures/{in/with-script.astro => with-script/input.astro} (100%) rename test/fixtures/{out/with-script.astro => with-script/output.astro} (100%) rename test/fixtures/{in/with-scss.astro => with-scss/input.astro} (100%) rename test/fixtures/{out/with-scss.astro => with-scss/output.astro} (100%) rename test/fixtures/{in/with-styles.astro => with-styles/input.astro} (100%) rename test/fixtures/{out/with-styles.astro => with-styles/output.astro} (100%) diff --git a/.changeset/witty-badgers-shave.md b/.changeset/witty-badgers-shave.md new file mode 100644 index 0000000..890141e --- /dev/null +++ b/.changeset/witty-badgers-shave.md @@ -0,0 +1,5 @@ +--- +'prettier-plugin-astro': patch +--- + +Add support for prettier options diff --git a/.prettierignore b/.prettierignore index 6c6b57a..ba14558 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,2 @@ -test/fixtures/**/* \ No newline at end of file +test/fixtures/**/*.md +test/fixtures/**/*.astro \ No newline at end of file diff --git a/src/printer.ts b/src/printer.ts index a06b3e5..97b3c57 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -28,6 +28,7 @@ import { isEmptyDoc, isEmptyTextNode, isInlineElement, + isInsideQuotedAttribute, isLine, isLoneMustacheTag, isNodeWithChildren, @@ -241,7 +242,7 @@ function print(path: AstPath, opts: ParserOptions, print: printFn): Doc { const isSelfClosingTag = isEmpty && (node.type !== 'Element' || selfClosingTags.indexOf(node.name) !== -1); const attributes = path.map(print, 'attributes'); if (isSelfClosingTag) { - return group(['<', node.name, indent(group([...attributes, ''])), ...[' ', `/>`]]); + return group(['<', node.name, indent(group(attributes)), line, `/>`]); // return group(['<', node.name, indent(group([...attributes, opts.jsxBracketNewLine ? dedent(line) : ''])), ...[opts.jsxBracketNewLine ? '' : ' ', `/>`]]); } try { @@ -313,7 +314,7 @@ function print(path: AstPath, opts: ParserOptions, print: printFn): Doc { body = () => path.map(print, 'children'); } - const openingTag = ['<', node.name, indent(group([...attributes, hugStart ? '' : !isPreTagContent(path) ? dedent(softline) : '']))]; + const openingTag = ['<', node.name, indent(group([...attributes, hugStart ? '' : !isPreTagContent(path) && !opts.bracketSameLine ? dedent(softline) : '']))]; // const openingTag = ['<', node.name, indent(group([...attributes, hugStart ? '' : opts.jsxBracketNewLine && !isPreTagContent(path) ? dedent(softline) : '']))]; if (hugStart && hugEnd) { @@ -393,8 +394,8 @@ function print(path: AstPath, opts: ParserOptions, print: printFn): Doc { return [ '{', printJS(path, print, 'expression', { - forceSingleLine: true, - forceSingleQuote: false, + forceSingleLine: isInsideQuotedAttribute(path), + forceSingleQuote: opts.jsxSingleQuote, }), '}', ]; diff --git a/test/astro-prettier.test.ts b/test/astro-prettier.test.ts index 536d65e..d38997c 100644 --- a/test/astro-prettier.test.ts +++ b/test/astro-prettier.test.ts @@ -1,73 +1,5 @@ -import test, { Macro } from 'ava'; -import { format, markdownFormat } from './test-utils.js'; -import { promises as fs } from 'fs'; -import { fileURLToPath, URL } from 'url'; - -const readFile = (path: string) => fs.readFile(fileURLToPath(new URL(`./fixtures${path}`, import.meta.url))).then((res) => res.toString().replace(/\r\n/g, '\n')); - -/** - * Utility to get `[src, out]` files - */ -const getFiles = async (name: string) => { - const [src, out] = await Promise.all([readFile(`/in/${name}.astro`), readFile(`/out/${name}.astro`)]); - return [src, out]; -}; - -const getMarkdownFiles = async (name: string) => { - const [src, out] = await Promise.all([readFile(`/in/${name}.md`), readFile(`/out/${name}.md`)]); - return [src, out]; -}; - -/** - * Macro for testing fixtures - */ -const Prettier: Macro<[string]> = async (t, name) => { - const [src, out] = await getFiles(name); - t.not(src, out, 'Unformated file and formated file are the same'); - - const formatted = format(src); - t.is(formatted, out, 'Incorrect formating'); - // test that our formatting is idempotent - const formattedTwice = format(formatted); - t.is(formatted, formattedTwice, 'Formatting is not idempotent'); -}; - -/** - * Macro title function for nice formatting - */ -Prettier.title = (title, name) => `${title}: - - - input: fixtures/in/${name}.astro - - output: fixtures/out/${name}.astro`; - -const PrettierUnaltered: Macro<[string]> = async (t, name) => { - const [src, out] = await getFiles(name); - t.is(src, out, 'Unformated file and formated file are not the same'); // the output should be unchanged - - const formatted = format(src); - t.is(formatted, out, 'Incorrect formating'); - // test that our formatting is idempotent - const formattedTwice = format(formatted); - t.is(formatted, formattedTwice, 'Formatting is not idempotent'); -}; - -PrettierUnaltered.title = Prettier.title; - -const PrettierMarkdown: Macro<[string]> = async (t, name) => { - const [src, out] = await getMarkdownFiles(name); - t.not(src, out, 'Unformated file and formated file are the same'); - - const formatted = markdownFormat(src); - t.is(formatted, out, 'Incorrect formating'); - // test that our formatting is idempotent - const formattedTwice = markdownFormat(formatted); - t.is(formatted, formattedTwice, 'Formatting is not idempotent'); -}; - -PrettierMarkdown.title = (title, name) => `${title}: - -- input: fixtures/in/${name}.md -- output: fixtures/out/${name}.md`; +import test from 'ava'; +import { Prettier, PrettierMarkdown, PrettierUnaltered } from './test-utils.js'; test('can format a basic Astro file', Prettier, 'basic'); @@ -122,3 +54,90 @@ test.todo("properly follow prettier' advice on formatting comments"); // note(drew): I think this is a function of Astro’s parser, not Prettier. We’ll have to handle helpful error messages there! test.todo('test whether invalid files provide helpful support messages / still try to be parsed by prettier?'); + +// https://prettier.io/docs/en/options.html#print-width +test('Can format an Astro file with prettier "printWidth" option', Prettier, 'option-print-width'); + +// https://prettier.io/docs/en/options.html#tab-width +test('Can format an Astro file with prettier "tabWidth" option', Prettier, 'option-tab-width'); + +// https://prettier.io/docs/en/options.html#tabs +test('Can format an Astro file with prettier "useTabs: true" option', Prettier, 'option-use-tabs-true'); + +// https://prettier.io/docs/en/options.html#tabs +test('Can format an Astro file with prettier "useTabs: false" option', Prettier, 'option-use-tabs-false'); + +// https://prettier.io/docs/en/options.html#semicolons +test('Can format an Astro file with prettier "semi: true" option', Prettier, 'option-semicolon-true'); + +// https://prettier.io/docs/en/options.html#semicolons +test('Can format an Astro file with prettier "semi: false" option', Prettier, 'option-semicolon-false'); + +// https://prettier.io/docs/en/options.html#quotes +test('Can format an Astro file with prettier "singleQuote: false" option', Prettier, 'option-single-quote-false'); + +// https://prettier.io/docs/en/options.html#quotes +test('Can format an Astro file with prettier "singleQuote: true" option', Prettier, 'option-single-quote-true'); + +// https://prettier.io/docs/en/options.html#quote-props +test('Can format an Astro file with prettier "quoteProps: as-needed" option', Prettier, 'option-quote-props-as-needed'); + +// https://prettier.io/docs/en/options.html#quote-props +test('Can format an Astro file with prettier "quoteProps: consistent" option', Prettier, 'option-quote-props-consistent'); + +// https://prettier.io/docs/en/options.html#quote-props +test('Can format an Astro file with prettier "quoteProps: preserve" option', Prettier, 'option-quote-props-preserve'); + +// https://prettier.io/docs/en/options.html#jsx-quotes +test('Can format an Astro file with prettier "jsxSingleQuote: false" option', Prettier, 'option-jsx-single-quote-false'); + +// https://prettier.io/docs/en/options.html#jsx-quotes +test('Can format an Astro file with prettier "jsxSingleQuote: true" option', Prettier, 'option-jsx-single-quote-true'); + +// https://prettier.io/docs/en/options.html#trailing-commas +test('Can format an Astro file with prettier "trailingComma: es5" option', Prettier, 'option-trailing-comma-es5'); + +// https://prettier.io/docs/en/options.html#trailing-commas +test('Can format an Astro file with prettier "trailingComma: none" option', Prettier, 'option-trailing-comma-none'); + +// https://prettier.io/docs/en/options.html#bracket-spacing +test('Can format an Astro file with prettier "bracketSpacing: true" option', Prettier, 'option-bracket-spacing-true'); + +// https://prettier.io/docs/en/options.html#bracket-spacing +test('Can format an Astro file with prettier "bracketSpacing: false" option', Prettier, 'option-bracket-spacing-false'); + +// https://prettier.io/docs/en/options.html#bracket-line +test('Can format an Astro file with prettier "bracketSameLine: false" option', Prettier, 'option-bracket-same-line-false'); + +// https://prettier.io/docs/en/options.html#bracket-line +test('Can format an Astro file with prettier "bracketSameLine: true" option', Prettier, 'option-bracket-same-line-true'); + +// https://prettier.io/docs/en/options.html#arrow-function-parentheses +test('Can format an Astro file with prettier "arrowParens: always" option', Prettier, 'option-arrow-parens-always'); + +// https://prettier.io/docs/en/options.html#arrow-function-parentheses +test('Can format an Astro file with prettier "arrowParens: avoid" option', Prettier, 'option-arrow-parens-avoid'); + +// https://prettier.io/docs/en/options.html#prose-wrap +test('Can format an Astro file with prettier "proseWrap: preserve" option', PrettierMarkdown, 'option-prose-wrap-preserve'); + +// https://prettier.io/docs/en/options.html#prose-wrap +test('Can format an Astro file with prettier "proseWrap: always" option', PrettierMarkdown, 'option-prose-wrap-always'); + +// https://prettier.io/docs/en/options.html#prose-wrap +test('Can format an Astro file with prettier "proseWrap: never" option', PrettierMarkdown, 'option-prose-wrap-never'); + +// https://prettier.io/docs/en/options.html#html-whitespace-sensitivity +test('Can format an Astro file with prettier "htmlWhitespaceSensitivity: css" option', Prettier, 'option-html-whitespace-sensitivity-css'); + +// https://prettier.io/docs/en/options.html#html-whitespace-sensitivity +test('Can format an Astro file with prettier "htmlWhitespaceSensitivity: strict" option', Prettier, 'option-html-whitespace-sensitivity-strict'); + +// https://prettier.io/docs/en/options.html#html-whitespace-sensitivity +test('Can format an Astro file with prettier "htmlWhitespaceSensitivity: ignore" option', Prettier, 'option-html-whitespace-sensitivity-ignore'); + +// astro option: astroSortOrder +test('Can format an Astro file with prettier "astroSortOrder: markup | styles" option', Prettier, 'option-astro-sort-order-markup-styles'); + +// astro option: astroSortOrder +test('Can format an Astro file with prettier "astroSortOrder: styles | markup" option', Prettier, 'option-astro-sort-order-styles-markup'); diff --git a/test/fixtures/in/attribute-with-embedded-expr.astro b/test/fixtures/attribute-with-embedded-expr/input.astro similarity index 100% rename from test/fixtures/in/attribute-with-embedded-expr.astro rename to test/fixtures/attribute-with-embedded-expr/input.astro diff --git a/test/fixtures/out/attribute-with-embedded-expr.astro b/test/fixtures/attribute-with-embedded-expr/output.astro similarity index 100% rename from test/fixtures/out/attribute-with-embedded-expr.astro rename to test/fixtures/attribute-with-embedded-expr/output.astro diff --git a/test/fixtures/in/autocloses-open-tags.astro b/test/fixtures/autocloses-open-tags/input.astro similarity index 100% rename from test/fixtures/in/autocloses-open-tags.astro rename to test/fixtures/autocloses-open-tags/input.astro diff --git a/test/fixtures/out/autocloses-open-tags.astro b/test/fixtures/autocloses-open-tags/output.astro similarity index 100% rename from test/fixtures/out/autocloses-open-tags.astro rename to test/fixtures/autocloses-open-tags/output.astro diff --git a/test/fixtures/in/basic.astro b/test/fixtures/basic/input.astro similarity index 100% rename from test/fixtures/in/basic.astro rename to test/fixtures/basic/input.astro diff --git a/test/fixtures/out/basic.astro b/test/fixtures/basic/output.astro similarity index 100% rename from test/fixtures/out/basic.astro rename to test/fixtures/basic/output.astro diff --git a/test/fixtures/in/converts-to-shorthand.astro b/test/fixtures/converts-to-shorthand/input.astro similarity index 100% rename from test/fixtures/in/converts-to-shorthand.astro rename to test/fixtures/converts-to-shorthand/input.astro diff --git a/test/fixtures/out/converts-to-shorthand.astro b/test/fixtures/converts-to-shorthand/output.astro similarity index 100% rename from test/fixtures/out/converts-to-shorthand.astro rename to test/fixtures/converts-to-shorthand/output.astro diff --git a/test/fixtures/in/doctype-with-embedded-expr.astro b/test/fixtures/doctype-with-embedded-expr/input.astro similarity index 100% rename from test/fixtures/in/doctype-with-embedded-expr.astro rename to test/fixtures/doctype-with-embedded-expr/input.astro diff --git a/test/fixtures/out/doctype-with-embedded-expr.astro b/test/fixtures/doctype-with-embedded-expr/output.astro similarity index 85% rename from test/fixtures/out/doctype-with-embedded-expr.astro rename to test/fixtures/doctype-with-embedded-expr/output.astro index d960352..79e12b3 100644 --- a/test/fixtures/out/doctype-with-embedded-expr.astro +++ b/test/fixtures/doctype-with-embedded-expr/output.astro @@ -16,8 +16,10 @@ const colors = ["red", "yellow", "blue"]; {"I'm some super long text and oh boy I sure do hope this formatter doesn't break me!"} - {colors.map((color) =>
+ {colors.map((color) => ( +
-
)} +
+ ))} diff --git a/test/fixtures/in/doctype-with-extra-attributes.astro b/test/fixtures/doctype-with-extra-attributes/input.astro similarity index 100% rename from test/fixtures/in/doctype-with-extra-attributes.astro rename to test/fixtures/doctype-with-extra-attributes/input.astro diff --git a/test/fixtures/out/doctype-with-extra-attributes.astro b/test/fixtures/doctype-with-extra-attributes/output.astro similarity index 100% rename from test/fixtures/out/doctype-with-extra-attributes.astro rename to test/fixtures/doctype-with-extra-attributes/output.astro diff --git a/test/fixtures/in/embedded-expr.astro b/test/fixtures/embedded-expr/input.astro similarity index 100% rename from test/fixtures/in/embedded-expr.astro rename to test/fixtures/embedded-expr/input.astro diff --git a/test/fixtures/out/embedded-expr.astro b/test/fixtures/embedded-expr/output.astro similarity index 85% rename from test/fixtures/out/embedded-expr.astro rename to test/fixtures/embedded-expr/output.astro index 6e873ac..0ae01ff 100644 --- a/test/fixtures/out/embedded-expr.astro +++ b/test/fixtures/embedded-expr/output.astro @@ -15,8 +15,10 @@ const colors = ["red", "yellow", "blue"]; {"I'm some super long text and oh boy I sure do hope this formatter doesn't break me!"} - {colors.map((color) =>
+ {colors.map((color) => ( +
-
)} +
+ ))} diff --git a/test/fixtures/in/embedded-in-markdown.md b/test/fixtures/embedded-in-markdown/input.md similarity index 99% rename from test/fixtures/in/embedded-in-markdown.md rename to test/fixtures/embedded-in-markdown/input.md index c228660..aa2ce12 100644 --- a/test/fixtures/in/embedded-in-markdown.md +++ b/test/fixtures/embedded-in-markdown/input.md @@ -21,7 +21,7 @@ For example, this three-line file is a valid Astro component: ```astro -
+

Hello world!

``` diff --git a/test/fixtures/out/embedded-in-markdown.md b/test/fixtures/embedded-in-markdown/output.md similarity index 99% rename from test/fixtures/out/embedded-in-markdown.md rename to test/fixtures/embedded-in-markdown/output.md index 5ec51f1..90d66fe 100644 --- a/test/fixtures/out/embedded-in-markdown.md +++ b/test/fixtures/embedded-in-markdown/output.md @@ -276,11 +276,13 @@ const items = ["Dog", "Cat", "Platipus"]; --- ``` diff --git a/test/fixtures/in/expr-and-html-comment.astro b/test/fixtures/expr-and-html-comment/input.astro similarity index 100% rename from test/fixtures/in/expr-and-html-comment.astro rename to test/fixtures/expr-and-html-comment/input.astro diff --git a/test/fixtures/out/expr-and-html-comment.astro b/test/fixtures/expr-and-html-comment/output.astro similarity index 100% rename from test/fixtures/out/expr-and-html-comment.astro rename to test/fixtures/expr-and-html-comment/output.astro diff --git a/test/fixtures/in/frontmatter.astro b/test/fixtures/frontmatter/input.astro similarity index 100% rename from test/fixtures/in/frontmatter.astro rename to test/fixtures/frontmatter/input.astro diff --git a/test/fixtures/out/frontmatter.astro b/test/fixtures/frontmatter/output.astro similarity index 100% rename from test/fixtures/out/frontmatter.astro rename to test/fixtures/frontmatter/output.astro diff --git a/test/fixtures/in/html-comment.astro b/test/fixtures/html-comment/input.astro similarity index 100% rename from test/fixtures/in/html-comment.astro rename to test/fixtures/html-comment/input.astro diff --git a/test/fixtures/out/html-comment.astro b/test/fixtures/html-comment/output.astro similarity index 100% rename from test/fixtures/out/html-comment.astro rename to test/fixtures/html-comment/output.astro diff --git a/test/fixtures/option-arrow-parens-always/input.astro b/test/fixtures/option-arrow-parens-always/input.astro new file mode 100644 index 0000000..8aa81fd --- /dev/null +++ b/test/fixtures/option-arrow-parens-always/input.astro @@ -0,0 +1,7 @@ +--- +const foo = ()=> false; + const foo2 = (a)=> a; +const foo3 = a=> { + return a + }; +--- \ No newline at end of file diff --git a/test/fixtures/option-arrow-parens-always/options.json b/test/fixtures/option-arrow-parens-always/options.json new file mode 100644 index 0000000..131fb14 --- /dev/null +++ b/test/fixtures/option-arrow-parens-always/options.json @@ -0,0 +1,3 @@ +{ + "arrowParens": "always" +} diff --git a/test/fixtures/option-arrow-parens-always/output.astro b/test/fixtures/option-arrow-parens-always/output.astro new file mode 100644 index 0000000..98cdb5d --- /dev/null +++ b/test/fixtures/option-arrow-parens-always/output.astro @@ -0,0 +1,7 @@ +--- +const foo = () => false; +const foo2 = (a) => a; +const foo3 = (a) => { + return a; +}; +--- diff --git a/test/fixtures/option-arrow-parens-avoid/input.astro b/test/fixtures/option-arrow-parens-avoid/input.astro new file mode 100644 index 0000000..8aa81fd --- /dev/null +++ b/test/fixtures/option-arrow-parens-avoid/input.astro @@ -0,0 +1,7 @@ +--- +const foo = ()=> false; + const foo2 = (a)=> a; +const foo3 = a=> { + return a + }; +--- \ No newline at end of file diff --git a/test/fixtures/option-arrow-parens-avoid/options.json b/test/fixtures/option-arrow-parens-avoid/options.json new file mode 100644 index 0000000..d68aa73 --- /dev/null +++ b/test/fixtures/option-arrow-parens-avoid/options.json @@ -0,0 +1,3 @@ +{ + "arrowParens": "avoid" +} diff --git a/test/fixtures/option-arrow-parens-avoid/output.astro b/test/fixtures/option-arrow-parens-avoid/output.astro new file mode 100644 index 0000000..c3d0dfd --- /dev/null +++ b/test/fixtures/option-arrow-parens-avoid/output.astro @@ -0,0 +1,7 @@ +--- +const foo = () => false; +const foo2 = a => a; +const foo3 = a => { + return a; +}; +--- diff --git a/test/fixtures/option-astro-sort-order-markup-styles/input.astro b/test/fixtures/option-astro-sort-order-markup-styles/input.astro new file mode 100644 index 0000000..14a4aa8 --- /dev/null +++ b/test/fixtures/option-astro-sort-order-markup-styles/input.astro @@ -0,0 +1,11 @@ +--- +const number = 10 +--- + + + +

lorem

\ No newline at end of file diff --git a/test/fixtures/option-astro-sort-order-markup-styles/options.json b/test/fixtures/option-astro-sort-order-markup-styles/options.json new file mode 100644 index 0000000..f6e0b3f --- /dev/null +++ b/test/fixtures/option-astro-sort-order-markup-styles/options.json @@ -0,0 +1,3 @@ +{ + "astroSortOrder": "markup | styles" +} diff --git a/test/fixtures/option-astro-sort-order-markup-styles/output.astro b/test/fixtures/option-astro-sort-order-markup-styles/output.astro new file mode 100644 index 0000000..4b9bec0 --- /dev/null +++ b/test/fixtures/option-astro-sort-order-markup-styles/output.astro @@ -0,0 +1,11 @@ +--- +const number = 10; +--- + +

lorem

+ + diff --git a/test/fixtures/option-astro-sort-order-styles-markup/input.astro b/test/fixtures/option-astro-sort-order-styles-markup/input.astro new file mode 100644 index 0000000..83473e9 --- /dev/null +++ b/test/fixtures/option-astro-sort-order-styles-markup/input.astro @@ -0,0 +1,10 @@ +--- +const number = 10 +--- + +

lorem

+ diff --git a/test/fixtures/option-astro-sort-order-styles-markup/options.json b/test/fixtures/option-astro-sort-order-styles-markup/options.json new file mode 100644 index 0000000..ae9d9f4 --- /dev/null +++ b/test/fixtures/option-astro-sort-order-styles-markup/options.json @@ -0,0 +1,3 @@ +{ + "astroSortOrder": "styles | markup" +} diff --git a/test/fixtures/option-astro-sort-order-styles-markup/output.astro b/test/fixtures/option-astro-sort-order-styles-markup/output.astro new file mode 100644 index 0000000..2475d47 --- /dev/null +++ b/test/fixtures/option-astro-sort-order-styles-markup/output.astro @@ -0,0 +1,11 @@ +--- +const number = 10; +--- + + + +

lorem

diff --git a/test/fixtures/option-bracket-same-line-false/input.astro b/test/fixtures/option-bracket-same-line-false/input.astro new file mode 100644 index 0000000..ea71ba4 --- /dev/null +++ b/test/fixtures/option-bracket-same-line-false/input.astro @@ -0,0 +1,15 @@ + + + + diff --git a/test/fixtures/option-bracket-same-line-false/options.json b/test/fixtures/option-bracket-same-line-false/options.json new file mode 100644 index 0000000..3380384 --- /dev/null +++ b/test/fixtures/option-bracket-same-line-false/options.json @@ -0,0 +1,3 @@ +{ + "bracketSameLine": false +} diff --git a/test/fixtures/option-bracket-same-line-false/output.astro b/test/fixtures/option-bracket-same-line-false/output.astro new file mode 100644 index 0000000..e814bdb --- /dev/null +++ b/test/fixtures/option-bracket-same-line-false/output.astro @@ -0,0 +1,16 @@ + + + diff --git a/test/fixtures/option-bracket-same-line-true/input.astro b/test/fixtures/option-bracket-same-line-true/input.astro new file mode 100644 index 0000000..ea71ba4 --- /dev/null +++ b/test/fixtures/option-bracket-same-line-true/input.astro @@ -0,0 +1,15 @@ + + + + diff --git a/test/fixtures/option-bracket-same-line-true/options.json b/test/fixtures/option-bracket-same-line-true/options.json new file mode 100644 index 0000000..9c1044f --- /dev/null +++ b/test/fixtures/option-bracket-same-line-true/options.json @@ -0,0 +1,3 @@ +{ + "bracketSameLine": true +} diff --git a/test/fixtures/option-bracket-same-line-true/output.astro b/test/fixtures/option-bracket-same-line-true/output.astro new file mode 100644 index 0000000..e606ec6 --- /dev/null +++ b/test/fixtures/option-bracket-same-line-true/output.astro @@ -0,0 +1,15 @@ + + + diff --git a/test/fixtures/option-bracket-spacing-false/input.astro b/test/fixtures/option-bracket-spacing-false/input.astro new file mode 100644 index 0000000..5b568c2 --- /dev/null +++ b/test/fixtures/option-bracket-spacing-false/input.astro @@ -0,0 +1,7 @@ +--- + const obj = { prop: false } + +--- +

+ {obj.prop} +

\ No newline at end of file diff --git a/test/fixtures/option-bracket-spacing-false/options.json b/test/fixtures/option-bracket-spacing-false/options.json new file mode 100644 index 0000000..81b81d2 --- /dev/null +++ b/test/fixtures/option-bracket-spacing-false/options.json @@ -0,0 +1,3 @@ +{ + "bracketSpacing": false +} diff --git a/test/fixtures/option-bracket-spacing-false/output.astro b/test/fixtures/option-bracket-spacing-false/output.astro new file mode 100644 index 0000000..7c7bf33 --- /dev/null +++ b/test/fixtures/option-bracket-spacing-false/output.astro @@ -0,0 +1,7 @@ +--- +const obj = {prop: false}; +--- + +

+ {obj.prop} +

diff --git a/test/fixtures/option-bracket-spacing-true/input.astro b/test/fixtures/option-bracket-spacing-true/input.astro new file mode 100644 index 0000000..5b568c2 --- /dev/null +++ b/test/fixtures/option-bracket-spacing-true/input.astro @@ -0,0 +1,7 @@ +--- + const obj = { prop: false } + +--- +

+ {obj.prop} +

\ No newline at end of file diff --git a/test/fixtures/option-bracket-spacing-true/options.json b/test/fixtures/option-bracket-spacing-true/options.json new file mode 100644 index 0000000..42ad37d --- /dev/null +++ b/test/fixtures/option-bracket-spacing-true/options.json @@ -0,0 +1,3 @@ +{ + "bracketSpacing": true +} diff --git a/test/fixtures/option-bracket-spacing-true/output.astro b/test/fixtures/option-bracket-spacing-true/output.astro new file mode 100644 index 0000000..7c13214 --- /dev/null +++ b/test/fixtures/option-bracket-spacing-true/output.astro @@ -0,0 +1,7 @@ +--- +const obj = { prop: false }; +--- + +

+ {obj.prop} +

diff --git a/test/fixtures/option-html-whitespace-sensitivity-css/input.astro b/test/fixtures/option-html-whitespace-sensitivity-css/input.astro new file mode 100644 index 0000000..1a2087b --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-css/input.astro @@ -0,0 +1,8 @@ +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto +
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
\ No newline at end of file diff --git a/test/fixtures/option-html-whitespace-sensitivity-css/options.json b/test/fixtures/option-html-whitespace-sensitivity-css/options.json new file mode 100644 index 0000000..db4922c --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-css/options.json @@ -0,0 +1,3 @@ +{ + "htmlWhitespaceSensitivity": "css" +} diff --git a/test/fixtures/option-html-whitespace-sensitivity-css/output.astro b/test/fixtures/option-html-whitespace-sensitivity-css/output.astro new file mode 100644 index 0000000..254a1a0 --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-css/output.astro @@ -0,0 +1,31 @@ +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, + dolor sit amet consectetur adipisicing elit. Odio, sint? + + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, + dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto + +
+ Architecto rerum architecto incidunt sint. +
+
+ Architecto rerum architecto incidunt sint. +
+
+ Architecto rerum architecto incidunt sint. +
+
+ Architecto rerum architecto incidunt sint. +
diff --git a/test/fixtures/option-html-whitespace-sensitivity-ignore/input.astro b/test/fixtures/option-html-whitespace-sensitivity-ignore/input.astro new file mode 100644 index 0000000..8a75c56 --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-ignore/input.astro @@ -0,0 +1,9 @@ +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto +
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+

lorem

lorem

loremlorem \ No newline at end of file diff --git a/test/fixtures/option-html-whitespace-sensitivity-ignore/options.json b/test/fixtures/option-html-whitespace-sensitivity-ignore/options.json new file mode 100644 index 0000000..f466c19 --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-ignore/options.json @@ -0,0 +1,3 @@ +{ + "htmlWhitespaceSensitivity": "ignore" +} diff --git a/test/fixtures/option-html-whitespace-sensitivity-ignore/output.astro b/test/fixtures/option-html-whitespace-sensitivity-ignore/output.astro new file mode 100644 index 0000000..f0bd117 --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-ignore/output.astro @@ -0,0 +1,35 @@ + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? + + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto + + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto + + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto + +
+ Architecto rerum architecto incidunt sint. +
+
+ Architecto rerum architecto incidunt sint. +
+
+ Architecto rerum architecto incidunt sint. +
+
+ Architecto rerum architecto incidunt sint. +
+

lorem

+

lorem

+lorem +lorem diff --git a/test/fixtures/option-html-whitespace-sensitivity-strict/input.astro b/test/fixtures/option-html-whitespace-sensitivity-strict/input.astro new file mode 100644 index 0000000..8a75c56 --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-strict/input.astro @@ -0,0 +1,9 @@ +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa architecto +
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint.
+

lorem

lorem

loremlorem \ No newline at end of file diff --git a/test/fixtures/option-html-whitespace-sensitivity-strict/options.json b/test/fixtures/option-html-whitespace-sensitivity-strict/options.json new file mode 100644 index 0000000..df69901 --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-strict/options.json @@ -0,0 +1,3 @@ +{ + "htmlWhitespaceSensitivity": "strict" +} diff --git a/test/fixtures/option-html-whitespace-sensitivity-strict/output.astro b/test/fixtures/option-html-whitespace-sensitivity-strict/output.astro new file mode 100644 index 0000000..3b54f3c --- /dev/null +++ b/test/fixtures/option-html-whitespace-sensitivity-strict/output.astro @@ -0,0 +1,32 @@ +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, + dolor sit amet consectetur adipisicing elit. Odio, sint? + + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto +Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, + dolor sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto + + Est molestiae sunt facilis quiasa architecto incidunt sint. Lorem ipsum, dolor + sit amet consectetur adipisicing elit. Odio, sint? sunt facilis quiasa + architecto + +
Architecto rerum architecto incidunt sint.
+
+ Architecto rerum architecto incidunt sint.
+
Architecto rerum architecto incidunt sint. +
+
+ Architecto rerum architecto incidunt sint. +
+

lorem

lorem

loremlorem diff --git a/test/fixtures/option-jsx-single-quote-false/input.astro b/test/fixtures/option-jsx-single-quote-false/input.astro new file mode 100644 index 0000000..eb2a584 --- /dev/null +++ b/test/fixtures/option-jsx-single-quote-false/input.astro @@ -0,0 +1,10 @@ +--- + const myVar = "lorem \"quoted\"" +function hello() { + return "hello" + 'lorem' +} +--- +

+ {hello + 'hello'} + {hello + "hello"} +

\ No newline at end of file diff --git a/test/fixtures/option-jsx-single-quote-false/options.json b/test/fixtures/option-jsx-single-quote-false/options.json new file mode 100644 index 0000000..d60ff4a --- /dev/null +++ b/test/fixtures/option-jsx-single-quote-false/options.json @@ -0,0 +1,3 @@ +{ + "jsxSingleQuote": false +} diff --git a/test/fixtures/option-jsx-single-quote-false/output.astro b/test/fixtures/option-jsx-single-quote-false/output.astro new file mode 100644 index 0000000..e5812e4 --- /dev/null +++ b/test/fixtures/option-jsx-single-quote-false/output.astro @@ -0,0 +1,11 @@ +--- +const myVar = 'lorem "quoted"'; +function hello() { + return "hello" + "lorem"; +} +--- + +

+ {hello + "hello"} + {hello + "hello"} +

diff --git a/test/fixtures/option-jsx-single-quote-true/input.astro b/test/fixtures/option-jsx-single-quote-true/input.astro new file mode 100644 index 0000000..ce79d1e --- /dev/null +++ b/test/fixtures/option-jsx-single-quote-true/input.astro @@ -0,0 +1,10 @@ +--- + const myVar = "lorem \"quoted\"" +function hello() { + return "hello" + 'lorem' +} +--- +

+ {hello + "hello"} + {hello + 'hello'} +

\ No newline at end of file diff --git a/test/fixtures/option-jsx-single-quote-true/options.json b/test/fixtures/option-jsx-single-quote-true/options.json new file mode 100644 index 0000000..111c022 --- /dev/null +++ b/test/fixtures/option-jsx-single-quote-true/options.json @@ -0,0 +1,3 @@ +{ + "jsxSingleQuote": true +} diff --git a/test/fixtures/option-jsx-single-quote-true/output.astro b/test/fixtures/option-jsx-single-quote-true/output.astro new file mode 100644 index 0000000..cc1c62e --- /dev/null +++ b/test/fixtures/option-jsx-single-quote-true/output.astro @@ -0,0 +1,11 @@ +--- +const myVar = 'lorem "quoted"'; +function hello() { + return "hello" + "lorem"; +} +--- + +

+ {hello + 'hello'} + {hello + 'hello'} +

diff --git a/test/fixtures/option-print-width/input.astro b/test/fixtures/option-print-width/input.astro new file mode 100644 index 0000000..0a1ac81 --- /dev/null +++ b/test/fixtures/option-print-width/input.astro @@ -0,0 +1,14 @@ +--- +const arrayTest = [{ + content: "Princesseuh", + attributes: { x: "55", y: "105", "font-size": "70px", fill: "#fefffe" }, + }, + { + content: "Introducing Astro: Ship Less JavaScript", + attributes: { x: "50", y: "325", "font-size": "40px", fill: "#fefffe" }, + }, +] +--- + diff --git a/test/fixtures/option-print-width/options.json b/test/fixtures/option-print-width/options.json new file mode 100644 index 0000000..de753c5 --- /dev/null +++ b/test/fixtures/option-print-width/options.json @@ -0,0 +1,3 @@ +{ + "printWidth": 100 +} diff --git a/test/fixtures/option-print-width/output.astro b/test/fixtures/option-print-width/output.astro new file mode 100644 index 0000000..98cc26d --- /dev/null +++ b/test/fixtures/option-print-width/output.astro @@ -0,0 +1,25 @@ +--- +const arrayTest = [ + { + content: "Princesseuh", + attributes: { x: "55", y: "105", "font-size": "70px", fill: "#fefffe" }, + }, + { + content: "Introducing Astro: Ship Less JavaScript", + attributes: { x: "50", y: "325", "font-size": "40px", fill: "#fefffe" }, + }, +]; +--- + + diff --git a/test/fixtures/option-prose-wrap-always/input.md b/test/fixtures/option-prose-wrap-always/input.md new file mode 100644 index 0000000..33db8e2 --- /dev/null +++ b/test/fixtures/option-prose-wrap-always/input.md @@ -0,0 +1,9 @@ +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? + +``` +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? +``` \ No newline at end of file diff --git a/test/fixtures/option-prose-wrap-always/options.json b/test/fixtures/option-prose-wrap-always/options.json new file mode 100644 index 0000000..cfae7e2 --- /dev/null +++ b/test/fixtures/option-prose-wrap-always/options.json @@ -0,0 +1,4 @@ +{ + "proseWrap": "always", + "printWidth": 80 +} diff --git a/test/fixtures/option-prose-wrap-always/output.md b/test/fixtures/option-prose-wrap-always/output.md new file mode 100644 index 0000000..745504c --- /dev/null +++ b/test/fixtures/option-prose-wrap-always/output.md @@ -0,0 +1,11 @@ +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi +saepe odit sed repellendus voluptatum sunt, quia dolorem quam quos aliquid +dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis +recusandae, animi odit quis cupiditate non culpa voluptatem, officiis magnam +quod aperiam perferendis obcaecati temporibus, iure natus hic? + +``` +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? +``` diff --git a/test/fixtures/option-prose-wrap-never/input.md b/test/fixtures/option-prose-wrap-never/input.md new file mode 100644 index 0000000..33db8e2 --- /dev/null +++ b/test/fixtures/option-prose-wrap-never/input.md @@ -0,0 +1,9 @@ +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? + +``` +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? +``` \ No newline at end of file diff --git a/test/fixtures/option-prose-wrap-never/options.json b/test/fixtures/option-prose-wrap-never/options.json new file mode 100644 index 0000000..0eeb27b --- /dev/null +++ b/test/fixtures/option-prose-wrap-never/options.json @@ -0,0 +1,4 @@ +{ + "proseWrap": "never", + "printWidth": 80 +} diff --git a/test/fixtures/option-prose-wrap-never/output.md b/test/fixtures/option-prose-wrap-never/output.md new file mode 100644 index 0000000..f2b6b90 --- /dev/null +++ b/test/fixtures/option-prose-wrap-never/output.md @@ -0,0 +1,7 @@ +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? + +``` +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? +``` diff --git a/test/fixtures/option-prose-wrap-preserve/input.md b/test/fixtures/option-prose-wrap-preserve/input.md new file mode 100644 index 0000000..1c33f93 --- /dev/null +++ b/test/fixtures/option-prose-wrap-preserve/input.md @@ -0,0 +1,8 @@ +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? +``` +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? +``` \ No newline at end of file diff --git a/test/fixtures/option-prose-wrap-preserve/options.json b/test/fixtures/option-prose-wrap-preserve/options.json new file mode 100644 index 0000000..e6af151 --- /dev/null +++ b/test/fixtures/option-prose-wrap-preserve/options.json @@ -0,0 +1,4 @@ +{ + "proseWrap": "preserve", + "printWidth": 80 +} diff --git a/test/fixtures/option-prose-wrap-preserve/output.md b/test/fixtures/option-prose-wrap-preserve/output.md new file mode 100644 index 0000000..e29feb8 --- /dev/null +++ b/test/fixtures/option-prose-wrap-preserve/output.md @@ -0,0 +1,9 @@ +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? + +``` +Lorem ipsum dolor sit amet consectetur adipisicing elit. At dignissimos quasi saepe odit sed repellendus voluptatum sunt, quia +dolorem quam quos aliquid dolorum, iste suscipit nisi aliquam. Illum eius velit distinctio corporis recusandae, animi odit quis cupiditate +non culpa voluptatem, officiis magnam quod aperiam perferendis obcaecati temporibus, iure natus hic? +``` diff --git a/test/fixtures/option-quote-props-as-needed/input.astro b/test/fixtures/option-quote-props-as-needed/input.astro new file mode 100644 index 0000000..917b26f --- /dev/null +++ b/test/fixtures/option-quote-props-as-needed/input.astro @@ -0,0 +1,9 @@ +--- + const myObject = { + "prop-1": "hello", + 'prop2': 10, + prop3: { + "prop4": false, + }, + } +--- \ No newline at end of file diff --git a/test/fixtures/option-quote-props-as-needed/options.json b/test/fixtures/option-quote-props-as-needed/options.json new file mode 100644 index 0000000..c75840a --- /dev/null +++ b/test/fixtures/option-quote-props-as-needed/options.json @@ -0,0 +1,3 @@ +{ + "quoteProps": "as-needed" +} diff --git a/test/fixtures/option-quote-props-as-needed/output.astro b/test/fixtures/option-quote-props-as-needed/output.astro new file mode 100644 index 0000000..16b68dd --- /dev/null +++ b/test/fixtures/option-quote-props-as-needed/output.astro @@ -0,0 +1,9 @@ +--- +const myObject = { + "prop-1": "hello", + prop2: 10, + prop3: { + prop4: false, + }, +}; +--- diff --git a/test/fixtures/option-quote-props-consistent/input.astro b/test/fixtures/option-quote-props-consistent/input.astro new file mode 100644 index 0000000..6acb807 --- /dev/null +++ b/test/fixtures/option-quote-props-consistent/input.astro @@ -0,0 +1,9 @@ +--- + const myObject = { + "prop-1": "hello", + prop2: 10, + prop3: { + prop4: false, + }, + } +--- \ No newline at end of file diff --git a/test/fixtures/option-quote-props-consistent/options.json b/test/fixtures/option-quote-props-consistent/options.json new file mode 100644 index 0000000..dffb6f2 --- /dev/null +++ b/test/fixtures/option-quote-props-consistent/options.json @@ -0,0 +1,3 @@ +{ + "quoteProps": "consistent" +} diff --git a/test/fixtures/option-quote-props-consistent/output.astro b/test/fixtures/option-quote-props-consistent/output.astro new file mode 100644 index 0000000..c96be87 --- /dev/null +++ b/test/fixtures/option-quote-props-consistent/output.astro @@ -0,0 +1,9 @@ +--- +const myObject = { + "prop-1": "hello", + "prop2": 10, + "prop3": { + prop4: false, + }, +}; +--- diff --git a/test/fixtures/option-quote-props-preserve/input.astro b/test/fixtures/option-quote-props-preserve/input.astro new file mode 100644 index 0000000..917b26f --- /dev/null +++ b/test/fixtures/option-quote-props-preserve/input.astro @@ -0,0 +1,9 @@ +--- + const myObject = { + "prop-1": "hello", + 'prop2': 10, + prop3: { + "prop4": false, + }, + } +--- \ No newline at end of file diff --git a/test/fixtures/option-quote-props-preserve/options.json b/test/fixtures/option-quote-props-preserve/options.json new file mode 100644 index 0000000..c77800f --- /dev/null +++ b/test/fixtures/option-quote-props-preserve/options.json @@ -0,0 +1,3 @@ +{ + "quoteProps": "preserve" +} diff --git a/test/fixtures/option-quote-props-preserve/output.astro b/test/fixtures/option-quote-props-preserve/output.astro new file mode 100644 index 0000000..2f5b900 --- /dev/null +++ b/test/fixtures/option-quote-props-preserve/output.astro @@ -0,0 +1,9 @@ +--- +const myObject = { + "prop-1": "hello", + "prop2": 10, + prop3: { + "prop4": false, + }, +}; +--- diff --git a/test/fixtures/option-semicolon-false/input.astro b/test/fixtures/option-semicolon-false/input.astro new file mode 100644 index 0000000..75a25ea --- /dev/null +++ b/test/fixtures/option-semicolon-false/input.astro @@ -0,0 +1,9 @@ +--- + const number = 10 +function hello() { + return "hello" +} +--- +

+ {hello} +

\ No newline at end of file diff --git a/test/fixtures/option-semicolon-false/options.json b/test/fixtures/option-semicolon-false/options.json new file mode 100644 index 0000000..cce9d3c --- /dev/null +++ b/test/fixtures/option-semicolon-false/options.json @@ -0,0 +1,3 @@ +{ + "semi": false +} diff --git a/test/fixtures/option-semicolon-false/output.astro b/test/fixtures/option-semicolon-false/output.astro new file mode 100644 index 0000000..50cd7ba --- /dev/null +++ b/test/fixtures/option-semicolon-false/output.astro @@ -0,0 +1,10 @@ +--- +const number = 10 +function hello() { + return "hello" +} +--- + +

+ {hello} +

diff --git a/test/fixtures/option-semicolon-true/input.astro b/test/fixtures/option-semicolon-true/input.astro new file mode 100644 index 0000000..75a25ea --- /dev/null +++ b/test/fixtures/option-semicolon-true/input.astro @@ -0,0 +1,9 @@ +--- + const number = 10 +function hello() { + return "hello" +} +--- +

+ {hello} +

\ No newline at end of file diff --git a/test/fixtures/option-semicolon-true/options.json b/test/fixtures/option-semicolon-true/options.json new file mode 100644 index 0000000..732e220 --- /dev/null +++ b/test/fixtures/option-semicolon-true/options.json @@ -0,0 +1,3 @@ +{ + "semi": true +} diff --git a/test/fixtures/option-semicolon-true/output.astro b/test/fixtures/option-semicolon-true/output.astro new file mode 100644 index 0000000..85c6924 --- /dev/null +++ b/test/fixtures/option-semicolon-true/output.astro @@ -0,0 +1,10 @@ +--- +const number = 10; +function hello() { + return "hello"; +} +--- + +

+ {hello} +

diff --git a/test/fixtures/option-single-quote-false/input.astro b/test/fixtures/option-single-quote-false/input.astro new file mode 100644 index 0000000..dcf9bbf --- /dev/null +++ b/test/fixtures/option-single-quote-false/input.astro @@ -0,0 +1,9 @@ +--- + const myVar = "lorem \"quoted\"" +function hello() { + return "hello" + 'lorem' +} +--- +

+ {hello + "hello"} +

\ No newline at end of file diff --git a/test/fixtures/option-single-quote-false/options.json b/test/fixtures/option-single-quote-false/options.json new file mode 100644 index 0000000..1ca87ab --- /dev/null +++ b/test/fixtures/option-single-quote-false/options.json @@ -0,0 +1,3 @@ +{ + "singleQuote": false +} diff --git a/test/fixtures/option-single-quote-false/output.astro b/test/fixtures/option-single-quote-false/output.astro new file mode 100644 index 0000000..7907ace --- /dev/null +++ b/test/fixtures/option-single-quote-false/output.astro @@ -0,0 +1,10 @@ +--- +const myVar = 'lorem "quoted"'; +function hello() { + return "hello" + "lorem"; +} +--- + +

+ {hello + "hello"} +

diff --git a/test/fixtures/option-single-quote-true/input.astro b/test/fixtures/option-single-quote-true/input.astro new file mode 100644 index 0000000..dcf9bbf --- /dev/null +++ b/test/fixtures/option-single-quote-true/input.astro @@ -0,0 +1,9 @@ +--- + const myVar = "lorem \"quoted\"" +function hello() { + return "hello" + 'lorem' +} +--- +

+ {hello + "hello"} +

\ No newline at end of file diff --git a/test/fixtures/option-single-quote-true/options.json b/test/fixtures/option-single-quote-true/options.json new file mode 100644 index 0000000..544138b --- /dev/null +++ b/test/fixtures/option-single-quote-true/options.json @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/test/fixtures/option-single-quote-true/output.astro b/test/fixtures/option-single-quote-true/output.astro new file mode 100644 index 0000000..a29dab4 --- /dev/null +++ b/test/fixtures/option-single-quote-true/output.astro @@ -0,0 +1,10 @@ +--- +const myVar = 'lorem "quoted"'; +function hello() { + return 'hello' + 'lorem'; +} +--- + +

+ {hello + 'hello'} +

diff --git a/test/fixtures/option-tab-width/input.astro b/test/fixtures/option-tab-width/input.astro new file mode 100644 index 0000000..854e530 --- /dev/null +++ b/test/fixtures/option-tab-width/input.astro @@ -0,0 +1,8 @@ +--- +function hello() { + return "hello" +} +--- +

+ {hello} +

\ No newline at end of file diff --git a/test/fixtures/option-tab-width/options.json b/test/fixtures/option-tab-width/options.json new file mode 100644 index 0000000..d7f8afd --- /dev/null +++ b/test/fixtures/option-tab-width/options.json @@ -0,0 +1,3 @@ +{ + "tabWidth": 3 +} diff --git a/test/fixtures/option-tab-width/output.astro b/test/fixtures/option-tab-width/output.astro new file mode 100644 index 0000000..73d5ed5 --- /dev/null +++ b/test/fixtures/option-tab-width/output.astro @@ -0,0 +1,9 @@ +--- +function hello() { + return "hello"; +} +--- + +

+ {hello} +

diff --git a/test/fixtures/option-trailing-comma-es5/input.astro b/test/fixtures/option-trailing-comma-es5/input.astro new file mode 100644 index 0000000..acb298b --- /dev/null +++ b/test/fixtures/option-trailing-comma-es5/input.astro @@ -0,0 +1,12 @@ +--- + const myArr = [ + 1, + "lorem", + false, + "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non aperiam amet nesciunt dolorem. Voluptatum delectus autem sapiente voluptatem? In, quam?", { + prop4: false } + ] +--- +

+ {myArr[0]} +

\ No newline at end of file diff --git a/test/fixtures/option-trailing-comma-es5/options.json b/test/fixtures/option-trailing-comma-es5/options.json new file mode 100644 index 0000000..757fd64 --- /dev/null +++ b/test/fixtures/option-trailing-comma-es5/options.json @@ -0,0 +1,3 @@ +{ + "trailingComma": "es5" +} diff --git a/test/fixtures/option-trailing-comma-es5/output.astro b/test/fixtures/option-trailing-comma-es5/output.astro new file mode 100644 index 0000000..6547d6d --- /dev/null +++ b/test/fixtures/option-trailing-comma-es5/output.astro @@ -0,0 +1,15 @@ +--- +const myArr = [ + 1, + "lorem", + false, + "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non aperiam amet nesciunt dolorem. Voluptatum delectus autem sapiente voluptatem? In, quam?", + { + prop4: false, + }, +]; +--- + +

+ {myArr[0]} +

diff --git a/test/fixtures/option-trailing-comma-none/input.astro b/test/fixtures/option-trailing-comma-none/input.astro new file mode 100644 index 0000000..acb298b --- /dev/null +++ b/test/fixtures/option-trailing-comma-none/input.astro @@ -0,0 +1,12 @@ +--- + const myArr = [ + 1, + "lorem", + false, + "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non aperiam amet nesciunt dolorem. Voluptatum delectus autem sapiente voluptatem? In, quam?", { + prop4: false } + ] +--- +

+ {myArr[0]} +

\ No newline at end of file diff --git a/test/fixtures/option-trailing-comma-none/options.json b/test/fixtures/option-trailing-comma-none/options.json new file mode 100644 index 0000000..36b3563 --- /dev/null +++ b/test/fixtures/option-trailing-comma-none/options.json @@ -0,0 +1,3 @@ +{ + "trailingComma": "none" +} diff --git a/test/fixtures/option-trailing-comma-none/output.astro b/test/fixtures/option-trailing-comma-none/output.astro new file mode 100644 index 0000000..ad8d509 --- /dev/null +++ b/test/fixtures/option-trailing-comma-none/output.astro @@ -0,0 +1,15 @@ +--- +const myArr = [ + 1, + "lorem", + false, + "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non aperiam amet nesciunt dolorem. Voluptatum delectus autem sapiente voluptatem? In, quam?", + { + prop4: false + } +]; +--- + +

+ {myArr[0]} +

diff --git a/test/fixtures/option-use-tabs-false/input.astro b/test/fixtures/option-use-tabs-false/input.astro new file mode 100644 index 0000000..854e530 --- /dev/null +++ b/test/fixtures/option-use-tabs-false/input.astro @@ -0,0 +1,8 @@ +--- +function hello() { + return "hello" +} +--- +

+ {hello} +

\ No newline at end of file diff --git a/test/fixtures/option-use-tabs-false/options.json b/test/fixtures/option-use-tabs-false/options.json new file mode 100644 index 0000000..df26abd --- /dev/null +++ b/test/fixtures/option-use-tabs-false/options.json @@ -0,0 +1,3 @@ +{ + "useTabs": false +} diff --git a/test/fixtures/option-use-tabs-false/output.astro b/test/fixtures/option-use-tabs-false/output.astro new file mode 100644 index 0000000..9fa8e43 --- /dev/null +++ b/test/fixtures/option-use-tabs-false/output.astro @@ -0,0 +1,9 @@ +--- +function hello() { + return "hello"; +} +--- + +

+ {hello} +

diff --git a/test/fixtures/option-use-tabs-true/input.astro b/test/fixtures/option-use-tabs-true/input.astro new file mode 100644 index 0000000..854e530 --- /dev/null +++ b/test/fixtures/option-use-tabs-true/input.astro @@ -0,0 +1,8 @@ +--- +function hello() { + return "hello" +} +--- +

+ {hello} +

\ No newline at end of file diff --git a/test/fixtures/option-use-tabs-true/options.json b/test/fixtures/option-use-tabs-true/options.json new file mode 100644 index 0000000..661f253 --- /dev/null +++ b/test/fixtures/option-use-tabs-true/options.json @@ -0,0 +1,3 @@ +{ + "useTabs": true +} diff --git a/test/fixtures/option-use-tabs-true/output.astro b/test/fixtures/option-use-tabs-true/output.astro new file mode 100644 index 0000000..513f1c7 --- /dev/null +++ b/test/fixtures/option-use-tabs-true/output.astro @@ -0,0 +1,9 @@ +--- +function hello() { + return "hello"; +} +--- + +

+ {hello} +

diff --git a/test/fixtures/in/preserve-tag-case.astro b/test/fixtures/preserve-tag-case/input.astro similarity index 100% rename from test/fixtures/in/preserve-tag-case.astro rename to test/fixtures/preserve-tag-case/input.astro diff --git a/test/fixtures/out/preserve-tag-case.astro b/test/fixtures/preserve-tag-case/output.astro similarity index 100% rename from test/fixtures/out/preserve-tag-case.astro rename to test/fixtures/preserve-tag-case/output.astro diff --git a/test/fixtures/in/prettier-ignore-html.astro b/test/fixtures/prettier-ignore-html/input.astro similarity index 100% rename from test/fixtures/in/prettier-ignore-html.astro rename to test/fixtures/prettier-ignore-html/input.astro diff --git a/test/fixtures/out/prettier-ignore-html.astro b/test/fixtures/prettier-ignore-html/output.astro similarity index 100% rename from test/fixtures/out/prettier-ignore-html.astro rename to test/fixtures/prettier-ignore-html/output.astro diff --git a/test/fixtures/in/prettier-ignore-js.astro b/test/fixtures/prettier-ignore-js/input.astro similarity index 100% rename from test/fixtures/in/prettier-ignore-js.astro rename to test/fixtures/prettier-ignore-js/input.astro diff --git a/test/fixtures/out/prettier-ignore-js.astro b/test/fixtures/prettier-ignore-js/output.astro similarity index 100% rename from test/fixtures/out/prettier-ignore-js.astro rename to test/fixtures/prettier-ignore-js/output.astro diff --git a/test/fixtures/in/single-style-element.astro b/test/fixtures/single-style-element/input.astro similarity index 100% rename from test/fixtures/in/single-style-element.astro rename to test/fixtures/single-style-element/input.astro diff --git a/test/fixtures/out/single-style-element.astro b/test/fixtures/single-style-element/output.astro similarity index 100% rename from test/fixtures/out/single-style-element.astro rename to test/fixtures/single-style-element/output.astro diff --git a/test/fixtures/in/style-tag-attributes.astro b/test/fixtures/style-tag-attributes/input.astro similarity index 100% rename from test/fixtures/in/style-tag-attributes.astro rename to test/fixtures/style-tag-attributes/input.astro diff --git a/test/fixtures/out/style-tag-attributes.astro b/test/fixtures/style-tag-attributes/output.astro similarity index 100% rename from test/fixtures/out/style-tag-attributes.astro rename to test/fixtures/style-tag-attributes/output.astro diff --git a/test/fixtures/in/unclosed-tag.astro b/test/fixtures/unclosed-tag/input.astro similarity index 100% rename from test/fixtures/in/unclosed-tag.astro rename to test/fixtures/unclosed-tag/input.astro diff --git a/test/fixtures/out/unclosed-tag.astro b/test/fixtures/unclosed-tag/output.astro similarity index 100% rename from test/fixtures/out/unclosed-tag.astro rename to test/fixtures/unclosed-tag/output.astro diff --git a/test/fixtures/in/with-codespans.astro b/test/fixtures/with-codespans/input.astro similarity index 100% rename from test/fixtures/in/with-codespans.astro rename to test/fixtures/with-codespans/input.astro diff --git a/test/fixtures/out/with-codespans.astro b/test/fixtures/with-codespans/output.astro similarity index 100% rename from test/fixtures/out/with-codespans.astro rename to test/fixtures/with-codespans/output.astro diff --git a/test/fixtures/in/with-indented-sass.astro b/test/fixtures/with-indented-sass/input.astro similarity index 100% rename from test/fixtures/in/with-indented-sass.astro rename to test/fixtures/with-indented-sass/input.astro diff --git a/test/fixtures/out/with-indented-sass.astro b/test/fixtures/with-indented-sass/output.astro similarity index 100% rename from test/fixtures/out/with-indented-sass.astro rename to test/fixtures/with-indented-sass/output.astro diff --git a/test/fixtures/in/with-sass.astro b/test/fixtures/with-sass/input.astro similarity index 100% rename from test/fixtures/in/with-sass.astro rename to test/fixtures/with-sass/input.astro diff --git a/test/fixtures/out/with-sass.astro b/test/fixtures/with-sass/output.astro similarity index 100% rename from test/fixtures/out/with-sass.astro rename to test/fixtures/with-sass/output.astro diff --git a/test/fixtures/in/with-script.astro b/test/fixtures/with-script/input.astro similarity index 100% rename from test/fixtures/in/with-script.astro rename to test/fixtures/with-script/input.astro diff --git a/test/fixtures/out/with-script.astro b/test/fixtures/with-script/output.astro similarity index 100% rename from test/fixtures/out/with-script.astro rename to test/fixtures/with-script/output.astro diff --git a/test/fixtures/in/with-scss.astro b/test/fixtures/with-scss/input.astro similarity index 100% rename from test/fixtures/in/with-scss.astro rename to test/fixtures/with-scss/input.astro diff --git a/test/fixtures/out/with-scss.astro b/test/fixtures/with-scss/output.astro similarity index 100% rename from test/fixtures/out/with-scss.astro rename to test/fixtures/with-scss/output.astro diff --git a/test/fixtures/in/with-styles.astro b/test/fixtures/with-styles/input.astro similarity index 100% rename from test/fixtures/in/with-styles.astro rename to test/fixtures/with-styles/input.astro diff --git a/test/fixtures/out/with-styles.astro b/test/fixtures/with-styles/output.astro similarity index 100% rename from test/fixtures/out/with-styles.astro rename to test/fixtures/with-styles/output.astro diff --git a/test/test-utils.ts b/test/test-utils.ts index b22a868..9a79af3 100644 --- a/test/test-utils.ts +++ b/test/test-utils.ts @@ -1,11 +1,12 @@ import prettier from 'prettier'; import { fileURLToPath } from 'url'; +import { promises as fs } from 'fs'; +import { Macro } from 'ava'; /** * format the contents of an astro file */ -export function format(contents: string, options: prettier.Options = {}): string { - // for some reason uvu isn't detecting throwing of strings?? +function format(contents: string, options: prettier.Options = {}): string { try { return prettier.format(contents, { parser: 'astro', @@ -23,11 +24,12 @@ export function format(contents: string, options: prettier.Options = {}): string return ''; } -export function markdownFormat(contents: string): string { +function markdownFormat(contents: string, options: prettier.Options = {}): string { try { return prettier.format(contents, { parser: 'markdown', plugins: [fileURLToPath(new URL('../', import.meta.url).toString())], + ...options, }); } catch (e) { if (e instanceof Error) { @@ -39,3 +41,88 @@ export function markdownFormat(contents: string): string { } return ''; } + +async function readFile(path: string) { + const res = await fs.readFile(fileURLToPath(new URL(`./fixtures${path}`, import.meta.url).toString())); + return res.toString().replace(/\r\n/g, '\n'); +} + +/** + * Utility to get `[src, out]` files + */ +async function getFiles(name: string) { + const [src, out] = await Promise.all([readFile(`/${name}/input.astro`), readFile(`/${name}/output.astro`)]); + return [src, out]; +} + +async function getOptions(name: string) { + let options: object; + try { + options = JSON.parse(await readFile(`/${name}/options.json`)); + } catch (e) { + options = {}; + } + return options; +} + +async function getMarkdownFiles(name: string) { + const [src, out] = await Promise.all([readFile(`/${name}/input.md`), readFile(`/${name}/output.md`)]); + return [src, out]; +} + +/** + * Macro for testing fixtures + */ +export const Prettier: Macro<[string]> = async (t, name) => { + const [src, out] = await getFiles(name); + t.not(src, out, 'Unformated file and formated file are the same'); + + const options = await getOptions(name); + + const formatted = format(src, options); + t.is(formatted, out, 'Incorrect formating'); + // test that our formatting is idempotent + const formattedTwice = format(formatted, options); + t.is(formatted, formattedTwice, 'Formatting is not idempotent'); +}; + +/** + * Macro title function for nice formatting + */ +Prettier.title = (title, name) => `${title}: + + - input: fixtures/${name}/input.astro + - output: fixtures/${name}/output.astro`; + +export const PrettierUnaltered: Macro<[string]> = async (t, name) => { + const [src, out] = await getFiles(name); + t.is(src, out, 'Unformated file and formated file are not the same'); // the output should be unchanged + + const options = await getOptions(name); + + const formatted = format(src, options); + t.is(formatted, out, 'Incorrect formating'); + // test that our formatting is idempotent + const formattedTwice = format(formatted); + t.is(formatted, formattedTwice, 'Formatting is not idempotent'); +}; + +PrettierUnaltered.title = Prettier.title; + +export const PrettierMarkdown: Macro<[string]> = async (t, name) => { + const [src, out] = await getMarkdownFiles(name); + t.not(src, out, 'Unformated file and formated file are the same'); + + const options = await getOptions(name); + + const formatted = markdownFormat(src, options); + t.is(formatted, out, 'Incorrect formating'); + // test that our formatting is idempotent + const formattedTwice = markdownFormat(formatted, options); + t.is(formatted, formattedTwice, 'Formatting is not idempotent'); +}; + +PrettierMarkdown.title = (title, name) => `${title}: + +- input: fixtures/${name}/input.md +- output: fixtures/${name}/output.md`;