DiagnosticRules.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using Microsoft.CodeAnalysis;
  2. namespace ET.Analyzer
  3. {
  4. public static class ETTaskInSyncMethodAnalyzerRule
  5. {
  6. private const string Title = "ETTask方法调用在非异步方法体内使用错误";
  7. private const string MessageFormat = "方法: {0} 在非异步方法体内使用时需要添加.Coroutine()后缀";
  8. private const string Description = "ETTask方法调用在非异步方法体内使用错误.";
  9. public static readonly DiagnosticDescriptor Rule =
  10. new DiagnosticDescriptor(DiagnosticIds.ETTaskInSyncMethodAnalyzerRuleId,
  11. Title,
  12. MessageFormat,
  13. DiagnosticCategories.Hotfix,
  14. DiagnosticSeverity.Error,
  15. true,
  16. Description);
  17. }
  18. public static class ETTaskInAsyncMethodAnalyzerRule
  19. {
  20. private const string Title = "ETTask方法调用在异步方法体内使用错误";
  21. private const string MessageFormat = "方法: {0} 在异步方法体内使用时需要添加await前缀 或 .Coroutine()后缀";
  22. private const string Description = "ETTask方法调用在异步方法体内使用错误.";
  23. public static readonly DiagnosticDescriptor Rule =
  24. new DiagnosticDescriptor(DiagnosticIds.ETTaskInAsyncMethodAnalyzerRuleId,
  25. Title,
  26. MessageFormat,
  27. DiagnosticCategories.Hotfix,
  28. DiagnosticSeverity.Error,
  29. true,
  30. Description);
  31. }
  32. public static class UniqueIdRangeAnaluzerRule
  33. {
  34. private const string Title = "唯一Id字段数值区间约束";
  35. private const string MessageFormat = "类: {0} Id字段: {1}的值: {2} 不在约束的区间内, 请修改";
  36. private const string Description = "唯一Id字段数值区间约束.";
  37. public static readonly DiagnosticDescriptor Rule =
  38. new DiagnosticDescriptor(DiagnosticIds.UniqueIdRangeAnalyzerRuleId,
  39. Title,
  40. MessageFormat,
  41. DiagnosticCategories.Model,
  42. DiagnosticSeverity.Error,
  43. true,
  44. Description);
  45. }
  46. public static class UniqueIdDuplicateAnalyzerRule
  47. {
  48. private const string Title = "唯一Id字段禁止重复";
  49. private const string MessageFormat = "类: {0} Id字段: {1}的值: {2} 与其他Id字段值重复, 请修改";
  50. private const string Description = "唯一Id字段禁止重复.";
  51. public static readonly DiagnosticDescriptor Rule =
  52. new DiagnosticDescriptor(DiagnosticIds.UniqueIdDuplicateAnalyzerRuleId,
  53. Title,
  54. MessageFormat,
  55. DiagnosticCategories.Model,
  56. DiagnosticSeverity.Error,
  57. true,
  58. Description);
  59. }
  60. public static class AddChildTypeAnalyzerRule
  61. {
  62. private const string Title = "AddChild方法类型约束错误";
  63. private const string MessageFormat = "Type: {0} 不允许作为实体: {1} 的AddChild函数参数类型! 若要允许该类型作为参数,请使用ChildOfAttribute对child实体类标记父级类型";
  64. private const string Description = "AddChild方法类型约束错误.";
  65. public static readonly DiagnosticDescriptor Rule =
  66. new DiagnosticDescriptor(DiagnosticIds.AddChildTypeAnalyzerRuleId,
  67. Title,
  68. MessageFormat,
  69. DiagnosticCategories.Hotfix,
  70. DiagnosticSeverity.Error,
  71. true,
  72. Description);
  73. }
  74. public static class DisableAccessEntityChildAnalyzerRule
  75. {
  76. private const string Title = "禁止在Entity类中直接调用Child和Component";
  77. private const string MessageFormat = "禁止在Entity类中直接调用Child和Component";
  78. private const string Description = "禁止在Entity类中直接调用Child和Component.";
  79. public static readonly DiagnosticDescriptor Rule =
  80. new DiagnosticDescriptor(DiagnosticIds.DisableUseChildComponentInEntityAnalyzerRuleId,
  81. Title,
  82. MessageFormat,
  83. DiagnosticCategories.Hotfix,
  84. DiagnosticSeverity.Error,
  85. true,
  86. Description);
  87. }
  88. public static class EntityComponentAnalyzerRule
  89. {
  90. private const string Title = "实体类添加或获取组件类型错误";
  91. private const string MessageFormat = "组件类型: {0} 不允许作为实体: {1} 的组件类型! 若要允许该类型作为参数,请使用ComponentOfAttribute对组件类标记父级实体类型";
  92. private const string Description = "实体类添加或获取组件类型错误.";
  93. public static readonly DiagnosticDescriptor Rule =
  94. new DiagnosticDescriptor(DiagnosticIds.EntityComponentAnalyzerRuleId,
  95. Title,
  96. MessageFormat,
  97. DiagnosticCategories.Hotfix,
  98. DiagnosticSeverity.Error,
  99. true,
  100. Description);
  101. }
  102. public static class StaticFieldDeclarationAnalyzerRule
  103. {
  104. private const string Title = "Static字段声明需要标记标签";
  105. private const string MessageFormat = "Static字段声明 {0} 需要标记标签";
  106. private const string Description = "Static字段声明需要标记标签.";
  107. public static readonly DiagnosticDescriptor Rule =
  108. new DiagnosticDescriptor(DiagnosticIds.StaticFieldDeclarationAnalyzerRule,
  109. Title,
  110. MessageFormat,
  111. DiagnosticCategories.All,
  112. DiagnosticSeverity.Error,
  113. true,
  114. Description);
  115. }
  116. public static class CheckETCancellTokenAfterAwaitAnalyzerRule
  117. {
  118. private const string Title = "含有ETCancelToken参数的异步函数内调用await表达式后必须判断CancelToken.IsCancel";
  119. private const string MessageFormat = "含有ETCancelToken参数的异步函数内调用await表达式后必须判断CancelToken.IsCancel";
  120. private const string Description = "含有ETCancelToken参数的异步函数内调用await表达式后必须判断CancelToken.IsCancel.";
  121. public static readonly DiagnosticDescriptor Rule =
  122. new DiagnosticDescriptor(DiagnosticIds.ETCancellationTokenAnalyzerRuleId,
  123. Title,
  124. MessageFormat,
  125. DiagnosticCategories.All,
  126. DiagnosticSeverity.Error,
  127. true,
  128. Description);
  129. }
  130. public static class AwaitExpressionCancelTokenParamAnalyzerRule
  131. {
  132. private const string Title = "含有ETCancelToken参数的异步函数内调用await表达式必须传入同一个CancelToken";
  133. private const string MessageFormat = "含有ETCancelToken参数的异步函数内调用await表达式必须传入同一个CancelToken";
  134. private const string Description = "含有ETCancelToken参数的异步函数内调用await表达式必须传入同一个CancelToken.";
  135. public static readonly DiagnosticDescriptor Rule =
  136. new DiagnosticDescriptor(DiagnosticIds.AwaitExpressionCancelTokenParamAnalyzerRuleId,
  137. Title,
  138. MessageFormat,
  139. DiagnosticCategories.All,
  140. DiagnosticSeverity.Error,
  141. true,
  142. Description);
  143. }
  144. public static class AsyncMethodWithCancelTokenParamAnalyzerRule
  145. {
  146. private const string Title = "异步函数声明处的ETCancelToken参数禁止声明默认值";
  147. private const string MessageFormat = "异步函数声明处的ETCancelToken参数禁止声明默认值";
  148. private const string Description = "异步函数声明处的ETCancelToken参数禁止声明默认值.";
  149. public static readonly DiagnosticDescriptor Rule =
  150. new DiagnosticDescriptor(DiagnosticIds.AsyncMethodWithCancelTokenParamAnalyzerRuleId,
  151. Title,
  152. MessageFormat,
  153. DiagnosticCategories.All,
  154. DiagnosticSeverity.Error,
  155. true,
  156. Description);
  157. }
  158. public static class ExpressionWithCancelTokenParamAnalyzerRule
  159. {
  160. private const string Title = "函数调用处的ETCancelToken参数禁止传入null";
  161. private const string MessageFormat = "函数调用处的ETCancelToken参数禁止传入null";
  162. private const string Description = "函数调用处的ETCancelToken参数禁止传入null.";
  163. public static readonly DiagnosticDescriptor Rule =
  164. new DiagnosticDescriptor(DiagnosticIds.ExpressionWithCancelTokenParamAnalyzerRuleId,
  165. Title,
  166. MessageFormat,
  167. DiagnosticCategories.All,
  168. DiagnosticSeverity.Error,
  169. true,
  170. Description);
  171. }
  172. }