summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xstd/prettier/main.ts15
-rw-r--r--std/prettier/main_test.ts12
-rw-r--r--std/prettier/testdata/config_file_yaml/.prettierrc.yaml2
-rw-r--r--std/prettier/testdata/config_file_yml/.prettierrc.yml2
4 files changed, 25 insertions, 6 deletions
diff --git a/std/prettier/main.ts b/std/prettier/main.ts
index cd8800d23..e3f2270c3 100755
--- a/std/prettier/main.ts
+++ b/std/prettier/main.ts
@@ -26,6 +26,7 @@
import { parse } from "../flags/mod.ts";
import * as path from "../path/mod.ts";
import * as toml from "../encoding/toml.ts";
+import * as yaml from "../encoding/yaml.ts";
import { ExpandGlobOptions, WalkInfo, expandGlob } from "../fs/mod.ts";
import { prettier, prettierPlugins } from "./prettier.ts";
const { args, cwd, exit, readAll, readFile, stdin, stdout, writeFile } = Deno;
@@ -393,7 +394,7 @@ async function autoResolveConfig(): Promise<PrettierBuildInOptions> {
async function resolveConfig(
filepath: string
): Promise<PrettierBuildInOptions> {
- let config: PrettierOptions = undefined;
+ let config: PrettierBuildInOptions = undefined;
function generateError(msg: string): Error {
return new Error(`Invalid prettier configuration file: ${msg}.`);
@@ -404,18 +405,22 @@ async function resolveConfig(
switch (path.extname(filepath)) {
case ".json":
try {
- config = JSON.parse(raw) as PrettierOptions;
+ config = JSON.parse(raw) as PrettierBuildInOptions;
} catch (err) {
throw generateError(err.message);
}
break;
case ".yml":
case ".yaml":
- // TODO: Unimplemented loading yaml / yml configuration file yet.
+ try {
+ config = yaml.parse(raw) as PrettierBuildInOptions;
+ } catch (err) {
+ throw generateError(err.message);
+ }
break;
case ".toml":
try {
- config = toml.parse(raw) as PrettierOptions;
+ config = toml.parse(raw) as PrettierBuildInOptions;
} catch (err) {
throw generateError(err.message);
}
@@ -434,7 +439,7 @@ async function resolveConfig(
);
if (output && output.default) {
- config = output.default;
+ config = output.default as PrettierBuildInOptions;
} else {
throw new Error(
"Prettier of JS version should have default exports."
diff --git a/std/prettier/main_test.ts b/std/prettier/main_test.ts
index a63890741..dd5197e4d 100644
--- a/std/prettier/main_test.ts
+++ b/std/prettier/main_test.ts
@@ -383,7 +383,9 @@ test(async function testPrettierWithAutoConfig(): Promise<void> {
"config_file_json",
"config_file_toml",
"config_file_js",
- "config_file_ts"
+ "config_file_ts",
+ "config_file_yaml",
+ "config_file_yml"
];
for (const configName of configs) {
@@ -441,6 +443,14 @@ test(async function testPrettierWithSpecifiedConfig(): Promise<void> {
{
dir: "config_file_ts",
name: ".prettierrc.ts"
+ },
+ {
+ dir: "config_file_yaml",
+ name: ".prettierrc.yaml"
+ },
+ {
+ dir: "config_file_yml",
+ name: ".prettierrc.yml"
}
];
diff --git a/std/prettier/testdata/config_file_yaml/.prettierrc.yaml b/std/prettier/testdata/config_file_yaml/.prettierrc.yaml
new file mode 100644
index 000000000..76e9f3104
--- /dev/null
+++ b/std/prettier/testdata/config_file_yaml/.prettierrc.yaml
@@ -0,0 +1,2 @@
+singleQuote: true
+trailingComma: "all"
diff --git a/std/prettier/testdata/config_file_yml/.prettierrc.yml b/std/prettier/testdata/config_file_yml/.prettierrc.yml
new file mode 100644
index 000000000..76e9f3104
--- /dev/null
+++ b/std/prettier/testdata/config_file_yml/.prettierrc.yml
@@ -0,0 +1,2 @@
+singleQuote: true
+trailingComma: "all"