public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned.ToLines(); var nesting = 0; // Remove brackets but preserve lines lines.ForEachWithIndex((i, line) => { foreach (var ch in line) { if (ch == '{') { nesting++; } if (ch == '}') { nesting--; } if (MaxNumberOfScopesValue < nesting) { var violationText = "Too deep nesting in line {0} - {1} scopes".Formatted(i + 1, nesting); var violation = new RuleViolation(violationText); Violations.Add(violation); } else if (nesting < 0) { var violationText = "} with no matching { on line {0}".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } } }); if (nesting > 0) { var violationText = "{ with no matching } on line {0}".Formatted(lines.Count); var violation = new RuleViolation(violationText); Violations.Add(violation); } }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned.ToLines(); var nesting = 0; // Remove brackets but preserve lines lines.ForEachWithIndex((i, line) => { foreach (var ch in line) { if (ch == '{') nesting++; if (ch == '}') nesting--; if (MaxNumberOfScopesValue < nesting) { var violationText = "Too deep nesting in line {0} - {1} scopes".Formatted(i+1,nesting); var violation = new RuleViolation(violationText); Violations.Add(violation); } else if (nesting < 0) { var violationText = "} with no matching { on line {0}".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } } }); if (nesting > 0) { var violationText = "{ with no matching } on line {0}".Formatted(lines.Count); var violation = new RuleViolation(violationText); Violations.Add(violation); } }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCode.ToLines(); lines.ForEachWithIndex((i, line) => { if (line.Length > MaxLineLength) { var violationText = "Line {0} has {1} symbols".Formatted(i + 1, line.Length); var violation = new RuleViolation(violationText); Violations.Add(violation); } }); }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned .ToLines(); lines.ForEachWithIndex((i, line) => { if (Regex.Match(line, "\\s+$").Captures.Count > 0) { var violationText = "Line {0} has trailing white spaces".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } }); }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned .ToLines(); lines.ForEachWithIndex((i, line) => { if (line.Contains("goto")) { var violationText = "Line {0} with use of goto".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } }); }