DiagnosticRules.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. public static class EntityClassDeclarationAnalyzerRule
  173. {
  174. private const string Title = "实体类限制多层继承";
  175. private const string MessageFormat = "类: {0} 不能继承{1}的子类 请直接继承{1}";
  176. private const string Description = "实体类限制多层继承.";
  177. public static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticIds.EntityClassDeclarationAnalyzerRuleId,
  178. Title,
  179. MessageFormat,
  180. DiagnosticCategories.All,
  181. DiagnosticSeverity.Error, true, Description);
  182. }
  183. public static class EntityDelegateDeclarationAnalyzerRule
  184. {
  185. private const string Title = "实体类禁止声明委托字段或属性";
  186. private const string MessageFormat = "实体类: {0} 不能在类内部声明委托字段或属性: {1}";
  187. private const string Description = "实体类禁止声明委托字段或属性.";
  188. public static readonly DiagnosticDescriptor Rule =
  189. new DiagnosticDescriptor(DiagnosticIds.DelegateAnalyzerRuleId,
  190. Title,
  191. MessageFormat,
  192. DiagnosticCategories.Model,
  193. DiagnosticSeverity.Error,
  194. true,
  195. Description);
  196. }
  197. public static class EntityFieldDeclarationInEntityAnalyzerRule
  198. {
  199. private const string Title = "实体类禁止声明实体字段";
  200. private const string MessageFormat = "实体类: {0} 不能在类内部声明实体或含有实体类参数的泛型类字段: {1} 请使用EntityRef代替";
  201. private const string Description = "实体类禁止声明实体字段.";
  202. public static readonly DiagnosticDescriptor Rule =
  203. new DiagnosticDescriptor(DiagnosticIds.EntityFieldDeclarationInEntityAnalyzerRuleId,
  204. Title,
  205. MessageFormat,
  206. DiagnosticCategories.Model,
  207. DiagnosticSeverity.Error,
  208. true,
  209. Description);
  210. }
  211. public static class AsyncMethodReturnTypeAnalyzerRule
  212. {
  213. private const string Title = "禁止声明返回值为void的异步方法";
  214. private const string MessageFormat = "禁止声明返回值为void的异步方法";
  215. private const string Description = "禁止声明返回值为void的异步方法.";
  216. public static readonly DiagnosticDescriptor Rule =
  217. new DiagnosticDescriptor(DiagnosticIds.AsyncMethodReturnTypeAnalyzerRuleId,
  218. Title,
  219. MessageFormat,
  220. DiagnosticCategories.Model,
  221. DiagnosticSeverity.Error,
  222. true,
  223. Description);
  224. }
  225. public static class ClientClassInServerAnalyzerRule
  226. {
  227. private const string Title = "禁止在Server程序集内引用ET.Client命名空间";
  228. private const string MessageFormat = "禁止在Server程序集内引用ET.Client命名空间";
  229. private const string Description = "禁止在Server程序集内引用ET.Client命名空间.";
  230. public static readonly DiagnosticDescriptor Rule =
  231. new DiagnosticDescriptor(DiagnosticIds.ClientClassInServerAnalyzerRuleId,
  232. Title,
  233. MessageFormat,
  234. DiagnosticCategories.Model,
  235. DiagnosticSeverity.Error,
  236. true,
  237. Description);
  238. }
  239. public static class LSEntityFloatMemberAnalyzer
  240. {
  241. private const string Title = "LSEntity类禁止声明浮点数字段或属性";
  242. private const string MessageFormat = "LSEntity类: {0} 禁止声明浮点数字段或属性: {1}";
  243. private const string Description = "LSEntity类禁止声明浮点数字段或属性.";
  244. public static readonly DiagnosticDescriptor Rule =
  245. new DiagnosticDescriptor(DiagnosticIds.LSEntityFloatMemberAnalyzerRuleId,
  246. Title,
  247. MessageFormat,
  248. DiagnosticCategories.Model,
  249. DiagnosticSeverity.Error,
  250. true,
  251. Description);
  252. }
  253. public static class EntitySystemAnalyzerRule
  254. {
  255. private const string Title = "Entity类存在未生成的生命周期函数";
  256. private const string MessageFormat = "Entity类: {0} 存在未生成的生命周期函数111";
  257. private const string Description = "Entity类存在未生成的生命周期函数.";
  258. public static readonly DiagnosticDescriptor Rule =
  259. new DiagnosticDescriptor(DiagnosticIds.EntitySystemAnalyzerRuleId,
  260. Title,
  261. MessageFormat,
  262. DiagnosticCategories.Model,
  263. DiagnosticSeverity.Error,
  264. true,
  265. Description);
  266. }
  267. public static class EntitySystemMethodNeedSystemOfAttrAnalyzerRule
  268. {
  269. private const string Title = "EntitySystem标签只能添加在含有EntitySystemOf标签的静态类中";
  270. private const string MessageFormat = "方法:{0}的{1}标签只能添加在含有{2}标签的静态类中";
  271. private const string Description = "EntitySystem标签只能添加在含有EntitySystemOf标签的静态类中.";
  272. public static readonly DiagnosticDescriptor Rule =
  273. new DiagnosticDescriptor(DiagnosticIds.EntitySystemMethodNeedSystemOfAttrAnalyzerRuleId,
  274. Title,
  275. MessageFormat,
  276. DiagnosticCategories.Model,
  277. DiagnosticSeverity.Error,
  278. true,
  279. Description);
  280. }
  281. public static class FiberLogAnalyzerRule
  282. {
  283. private const string Title = "实体类内部或含有实体类参数的函数内部必须使用Fiber输出日志";
  284. private const string MessageFormat = "实体类内部或含有实体类参数的函数内部必须使用Fiber输出日志";
  285. private const string Description = "实体类内部或含有实体类参数的函数内部必须使用Fiber输出日志.";
  286. public static readonly DiagnosticDescriptor Rule =
  287. new DiagnosticDescriptor(DiagnosticIds.FiberLogAnalyzerRuleId,
  288. Title,
  289. MessageFormat,
  290. DiagnosticCategories.All,
  291. DiagnosticSeverity.Error,
  292. true,
  293. Description);
  294. }
  295. public static class EntityHashCodeAnalyzerRule
  296. {
  297. private const string Title = "实体类HashCode禁止重复";
  298. private const string MessageFormat = "{0} 与 {1} 类名HashCode相同:{2}, 请修改类名保证实体类HashCode唯一";
  299. private const string Description = "实体类HashCode禁止重复.";
  300. public static readonly DiagnosticDescriptor Rule =
  301. new DiagnosticDescriptor(DiagnosticIds.EntityHashCodeAnalyzerRuleId,
  302. Title,
  303. MessageFormat,
  304. DiagnosticCategories.All,
  305. DiagnosticSeverity.Error,
  306. true,
  307. Description);
  308. }
  309. public static class EntityComponentChildAnalyzerRule
  310. {
  311. private const string Title = "实体类禁止同时标记为Component和Child";
  312. private const string MessageFormat = "实体类:{0} 禁止同时标记为Component和Child";
  313. private const string Description = "实体类禁止同时标记为Component和Child.";
  314. public static readonly DiagnosticDescriptor Rule =
  315. new DiagnosticDescriptor(DiagnosticIds.EntityComponentChildAnalyzerRuleId,
  316. Title,
  317. MessageFormat,
  318. DiagnosticCategories.All,
  319. DiagnosticSeverity.Error,
  320. true,
  321. Description);
  322. }
  323. public static class EntityCannotDeclareGenericTypeRule
  324. {
  325. private const string Title = "实体类禁止声明为泛型实体类";
  326. private const string MessageFormat = "实体类:{0} 禁止声明为泛型实体类";
  327. private const string Description = "实体类禁止声明为泛型实体类.";
  328. public static readonly DiagnosticDescriptor Rule =
  329. new DiagnosticDescriptor(DiagnosticIds.EntityCannotDeclareGenericTypeRuleId,
  330. Title,
  331. MessageFormat,
  332. DiagnosticCategories.All,
  333. DiagnosticSeverity.Error,
  334. true,
  335. Description);
  336. }
  337. public static class NetMessageAnalyzerRule
  338. {
  339. private const string Title = "消息类禁止声明实体字段";
  340. private const string MessageFormat = "消息类: {0} 禁止声明实体字段: {1}";
  341. private const string Description = "消息类禁止声明实体字段.";
  342. public static readonly DiagnosticDescriptor Rule =
  343. new DiagnosticDescriptor(DiagnosticIds.NetMessageAnalyzerRuleId,
  344. Title,
  345. MessageFormat,
  346. DiagnosticCategories.All,
  347. DiagnosticSeverity.Error,
  348. true,
  349. Description);
  350. }
  351. public static class DisableNewAnalyzerRule
  352. {
  353. private const string Title = "含有DisableNew标记的类禁止使用new构造对象";
  354. private const string MessageFormat = "禁止使用new构造{0}类型的对象";
  355. private const string Description = "含有DisableNew标记的类禁止使用new构造对象.";
  356. public static readonly DiagnosticDescriptor Rule =
  357. new DiagnosticDescriptor(DiagnosticIds.DisableNewAnalyzerRuleId,
  358. Title,
  359. MessageFormat,
  360. DiagnosticCategories.All,
  361. DiagnosticSeverity.Error,
  362. true,
  363. Description);
  364. }
  365. public static class EntityClassDeclarationAnalyzerrRule
  366. {
  367. private const string Title = "Model/ModelView程序集禁止声明非实体类";
  368. private const string MessageFormat = "Model/ModelView程序集禁止声明非Object类:{0}, 除非加上[EnableClass]";
  369. private const string Description = "Model/ModelView程序集禁止声明非实体类, 除非加上[EnableClass] Attribute.";
  370. public static readonly DiagnosticDescriptor Rule =
  371. new DiagnosticDescriptor(DiagnosticIds.DisableNormalClassDeclaratonInModelAssemblyAnalyzerRuleId,
  372. Title,
  373. MessageFormat,
  374. DiagnosticCategories.All,
  375. DiagnosticSeverity.Error,
  376. true,
  377. Description);
  378. }
  379. }