diff options
author | Axetroy <axetroy.dev@gmail.com> | 2019-11-27 00:07:40 +0800 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-11-26 08:07:39 -0800 |
commit | 2a348144c6932f749dfa28b6b8590d6df1c083f2 (patch) | |
tree | 778e1e289aa61056f188d346c92bf189d3b5bf50 /std/prettier/main.ts | |
parent | c016684653df45c3c3bc88d79dfc295ea5c6426f (diff) |
feat: add ignore parser for std/prettier (#3399)
Diffstat (limited to 'std/prettier/main.ts')
-rwxr-xr-x | std/prettier/main.ts | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/std/prettier/main.ts b/std/prettier/main.ts index e3f2270c3..b3c469659 100755 --- a/std/prettier/main.ts +++ b/std/prettier/main.ts @@ -27,6 +27,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 * as ignore from "./ignore.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; @@ -460,7 +461,7 @@ async function resolveConfig( /** * auto detect .prettierignore and return pattern if file exist. */ -async function autoResolveIgnoreFile(): Promise<string[]> { +async function autoResolveIgnoreFile(): Promise<Set<string>> { const files = await Deno.readDir("."); for (const f of files) { @@ -469,20 +470,16 @@ async function autoResolveIgnoreFile(): Promise<string[]> { } } - return []; + return new Set([]); } /** * parse prettier ignore file. * @param filepath the ignore file path. */ -async function resolveIgnoreFile(filepath: string): Promise<string[]> { +async function resolveIgnoreFile(filepath: string): Promise<Set<string>> { const raw = new TextDecoder().decode(await Deno.readFile(filepath)); - - return raw - .split("\n") - .filter((v: string) => !!v.trim() && v.trim().indexOf("#") !== 0) - .map(v => v); + return ignore.parse(raw); } async function main(opts): Promise<void> { @@ -532,12 +529,12 @@ async function main(opts): Promise<void> { const ignoreFilepath = opts["ignore-path"]; if (ignoreFilepath && ignoreFilepath !== "disable") { - const ignorePatterns: string[] = + const ignorePatterns = ignoreFilepath === "auto" ? await autoResolveIgnoreFile() : await resolveIgnoreFile(ignoreFilepath); - ignore = ignore.concat(ignorePatterns); + ignore = ignore.concat(Array.from(ignorePatterns)); } const files = getTargetFiles(args.length ? args : ["."], ignore); |