DiagnosticRules.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. }