Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b0b8066e
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,发现更多精彩内容 >>
提交
b0b8066e
编写于
1月 11, 2017
作者:
J
Jonathon Marolf
提交者:
GitHub
1月 11, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Properly handle lack of editorconfig file for naming styles (#16413)
We now return false if we get an empty set of naming styles.
上级
fe1c69b0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
8 deletion
+50
-8
src/Workspaces/Core/Portable/Options/EditorConfigStorageLocation.cs
...aces/Core/Portable/Options/EditorConfigStorageLocation.cs
+18
-8
src/Workspaces/CoreTest/EditorConfigStorageLocation/EditorConfigStorageLocationTests.cs
...ConfigStorageLocation/EditorConfigStorageLocationTests.cs
+31
-0
src/Workspaces/CoreTest/ServicesTest.csproj
src/Workspaces/CoreTest/ServicesTest.csproj
+1
-0
未找到文件。
src/Workspaces/Core/Portable/Options/EditorConfigStorageLocation.cs
浏览文件 @
b0b8066e
...
...
@@ -2,6 +2,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
;
using
static
Microsoft
.
CodeAnalysis
.
CodeStyle
.
CodeStyleHelpers
;
...
...
@@ -17,7 +18,7 @@ internal sealed class EditorConfigStorageLocation : OptionStorageLocation
private
Func
<
string
,
Type
,
object
>
_parseValue
;
private
Func
<
IReadOnlyDictionary
<
string
,
object
>,
Type
,
object
>
_p
arseDictionary
;
private
Func
<
IReadOnlyDictionary
<
string
,
object
>,
Type
,
(
object
result
,
bool
succeeded
)>
_tryP
arseDictionary
;
public
bool
TryParseReadonlyDictionary
(
IReadOnlyDictionary
<
string
,
object
>
allRawConventions
,
Type
type
,
out
object
result
)
{
...
...
@@ -29,10 +30,11 @@ public bool TryParseReadonlyDictionary(IReadOnlyDictionary<string, object> allRa
return
true
;
}
}
else
if
(
_
p
arseDictionary
!=
null
)
else
if
(
_
tryP
arseDictionary
!=
null
)
{
result
=
_parseDictionary
(
allRawConventions
,
type
);
return
true
;
var
tuple
=
_tryParseDictionary
(
allRawConventions
,
type
);
result
=
tuple
.
result
;
return
tuple
.
succeeded
;
}
result
=
null
;
...
...
@@ -75,11 +77,19 @@ public EditorConfigStorageLocation(string keyName, Func<string, object> parseVal
public
EditorConfigStorageLocation
()
{
// If the user didn't pass a keyName assume we need to parse the entire dictionary
_
p
arseDictionary
=
(
dictionary
,
type
)
=>
_
tryP
arseDictionary
=
(
dictionary
,
type
)
=>
{
if
(
type
==
typeof
(
NamingStylePreferences
))
{
return
EditorConfigNamingStyleParser
.
GetNamingStylesFromDictionary
(
dictionary
);
var
result
=
EditorConfigNamingStyleParser
.
GetNamingStylesFromDictionary
(
dictionary
);
if
(!
result
.
NamingRules
.
Any
()
&&
!
result
.
NamingStyles
.
Any
()
&&
!
result
.
SymbolSpecifications
.
Any
())
{
return
(
result
:
result
,
succeeded
:
false
);
}
return
(
result
:
result
,
succeeded
:
true
);
}
else
{
...
...
@@ -88,10 +98,10 @@ public EditorConfigStorageLocation()
};
}
public
EditorConfigStorageLocation
(
Func
<
IReadOnlyDictionary
<
string
,
object
>,
object
>
p
arseDictionary
)
public
EditorConfigStorageLocation
(
Func
<
IReadOnlyDictionary
<
string
,
object
>,
(
object
result
,
bool
succeeded
)>
tryP
arseDictionary
)
{
// If we're explicitly given a parsing function we can throw away the type when parsing
_
parseDictionary
=
(
dictionary
,
type
)
=>
p
arseDictionary
(
dictionary
);
_
tryParseDictionary
=
(
dictionary
,
type
)
=>
tryP
arseDictionary
(
dictionary
);
}
}
}
src/Workspaces/CoreTest/EditorConfigStorageLocation/EditorConfigStorageLocationTests.cs
0 → 100644
浏览文件 @
b0b8066e
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.Collections.Generic
;
using
Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
;
using
Microsoft.CodeAnalysis.Options
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.UnitTests.EditorConfig.StorageLocation
{
public
class
EditorConfigStorageLocationTests
{
[
Fact
]
public
static
void
TestEmptyDictionaryReturnFalse
()
{
var
editorConfigStorageLocation
=
new
EditorConfigStorageLocation
();
var
result
=
editorConfigStorageLocation
.
TryParseReadonlyDictionary
(
new
Dictionary
<
string
,
object
>(),
typeof
(
NamingStylePreferences
),
out
var
@object
);
Assert
.
False
(
result
,
"Expected TryParseReadonlyDictionary to return 'false' for empty dictionary"
);
}
[
Fact
]
public
static
void
TestObjectTypeThrowsNotSupportedException
()
{
var
editorConfigStorageLocation
=
new
EditorConfigStorageLocation
();
Assert
.
Throws
<
NotSupportedException
>(()
=>
{
editorConfigStorageLocation
.
TryParseReadonlyDictionary
(
new
Dictionary
<
string
,
object
>(),
typeof
(
object
),
out
var
@object
);
});
}
}
}
src/Workspaces/CoreTest/ServicesTest.csproj
浏览文件 @
b0b8066e
...
...
@@ -72,6 +72,7 @@
<ItemGroup>
<Compile
Include=
"CodeStyle\EditorConfigCodeStyleParserTests.cs"
/>
<Compile
Include=
"DependentTypeFinderTests.cs"
/>
<Compile
Include=
"EditorConfigStorageLocation\EditorConfigStorageLocationTests.cs"
/>
<Compile
Include=
"Editting\SyntaxEditorTests.cs"
/>
<Compile
Include=
"Execution\Extensions.cs"
/>
<Compile
Include=
"Execution\SnapshotSerializationTestBase.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录