Skip to content

Commit

Permalink
Ignore formatting if no file path was given
Browse files Browse the repository at this point in the history
Refs #3
  • Loading branch information
remcohaszing committed Feb 12, 2024
1 parent c8c181f commit b40fa38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ test('ignore missing prettier parser', () => {
assert.equal(result, '__example__\n\n')
})

test('ignore missing file', () => {
const result = unified()
.use(valueStringify)
.use(unifiedPrettier)
.stringify({ type: 'root', value: '__example__\n\n' })

assert.equal(result, '__example__\n\n')
})

test('accept prettier options', () => {
const result = unified()
.use(valueStringify)
Expand Down
4 changes: 4 additions & 0 deletions src/unified-prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const unifiedPrettier: Plugin<[Options?]> = function unifiedPrettier(options) {
this.compiler = (tree, file) => {
const content = compiler(tree, file)

if (!file.path) {
return content
}

const filepath = resolve(file.cwd, file.path)

const signal = new Int32Array(new SharedArrayBuffer(4))
Expand Down

0 comments on commit b40fa38

Please sign in to comment.