Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
80b13715
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
80b13715
编写于
11月 14, 2019
作者:
罗
罗文
提交者:
Ry Dahl
11月 13, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fmt: allow configuration of Prettier options (#3314)
上级
8d033972
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
210 addition
and
5 deletion
+210
-5
cli/flags.rs
cli/flags.rs
+186
-2
std/prettier/main.ts
std/prettier/main.ts
+24
-3
未找到文件。
cli/flags.rs
浏览文件 @
80b13715
...
...
@@ -339,12 +339,111 @@ This command has implicit access to all permissions (equivalent to deno run --al
Automatically downloads Prettier dependencies on first run.
deno fmt myfile1.ts myfile2.ts"
,
)
.arg
(
)
.arg
(
Arg
::
with_name
(
"stdout"
)
.long
(
"stdout"
)
.help
(
"Output formated code to stdout"
)
.takes_value
(
false
),
)
.arg
(
)
.arg
(
Arg
::
with_name
(
"print-width"
)
.long
(
"print-width"
)
.value_name
(
"int"
)
.help
(
"Specify the line length that the printer will wrap on."
)
.takes_value
(
true
)
.require_equals
(
true
)
)
.arg
(
Arg
::
with_name
(
"tab-width"
)
.long
(
"tab-width"
)
.value_name
(
"int"
)
.help
(
"Specify the number of spaces per indentation-level."
)
.takes_value
(
true
)
.require_equals
(
true
)
)
.arg
(
Arg
::
with_name
(
"use-tabs"
)
.long
(
"use-tabs"
)
.help
(
"Indent lines with tabs instead of spaces."
)
.takes_value
(
false
)
)
.arg
(
Arg
::
with_name
(
"no-semi"
)
.long
(
"no-semi"
)
.help
(
"Print semicolons at the ends of statements."
)
.takes_value
(
false
)
)
.arg
(
Arg
::
with_name
(
"single-quote"
)
.long
(
"single-quote"
)
.help
(
"Use single quotes instead of double quotes."
)
.takes_value
(
false
)
)
.arg
(
Arg
::
with_name
(
"quote-props"
)
.long
(
"quote-props"
)
.value_name
(
"as-needed|consistent|preserve"
)
.help
(
"Change when properties in objects are quoted."
)
.takes_value
(
true
)
.possible_values
(
&
[
"as-needed"
,
"consistent"
,
"preserve"
])
.require_equals
(
true
)
)
.arg
(
Arg
::
with_name
(
"jsx-single-quote"
)
.long
(
"jsx-single-quote"
)
.help
(
"Use single quotes instead of double quotes in JSX."
)
.takes_value
(
false
)
)
.arg
(
Arg
::
with_name
(
"jsx-bracket-same-line"
)
.long
(
"jsx-bracket-same-line"
)
.help
(
"Put the > of a multi-line JSX element at the end of the last line
instead of being alone on the next line (does not apply to self closing elements)."
)
.takes_value
(
false
)
)
.arg
(
Arg
::
with_name
(
"trailing-comma"
)
.long
(
"trailing-comma"
)
.help
(
"Print trailing commas wherever possible when multi-line."
)
.takes_value
(
false
)
)
.arg
(
Arg
::
with_name
(
"no-bracket-spacing"
)
.long
(
"no-bracket-spacing"
)
.help
(
"Print spaces between brackets in object literals."
)
.takes_value
(
false
)
)
.arg
(
Arg
::
with_name
(
"arrow-parens"
)
.long
(
"arrow-parens"
)
.value_name
(
"avoid|always"
)
.help
(
"Include parentheses around a sole arrow function parameter."
)
.takes_value
(
true
)
.possible_values
(
&
[
"avoid"
,
"always"
])
.require_equals
(
true
)
)
.arg
(
Arg
::
with_name
(
"prose-wrap"
)
.long
(
"prose-wrap"
)
.value_name
(
"always|never|preserve"
)
.help
(
"How to wrap prose."
)
.takes_value
(
true
)
.possible_values
(
&
[
"always"
,
"never"
,
"preserve"
])
.require_equals
(
true
)
)
.arg
(
Arg
::
with_name
(
"end-of-line"
)
.long
(
"end-of-line"
)
.value_name
(
"auto|lf|crlf|cr"
)
.help
(
"Which end of line characters to apply."
)
.takes_value
(
true
)
.possible_values
(
&
[
"auto"
,
"lf"
,
"crlf"
,
"cr"
])
.require_equals
(
true
)
)
.arg
(
Arg
::
with_name
(
"files"
)
.takes_value
(
true
)
.multiple
(
true
)
...
...
@@ -866,6 +965,36 @@ pub fn flags_from_vec(
argv
.push
(
"--write"
.to_string
());
}
let
prettier_flags
=
[
[
"1"
,
"print-width"
],
[
"1"
,
"tab-width"
],
[
"0"
,
"use-tabs"
],
[
"0"
,
"no-semi"
],
[
"0"
,
"single-quote"
],
[
"1"
,
"quote-props"
],
[
"0"
,
"jsx-single-quote"
],
[
"0"
,
"jsx-bracket-same-line"
],
[
"0"
,
"trailing-comma"
],
[
"0"
,
"no-bracket-spacing"
],
[
"1"
,
"arrow-parens"
],
[
"1"
,
"prose-wrap"
],
[
"1"
,
"end-of-line"
],
];
for
opt
in
&
prettier_flags
{
let
t
=
opt
[
0
];
let
keyword
=
opt
[
1
];
if
fmt_match
.is_present
(
&
keyword
)
{
if
t
==
"0"
{
argv
.push
(
format!
(
"--{}"
,
keyword
));
}
else
{
argv
.push
(
format!
(
"--{}"
,
keyword
));
argv
.push
(
fmt_match
.value_of
(
keyword
)
.unwrap
()
.to_string
());
}
}
}
DenoSubcommand
::
Run
}
(
"info"
,
Some
(
info_match
))
=>
{
...
...
@@ -1908,4 +2037,59 @@ mod tests {
assert_eq!
(
subcommand
,
DenoSubcommand
::
Run
);
assert_eq!
(
argv
,
svec!
[
"deno"
,
"script.ts"
])
}
#[test]
fn
test_flags_from_vec_39
()
{
let
(
flags
,
subcommand
,
argv
)
=
flags_from_vec
(
svec!
[
"deno"
,
"fmt"
,
"--print-width=100"
,
"--tab-width=4"
,
"--use-tabs"
,
"--no-semi"
,
"--single-quote"
,
"--arrow-parens=always"
,
"--prose-wrap=preserve"
,
"--end-of-line=crlf"
,
"--quote-props=preserve"
,
"--jsx-single-quote"
,
"--jsx-bracket-same-line"
,
"script.ts"
]);
assert_eq!
(
flags
,
DenoFlags
{
allow_write
:
true
,
allow_read
:
true
,
..
DenoFlags
::
default
()
}
);
assert_eq!
(
subcommand
,
DenoSubcommand
::
Run
);
assert_eq!
(
argv
,
svec!
[
"deno"
,
PRETTIER_URL
,
"script.ts"
,
"--write"
,
"--print-width"
,
"100"
,
"--tab-width"
,
"4"
,
"--use-tabs"
,
"--no-semi"
,
"--single-quote"
,
"--quote-props"
,
"preserve"
,
"--jsx-single-quote"
,
"--jsx-bracket-same-line"
,
"--arrow-parens"
,
"always"
,
"--prose-wrap"
,
"preserve"
,
"--end-of-line"
,
"crlf"
]
);
}
}
std/prettier/main.ts
浏览文件 @
80b13715
...
...
@@ -61,6 +61,15 @@ JS/TS Styling Options:
beginning of lines which may need them.
--single-quote Use single quotes instead of double
quotes. Defaults to false.
--quote-props <as-needed|consistent|preserve>
Change when properties in objects are
quoted. Defaults to as-needed.
--jsx-single-quote Use single quotes instead of double
quotes in JSX.
--jsx-bracket-same-line Put the > of a multi-line JSX element at
the end of the last line instead of
being alone on the next line (does not
apply to self closing elements).
--trailing-comma <none|es5|all> Print trailing commas wherever possible
when multi-line. Defaults to none.
--no-bracket-spacing Do not print spaces between brackets.
...
...
@@ -103,6 +112,9 @@ interface PrettierOptions {
useTabs
:
boolean
;
semi
:
boolean
;
singleQuote
:
boolean
;
quoteProps
:
string
;
jsxSingleQuote
:
boolean
;
jsxBracketSameLine
:
boolean
;
trailingComma
:
string
;
bracketSpacing
:
boolean
;
arrowParens
:
string
;
...
...
@@ -340,6 +352,9 @@ async function main(opts): Promise<void> {
useTabs
:
Boolean
(
opts
[
"
use-tabs
"
]),
semi
:
Boolean
(
opts
[
"
semi
"
]),
singleQuote
:
Boolean
(
opts
[
"
single-quote
"
]),
quoteProps
:
opts
[
"
quote-props
"
],
jsxSingleQuote
:
Boolean
(
opts
[
"
jsx-single-quote
"
]),
jsxBracketSameLine
:
Boolean
(
opts
[
"
jsx-bracket-same-line
"
]),
trailingComma
:
opts
[
"
trailing-comma
"
],
bracketSpacing
:
Boolean
(
opts
[
"
bracket-spacing
"
]),
arrowParens
:
opts
[
"
arrow-parens
"
],
...
...
@@ -387,7 +402,8 @@ main(
"
arrow-parens
"
,
"
prose-wrap
"
,
"
end-of-line
"
,
"
stdin-parser
"
"
stdin-parser
"
,
"
quote-props
"
],
boolean
:
[
"
check
"
,
...
...
@@ -397,7 +413,9 @@ main(
"
single-quote
"
,
"
bracket-spacing
"
,
"
write
"
,
"
stdin
"
"
stdin
"
,
"
jsx-single-quote
"
,
"
jsx-bracket-same-line
"
],
default
:
{
ignore
:
[],
...
...
@@ -413,7 +431,10 @@ main(
"
end-of-line
"
:
"
auto
"
,
write
:
false
,
stdin
:
false
,
"
stdin-parser
"
:
"
typescript
"
"
stdin-parser
"
:
"
typescript
"
,
"
quote-props
"
:
"
as-needed
"
,
"
jsx-single-quote
"
:
false
,
"
jsx-bracket-same-line
"
:
false
},
alias
:
{
H
:
"
help
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录