-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOrcNDependRuleFile.ndrules
More file actions
100 lines (94 loc) · 4.95 KB
/
OrcNDependRuleFile.ndrules
File metadata and controls
100 lines (94 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?xml version="1.0" encoding="utf-8"?>
<Queries>
<Group Name="ORC Metrics" Active="True" ShownInReport="False">
<Group Name="Coding Style" Active="True" ShownInReport="False">
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="True"><![CDATA[// <Name>Don't use dangerous method A.Equals(B). Use Equals(A,B) instead.</Name>
// <Id>OPT9001:A.Equals</Id>
warnif count > 0
let wrongMethods = ThirdParty.Methods.WithFullNameIn(
"System.Object.Equals(Object)"
)
from m in Application.Methods.UsingAny(wrongMethods)
where !(m.OverriddensBase.Any()) // Should filter calls of base.Equals()
select new { m, calls = m.MethodsCalled.Intersect(wrongMethods) }
//<Description>
// Do not use A.Equals(B), because A might be null.
//</Description>
//<HowToFix>
// Use object.Equals(A,B) instead
//</HowToFix>
]]></Query>
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="True"><![CDATA[// <Name>Instance fields should be prefixed with a '_'</Name>
// <Id>OPT9002:FieldPrefixNeeded</Id>
warnif count > 0 from f in JustMyCode.Fields where
!f.NameLike (@"^_") &&
!f.IsStatic &&
!f.IsLiteral &&
f.IsPrivate &&
!f.IsGeneratedByCompiler &&
!f.IsSpecialName &&
!f.IsEventDelegateObject
select new { f, f.SizeOfInst }
// This naming convention provokes debate.
// Don't hesitate to customize the regex of
// NameLike to your preference.]]></Query>
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="True"><![CDATA[// <Name>Instance fields should not contain a '_' but be prefixed with a '_'</Name>
// <Id>OPT9003:NoUnderScore</Id>
warnif count > 0 from f in JustMyCode.Fields where
f.NameLike (@"^_.*_.*") &&
!f.IsStatic &&
!f.IsLiteral &&
f.IsPrivate &&
!f.IsGeneratedByCompiler &&
!f.IsSpecialName &&
!f.IsEventDelegateObject
select new { f, f.SizeOfInst }
// This naming convention provokes debate.
// Don't hesitate to customize the regex of
// NameLike to your preference.]]></Query>
<Query Active="False" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[//<Name>Check that all namespaces begins with Orconomy.ProductName</Name>
warnif count > 0 from n in JustMyCode.Namespaces where
!n.NameLike (@"^Orconomy.ProductName")
select new { n, n.NbLinesOfCode } ]]></Query>
</Group>
<Group Name="Info" Active="True" ShownInReport="False">
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Attributes used</Name>
from t in ThirdParty.Types
where t.IsAttributeClass
select t]]></Query>
<Query Active="False" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Types SupressMessage Attribute used</Name>
from t in JustMyCode.Types
where t.HasAttribute("System.Diagnostics.CodeAnalysis.SuppressMessageAttribute")
select t
]]></Query>
<Query Active="False" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Fields SupressMessage Attribute used</Name>
from t in JustMyCode.Fields
where t.HasAttribute("System.Diagnostics.CodeAnalysis.SuppressMessageAttribute")
select t]]></Query>
<Query Active="False" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Methods SupressMessage Attribute used</Name>
from t in JustMyCode.Types.TaggedWithAnyAttributes(
ThirdParty.Types.Where(t => t.IsAttributeClass))
where t.HasAttribute("System.Diagnostics.CodeAnalysis.SuppressMessageAttribute")
select t]]></Query>
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Fields with GeneratedCode Attribute</Name>
from m in Fields
where m.HasAttribute("System.CodeDom.Compiler.GeneratedCodeAttribute".AllowNoMatch())
select new {m, m.ParentType}]]></Query>
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Methods with GeneratedCode Attribute</Name>
from m in Methods
where m.HasAttribute("System.CodeDom.Compiler.GeneratedCodeAttribute".AllowNoMatch())
select new {m, m.ParentType}
]]></Query>
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Types with GeneratedCode Attribute</Name>
from m in Types
where m.HasAttribute("System.CodeDom.Compiler.GeneratedCodeAttribute".AllowNoMatch())
select new {m}
]]></Query>
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Assemblieswith GeneratedCode Attribute</Name>
from m in Assemblies
where m.HasAttribute("System.CodeDom.Compiler.GeneratedCodeAttribute".AllowNoMatch())
select new {m}
]]></Query>
</Group>
</Group>
</Queries>