SupportedDiagnostics => ImmutableArray.Create(Descriptor);
-
- public override void Initialize(AnalysisContext context)
- {
- context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.NamedType, SymbolKind.Method, SymbolKind.Property, SymbolKind.Field, SymbolKind.Event);
- }
-
- private static void AnalyzeSymbol(SymbolAnalysisContext context)
- {
- if (context.Symbol.DeclaredAccessibility != Accessibility.Public)
- return;
-
- if (!string.IsNullOrWhiteSpace(context.Symbol.GetDocumentationCommentXml()))
- return;
-
- // ignore getters and setter methods for documentation
- if (context.Symbol.Kind == SymbolKind.Method)
- {
- var methodSymbol = (IMethodSymbol)context.Symbol;
- if (methodSymbol.MethodKind == MethodKind.PropertyGet ||
- methodSymbol.MethodKind == MethodKind.PropertySet)
- return;
- }
-
- var location = context.Symbol.Locations[0];
- var name = context.Symbol.Name;
-
- var diagnostic = Diagnostic.Create(Descriptor, location, context.Symbol.Kind.ToString(), name);
- context.ReportDiagnostic(diagnostic);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.Designer.cs b/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.Designer.cs
index f1db291..7c4b06f 100644
--- a/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.Designer.cs
+++ b/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.Designer.cs
@@ -441,7 +441,7 @@ public static string AG0038Title {
}
///
- /// Looks up a localized string similar to Libraries with Public members must have documentation.
+ /// Looks up a localized string similar to Method {0} has {1} lines of code and is potentially not readable, consider refactoring for better readability. {2} non-whitespace lines is what we recommend as a maximum, but its up to individual context..
///
public static string AG0039Title {
get {
diff --git a/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.resx b/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.resx
index 924e99a..c44c768 100644
--- a/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.resx
+++ b/src/Agoda.Analyzers/AgodaCustom/CustomRulesResources.resx
@@ -249,6 +249,6 @@ One exception is logging, where it can be useful to see the exact DC / cluster /
Do not use #region directives
- Libraries with Public members must have documentation
+ Method {0} has {1} lines of code and is potentially not readable, consider refactoring for better readability. {2} non-whitespace lines is what we recommend as a maximum, but its up to individual context.
\ No newline at end of file
diff --git a/src/Agoda.Analyzers/RuleContent/AG0039MethodLineLengthAnalyzer.html b/src/Agoda.Analyzers/RuleContent/AG0039MethodLineLengthAnalyzer.html
new file mode 100644
index 0000000..9ff1cae
--- /dev/null
+++ b/src/Agoda.Analyzers/RuleContent/AG0039MethodLineLengthAnalyzer.html
@@ -0,0 +1,71 @@
+
+ Long methods should be considered for refactoring
+
+
+ -
+ This rule is to help people identify potentially long methods, so they can consider refactoring them.
+
+ -
+ The rule does not count lines of whitespace in the recommended maximum is 40 lines, this varies per context though and should not be looked at as a hard limit.
+
+ -
+ Try to break up long methods into smaller private methods that describe what's going on.
+
+ -
+ However, don't chain methods together to avoid long methods when refactoring.
+
+ Noncompliant Code Example
+
+class MyClass()
+{
+ public void MethodThatDoesALotOfStuff()
+ {
+ return DoThisFirst();
+ }
+
+ private int DoThisFirst()
+ {
+ // do some stuff...
+ return DoThisSecond()
+ }
+ private int DoThisSecond()
+ {
+ // do some stuff...
+ return DoThisThird();
+ }
+ private int DoThisThird()
+ {
+ // do some stuff...
+ }
+
+}
+
+ Compliant Code Example
+
+class MyClass()
+{
+ public void MethodThatDoesALotOfStuff()
+ {
+ DoThisFirst();
+ DoThisSecond();
+ return DoThisThird();
+ }
+
+ private void DoThisFirst()
+ {
+ // do some stuff...
+ }
+ private void DoThisSecond()
+ {
+ // do some stuff...
+ }
+ private int DoThisThird()
+ {
+ // do some stuff...
+ }
+}
+
+
+ If you are having problems with breaking methods down, try Martin Fowler's Book called refactoring https://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Signature/dp/0134757599/
+
+
\ No newline at end of file
diff --git a/src/Agoda.Analyzers/RuleContent/AG0039UndocumentedMemberAnalyzer.html b/src/Agoda.Analyzers/RuleContent/AG0039UndocumentedMemberAnalyzer.html
deleted file mode 100644
index 2f2de7b..0000000
--- a/src/Agoda.Analyzers/RuleContent/AG0039UndocumentedMemberAnalyzer.html
+++ /dev/null
@@ -1,19 +0,0 @@
-
- Public members should be documented or made internal
-
-
- -
- This rule is intended for libraries, it helps other people understand how to use teh code you publish.
-
- -
- We follow Docs as Code (https://www.writethedocs.org/guide/docs-as-code/), so we want to document the code in the code, not in a separate document.
- This helps ensure that we can the documentation updated, as we can use the same tools we use for code to ensure we update the documentation.
- For example, this static code analysis rule
-
- -
- Recommend using it with tools like DocFx to complete the documentation loop from code to make it easier for people to consume.
-
- -
- Or make them internal, sometimes you don''t want to documentation them because you don't intend people to use them, if this is the case, make them internal.
-
-
\ No newline at end of file