-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* @import { Options } from "npm:prettier"; | ||
*/ | ||
|
||
/** | ||
* Prettier configuration. | ||
* @see [Prettier options](https://prettier.io/docs/en/options.html) | ||
* @type {Options} | ||
*/ | ||
export default { | ||
/** | ||
* Avoid parentheses around a sole arrow function parameter. | ||
*/ | ||
arrowParens: "avoid", | ||
|
||
/** | ||
* Put the `>` of a multi-line HTML like in a new line. | ||
*/ | ||
bracketSameLine: false, | ||
|
||
/** | ||
* Print spaces between brackets in object literals. | ||
*/ | ||
bracketSpacing: true, | ||
|
||
/** | ||
* Control whether Prettier formats quoted code embedded in the file. | ||
*/ | ||
embeddedLanguageFormatting: "auto", | ||
|
||
/** | ||
* Unix EOL. | ||
*/ | ||
endOfLine: "lf", | ||
|
||
/** | ||
* Use curious ternaries, with the question mark after the condition, | ||
* instead of on the same line as the consequent. | ||
*/ | ||
experimentalTernaries: true, | ||
|
||
/** | ||
* Strict whitespace in HTML. | ||
*/ | ||
htmlWhitespaceSensitivity: "strict", | ||
|
||
/** | ||
* JSX should use double quote. | ||
*/ | ||
jsxSingleQuote: false, | ||
|
||
/** | ||
* Print width is ideal at 80 characters. | ||
*/ | ||
printWidth: 80, | ||
|
||
/** | ||
* Wrap text to fit the print width. | ||
*/ | ||
proseWrap: "always", | ||
|
||
/** | ||
* Add quotes around properties of object if needed. | ||
*/ | ||
quoteProps: "as-needed", | ||
|
||
/** | ||
* Print semicolons at the ends of statements. | ||
*/ | ||
semi: true, | ||
|
||
/** | ||
* Shows multiple attributes per line in HTML, Vue and JSX. | ||
*/ | ||
singleAttributePerLine: false, | ||
|
||
/** | ||
* Use double quotes. | ||
*/ | ||
singleQuote: false, | ||
|
||
/** | ||
* Tab width at 4 is ideal. | ||
*/ | ||
tabWidth: 4, | ||
|
||
/** | ||
* Add trailing commas to make edition easier and diffing better. | ||
*/ | ||
trailingComma: "all", | ||
|
||
/** | ||
* Obviously use tabs. | ||
*/ | ||
useTabs: true, | ||
|
||
/** | ||
* Indent code in Vue files. | ||
*/ | ||
vueIndentScriptAndStyle: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { format } from "prettier"; | ||
import prettierConfig from "../prettier.config.mjs"; | ||
|
||
const extensions = [".js", ".json", ".md", ".ts"]; | ||
const decoder = new TextDecoder("utf-8"); | ||
const encoder = new TextEncoder(); | ||
|
||
const getFiles = async function* ( | ||
directory = ".", | ||
): AsyncGenerator<[path: string, content: string]> { | ||
for await (const entry of Deno.readDir(directory)) { | ||
if (!entry.name.startsWith(".")) { | ||
const path = `${directory}/${entry.name}`; | ||
|
||
entry.isDirectory ? yield* getFiles(path) | ||
: extensions.some(extension => entry.name.endsWith(extension)) ? | ||
yield await Deno.readFile(path).then(content => [ | ||
path, | ||
decoder.decode(content), | ||
]) | ||
: undefined; | ||
} | ||
} | ||
}; | ||
|
||
Array.fromAsync(getFiles()).then(files => | ||
files.forEach(([filepath, code]) => | ||
format(code, { filepath, ...prettierConfig }).then(formattedCode => | ||
Deno.writeFile(filepath, encoder.encode(formattedCode)), | ||
), | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters