Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a23e74b6
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a23e74b6
编写于
1月 29, 2019
作者:
S
Sam Harwell
提交者:
GitHub
1月 29, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #32910 from sharwell/format-dry-run
dotnet-format --dry-run
上级
3c1b3a4f
fcca99e2
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
107 addition
and
10 deletion
+107
-10
src/Tools/dotnet-format/CodeFormatter.cs
src/Tools/dotnet-format/CodeFormatter.cs
+5
-5
src/Tools/dotnet-format/Program.cs
src/Tools/dotnet-format/Program.cs
+11
-5
src/Tools/dotnet-format/Properties/launchSettings.json
src/Tools/dotnet-format/Properties/launchSettings.json
+14
-0
src/Tools/dotnet-format/Resources.Designer.cs
src/Tools/dotnet-format/Resources.Designer.cs
+9
-0
src/Tools/dotnet-format/Resources.resx
src/Tools/dotnet-format/Resources.resx
+3
-0
src/Tools/dotnet-format/xlf/Resources.cs.xlf
src/Tools/dotnet-format/xlf/Resources.cs.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.de.xlf
src/Tools/dotnet-format/xlf/Resources.de.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.es.xlf
src/Tools/dotnet-format/xlf/Resources.es.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.fr.xlf
src/Tools/dotnet-format/xlf/Resources.fr.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.it.xlf
src/Tools/dotnet-format/xlf/Resources.it.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.ja.xlf
src/Tools/dotnet-format/xlf/Resources.ja.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.ko.xlf
src/Tools/dotnet-format/xlf/Resources.ko.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.pl.xlf
src/Tools/dotnet-format/xlf/Resources.pl.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.pt-BR.xlf
src/Tools/dotnet-format/xlf/Resources.pt-BR.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.ru.xlf
src/Tools/dotnet-format/xlf/Resources.ru.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.tr.xlf
src/Tools/dotnet-format/xlf/Resources.tr.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.zh-Hans.xlf
src/Tools/dotnet-format/xlf/Resources.zh-Hans.xlf
+5
-0
src/Tools/dotnet-format/xlf/Resources.zh-Hant.xlf
src/Tools/dotnet-format/xlf/Resources.zh-Hant.xlf
+5
-0
未找到文件。
src/Tools/dotnet-format/CodeFormatter.cs
浏览文件 @
a23e74b6
...
...
@@ -21,9 +21,9 @@ namespace Microsoft.CodeAnalysis.Tools.CodeFormatter
{
internal
static
class
CodeFormatter
{
const
int
MaxLoggedWorkspaceWarnings
=
5
;
private
const
int
MaxLoggedWorkspaceWarnings
=
5
;
public
static
async
Task
<
int
>
FormatWorkspaceAsync
(
ILogger
logger
,
string
solutionOrProjectPath
,
bool
isSolution
,
bool
logAllWorkspaceWarnings
,
CancellationToken
cancellationToken
)
public
static
async
Task
<
int
>
FormatWorkspaceAsync
(
ILogger
logger
,
string
solutionOrProjectPath
,
bool
isSolution
,
bool
logAllWorkspaceWarnings
,
bool
saveFormattedFiles
,
CancellationToken
cancellationToken
)
{
logger
.
LogInformation
(
string
.
Format
(
Resources
.
Formatting_code_files_in_workspace_0
,
solutionOrProjectPath
));
...
...
@@ -61,7 +61,7 @@ public static async Task<int> FormatWorkspaceAsync(ILogger logger, string soluti
logger
.
LogTrace
(
Resources
.
Workspace_loaded_in_0_ms
,
workspaceStopwatch
.
ElapsedMilliseconds
);
workspaceStopwatch
.
Restart
();
exitCode
=
await
FormatFilesInWorkspaceAsync
(
logger
,
workspace
,
projectPath
,
codingConventionsManager
,
cancellationToken
).
ConfigureAwait
(
false
);
exitCode
=
await
FormatFilesInWorkspaceAsync
(
logger
,
workspace
,
projectPath
,
codingConventionsManager
,
saveFormattedFiles
,
cancellationToken
).
ConfigureAwait
(
false
);
logger
.
LogDebug
(
Resources
.
Format_complete_in_0_ms
,
workspaceStopwatch
.
ElapsedMilliseconds
);
}
...
...
@@ -92,7 +92,7 @@ void LogWorkspaceWarnings(object sender, WorkspaceDiagnosticEventArgs args)
}
}
private
static
async
Task
<
int
>
FormatFilesInWorkspaceAsync
(
ILogger
logger
,
Workspace
workspace
,
string
projectPath
,
ICodingConventionsManager
codingConventionsManager
,
CancellationToken
cancellationToken
)
private
static
async
Task
<
int
>
FormatFilesInWorkspaceAsync
(
ILogger
logger
,
Workspace
workspace
,
string
projectPath
,
ICodingConventionsManager
codingConventionsManager
,
bool
saveFormattedFiles
,
CancellationToken
cancellationToken
)
{
var
projectIds
=
workspace
.
CurrentSolution
.
ProjectIds
.
ToImmutableArray
();
var
optionsApplier
=
new
EditorConfigOptionsApplier
();
...
...
@@ -115,7 +115,7 @@ private static async Task<int> FormatFilesInWorkspaceAsync(ILogger logger, Works
logger
.
LogInformation
(
Resources
.
Formatting_code_files_in_project_0
,
project
.
Name
);
var
formattedSolution
=
await
FormatFilesInProjectAsync
(
logger
,
project
,
codingConventionsManager
,
optionsApplier
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(!
workspace
.
TryApplyChanges
(
formattedSolution
))
if
(
saveFormattedFiles
&&
!
workspace
.
TryApplyChanges
(
formattedSolution
))
{
logger
.
LogError
(
Resources
.
Failed_to_save_formatting_changes
);
return
1
;
...
...
src/Tools/dotnet-format/Program.cs
浏览文件 @
a23e74b6
...
...
@@ -14,11 +14,11 @@
namespace
Microsoft.CodeAnalysis.Tools.CodeFormatter
{
class
Program
internal
class
Program
{
static
readonly
string
[]
_verbosityLevels
=
new
[]
{
"q"
,
"quiet"
,
"m"
,
"minimal"
,
"n"
,
"normal"
,
"d"
,
"detailed"
,
"diag"
,
"diagnostic"
};
private
static
readonly
string
[]
_verbosityLevels
=
new
[]
{
"q"
,
"quiet"
,
"m"
,
"minimal"
,
"n"
,
"normal"
,
"d"
,
"detailed"
,
"diag"
,
"diagnostic"
};
static
async
Task
<
int
>
Main
(
string
[]
args
)
private
static
async
Task
<
int
>
Main
(
string
[]
args
)
{
var
parser
=
new
CommandLineBuilder
(
new
Command
(
"dotnet-format"
,
handler
:
CommandHandler
.
Create
(
typeof
(
Program
).
GetMethod
(
nameof
(
Run
)))))
.
UseParseDirective
()
...
...
@@ -30,13 +30,14 @@ static async Task<int> Main(string[] args)
.
UseExceptionHandler
()
.
AddOption
(
new
Option
(
new
[]
{
"-w"
,
"--workspace"
},
Resources
.
The_solution_or_project_file_to_operate_on_If_a_file_is_not_specified_the_command_will_search_the_current_directory_for_one
,
new
Argument
<
string
>(()
=>
null
)))
.
AddOption
(
new
Option
(
new
[]
{
"-v"
,
"--verbosity"
},
Resources
.
Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic
,
new
Argument
<
string
>()
{
Arity
=
ArgumentArity
.
ExactlyOne
}.
FromAmong
(
_verbosityLevels
)))
.
AddOption
(
new
Option
(
new
[]
{
"--dry-run"
},
Resources
.
Format_files_but_do_not_save_changes_to_disk
,
new
Argument
<
bool
>()))
.
UseVersionOption
()
.
Build
();
return
await
parser
.
InvokeAsync
(
args
).
ConfigureAwait
(
false
);
}
public
static
async
Task
<
int
>
Run
(
string
workspace
,
string
verbosity
,
IConsole
console
=
null
)
public
static
async
Task
<
int
>
Run
(
string
workspace
,
string
verbosity
,
bool
dryRun
,
IConsole
console
=
null
)
{
var
serviceCollection
=
new
ServiceCollection
();
var
logLevel
=
GetLogLevel
(
verbosity
);
...
...
@@ -65,7 +66,12 @@ public static async Task<int> Run(string workspace, string verbosity, IConsole c
MSBuildCoreLoader
.
LoadDotnetInstance
(
workspaceDirectory
);
return
await
CodeFormatter
.
FormatWorkspaceAsync
(
logger
,
workspacePath
,
isSolution
,
logAllWorkspaceWarnings
:
logLevel
==
LogLevel
.
Trace
,
cancellationTokenSource
.
Token
).
ConfigureAwait
(
false
);
logger
,
workspacePath
,
isSolution
,
logAllWorkspaceWarnings
:
logLevel
==
LogLevel
.
Trace
,
saveFormattedFiles
:
!
dryRun
,
cancellationTokenSource
.
Token
).
ConfigureAwait
(
false
);
}
catch
(
FileNotFoundException
fex
)
{
...
...
src/Tools/dotnet-format/Properties/launchSettings.json
0 → 100644
浏览文件 @
a23e74b6
{
"profiles"
:
{
"dotnet-format (--dry-run)"
:
{
"commandName"
:
"Project"
,
"commandLineArgs"
:
"-w Roslyn.sln --dry-run"
,
"workingDirectory"
:
"$(SolutionDir)"
},
"dotnet-format"
:
{
"commandName"
:
"Project"
,
"commandLineArgs"
:
"-w Roslyn.sln"
,
"workingDirectory"
:
"$(SolutionDir)"
}
}
}
src/Tools/dotnet-format/Resources.Designer.cs
浏览文件 @
a23e74b6
...
...
@@ -117,6 +117,15 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Format files, but do not save changes to disk..
/// </summary>
internal
static
string
Format_files_but_do_not_save_changes_to_disk
{
get
{
return
ResourceManager
.
GetString
(
"Format_files_but_do_not_save_changes_to_disk"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Formatting code file '{0}'..
/// </summary>
...
...
src/Tools/dotnet-format/Resources.resx
浏览文件 @
a23e74b6
...
...
@@ -180,4 +180,7 @@
<data
name=
"Maximum_number_of_workspace_warnings_to_log_has_been_reached_Set_the_verbosity_option_to_the_diagnostic_level_to_see_all_warnings"
xml:space=
"preserve"
>
<value>
Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings.
</value>
</data>
<data
name=
"Format_files_but_do_not_save_changes_to_disk"
xml:space=
"preserve"
>
<value>
Format files, but do not save changes to disk.
</value>
</data>
</root>
\ No newline at end of file
src/Tools/dotnet-format/xlf/Resources.cs.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.de.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.es.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.fr.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.it.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.ja.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.ko.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.pl.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.pt-BR.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.ru.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.tr.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.zh-Hans.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
src/Tools/dotnet-format/xlf/Resources.zh-Hant.xlf
浏览文件 @
a23e74b6
...
...
@@ -32,6 +32,11 @@
<target
state=
"new"
>
Format complete in {0}ms.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Format_files_but_do_not_save_changes_to_disk"
>
<source>
Format files, but do not save changes to disk.
</source>
<target
state=
"new"
>
Format files, but do not save changes to disk.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Formatting_code_file_0"
>
<source>
Formatting code file '{0}'.
</source>
<target
state=
"new"
>
Formatting code file '{0}'.
</target>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录