Is there a way to run the formatter programatically? #10729
Unanswered
halvardssm
asked this question in
Q&A
Replies: 2 comments
-
|
Not currently. I thought we had an issue for it, but I couldn't find it, so I opened #10731. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I'm using this. import { iter } from "https://deno.land/std@0.97.0/io/util.ts";
const denoFmt = async (code: string) => {
const process = Deno.run({
cmd: ["deno", "fmt", "-"],
stdin: "piped",
stdout: "piped",
});
const input = new TextEncoder().encode(code);
await process.stdin.write(input);
process.stdin.close();
const formatteds = [];
const accumulates = [0];
let sum = 0;
for await (const chunk of iter(process.stdout)) {
formatteds.push(new Uint8Array(chunk));
sum += chunk.length;
accumulates.push(sum);
}
const concatenated = new Uint8Array(sum);
for (let i = 0; i < formatteds.length; i++) {
concatenated.set(formatteds[i], accumulates[i]);
}
const decoded = new TextDecoder().decode(concatenated);
return decoded;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I was wondering if there is a way to run an equivalent to
deno fmtanddeno fmt --checkfor a string in my deno code?I have this code:
is there a way to format the string, or check formatting? E.g. like such:
Beta Was this translation helpful? Give feedback.
All reactions