StyleCop
2015-11-05 16:49
141 查看
1. Install StyleCop-4.7.49.0.msi
https://stylecop.codeplex.com/
2. Run StyleCop/Run StyleCop (Rescan All)
3. Warnings
CSharp.Ordering: All using directives must be placed inside of the namespace. > Can be turned off in the StyleCop Settings
4. How do I integrate StyleCop 4.7 with Visual Studio MSBuild?
The above command will download the latest stable required dlls and files and integrate style cop with your project. Build your project and any stylecop errors will be shown in the warnings section.
If you want your build to succeed only if all stylecop errors are fixed, you will need to make some changes to the project file to set a boolean to not treat stylecop errors as warnings.
Open the .csproj file for your project in notepad, and find the first PropertyGroup section within the file. Add a new tag to set the StyleCopTreatErrorsAsWarnings flag to false.
For example:
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings> is shown above.
Issues:
1. C# - StyleCop - SA1121: UseBuiltInTypeAlias - Readability Rules
The code uses one of the basic C# types, but does not use the built-in alias for the type.
Rather than using the type name or the fully-qualified type name, the built-in aliases for these types should always be used: bool, byte, char, decimal, double, short, int, long, object, sbyte, float, string, ushort, uint, ulong.
so String.Empty is wrong (depend on above rules) and string.Empty is good.
I do not agree :)
<Rule Name="UseBuiltInTypeAlias">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
2. How to exclude private members from StyleCop rule SA1600
I am not very interesting with write documents for private members :)
<AnalyzerSettings>
<BooleanProperty Name="IncludeFields">False</BooleanProperty>
</AnalyzerSettings>
3. A field name in C# must not begins with an underscore.
I do not agree :)
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
4. By default, StyleCop does not allow variable or field names to include Hungarian notation
How can I allow nh (NHibernate)
<Analyzers>
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules">
<AnalyzerSettings>
<CollectionProperty Name="Hungarian">
<Value>nh</Value>
</CollectionProperty>
</AnalyzerSettings>
</Analyzer>
</Analyzers>
5. The comment must start with a single space. To ignore this error when commenting out a line of code, begin the comment with '////' rather than '//'
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.SpacingRules">
<Rules>
<Rule Name="SingleLineCommentsMustBeginWithSingleSpace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
</Analyzer>
6. The comment is empty. Add text to the comment or remove it.
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="CommentsMustContainText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
7. More rules you can found in the below url:
http://www.stylecop.com/docs/StyleCop%20Rules.html
https://stylecop.codeplex.com/
2. Run StyleCop/Run StyleCop (Rescan All)
3. Warnings
CSharp.Ordering: All using directives must be placed inside of the namespace. > Can be turned off in the StyleCop Settings
4. How do I integrate StyleCop 4.7 with Visual Studio MSBuild?
The above command will download the latest stable required dlls and files and integrate style cop with your project. Build your project and any stylecop errors will be shown in the warnings section.
If you want your build to succeed only if all stylecop errors are fixed, you will need to make some changes to the project file to set a boolean to not treat stylecop errors as warnings.
Open the .csproj file for your project in notepad, and find the first PropertyGroup section within the file. Add a new tag to set the StyleCopTreatErrorsAsWarnings flag to false.
For example:
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings> is shown above.
Issues:
1. C# - StyleCop - SA1121: UseBuiltInTypeAlias - Readability Rules
The code uses one of the basic C# types, but does not use the built-in alias for the type.
Rather than using the type name or the fully-qualified type name, the built-in aliases for these types should always be used: bool, byte, char, decimal, double, short, int, long, object, sbyte, float, string, ushort, uint, ulong.
so String.Empty is wrong (depend on above rules) and string.Empty is good.
I do not agree :)
<Rule Name="UseBuiltInTypeAlias">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
2. How to exclude private members from StyleCop rule SA1600
I am not very interesting with write documents for private members :)
<AnalyzerSettings>
<BooleanProperty Name="IncludeFields">False</BooleanProperty>
</AnalyzerSettings>
3. A field name in C# must not begins with an underscore.
I do not agree :)
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
4. By default, StyleCop does not allow variable or field names to include Hungarian notation
How can I allow nh (NHibernate)
<Analyzers>
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules">
<AnalyzerSettings>
<CollectionProperty Name="Hungarian">
<Value>nh</Value>
</CollectionProperty>
</AnalyzerSettings>
</Analyzer>
</Analyzers>
5. The comment must start with a single space. To ignore this error when commenting out a line of code, begin the comment with '////' rather than '//'
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.SpacingRules">
<Rules>
<Rule Name="SingleLineCommentsMustBeginWithSingleSpace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
</Analyzer>
6. The comment is empty. Add text to the comment or remove it.
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="CommentsMustContainText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
7. More rules you can found in the below url:
http://www.stylecop.com/docs/StyleCop%20Rules.html
相关文章推荐
- 常用的opengl函数(三)
- Linux find命令简明
- 电商网站接入快递查询
- Tomcat服务器的安装配置图文教程(推荐)
- linux下配置 tomcat7 自动启动
- 查看Linux下的文件
- 查看Linux下的文件
- linux:~/.bash_history ,~/.bash_logout,/etc/issue,/etc/issue.net,/etc/motd
- hadoop安全机制Kerberos详细介绍
- linux mysql 优化
- Oralce drop all tables
- ARM+Linux系统启动流程分析----ARM处理器的启动流程
- ARM+Linux系统启动流程分析----系统启动总概述
- linux中的vi编辑器(二)
- Ubuntu12.04下OpenCV2.4.9源码编译安装
- rsync和sersync实现数据实时同步
- nginx安全加固
- 统计文件行数
- 【转】Ecshop 后台增加一个左侧列表菜单menu菜单的方法
- Linux安装MYsql(yum)