public static void Check(string startBlock, Watchdog wd)
        {
            if (startBlock.Contains("(") && startBlock.Contains(")"))
            {
                string methodName = CamelCaseCSharpWatchdog.GetPossibleMethodName(startBlock);

                if (methodName.Length > 2
                    && char.IsLower(methodName, 0))
                {
                    wd.IncreaseCount((int)ErrorCodes.PascalCaseError);

                    // TODO: The line report is inaccurate, as several lines may have passed.
                    // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                    //
                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0}: '{1}' (line {2})",
                                              wd.errorCodeStrings[(int)ErrorCodes.PascalCaseError],
                                              methodName,
                                              wd.checkedLinesThisFile));
                    }
                }
            }

            return;
        }
Exemple #2
0
        public static void Check(string startBlock, Watchdog wd)
        {
            if (startBlock.Contains("enum "))
            {
                var enumName = CamelCaseCSharpWatchdog.GetPossibleBlockIdentifier("enum", startBlock);

                if (enumName.Length > 2 &&
                    char.IsLower(enumName, 0))
                {
                    wd.IncreaseCount((int)ErrorCodes.PascalCaseError);

                    // TODO: The line report is inaccurate, as several lines may have passed.
                    // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                    //
                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0}: '{1}' (line {2})",
                                              wd.errorCodeStrings[(int)ErrorCodes.PascalCaseError],
                                              enumName,
                                              wd.checkedLinesThisFile));
                    }
                }
            }

            return;
        }
        public static void Check(string statement, Watchdog wd)
        {
            // Check for closing brace, indicating the statement is complete.
            //
            // TODO: Use central reserved words list.
            //
            if ((statement.Trim().StartsWith("if")
                 || statement.Trim().StartsWith("else")
                 || statement.Trim().StartsWith("while")
                 || statement.Trim().StartsWith("foreach")
                 || statement.Trim().StartsWith("for"))
                && statement.Contains(")"))
            {
                wd.IncreaseCount((int)ErrorCodes.MissingBracesError);

                // TODO: The line report is inaccurate, as several lines may have passed.
                // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                //
                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.MissingBracesError],
                                          wd.checkedLinesThisFile + 1));
                }
            }

            return;
        }
        public static void Check(string statement, Watchdog wd)
        {
            // Check for closing brace, indicating the statement is complete.
            //
            // TODO: Use central reserved words list.
            //
            if ((statement.Trim().StartsWith("if") ||
                 statement.Trim().StartsWith("else") ||
                 statement.Trim().StartsWith("while") ||
                 statement.Trim().StartsWith("foreach") ||
                 statement.Trim().StartsWith("for")) &&
                statement.Contains(")"))
            {
                wd.IncreaseCount((int)ErrorCodes.MissingBracesError);

                // TODO: The line report is inaccurate, as several lines may have passed.
                // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                //
                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.MissingBracesError],
                                          wd.checkedLinesThisFile + 1));
                }
            }

            return;
        }
        public static void Check(string statement, Watchdog wd)
        {
            // Trim leading spaces before check.
            // Ignore empty statements, e.g. inline 'new' statements.
            // Ignore comparison operators, as they most probably are part of a 'for' loop.
            // Ignore single closing braces, most probably closing inline lambdas.
            // Ignore 'get' and 'set': Properties are OK in a single line.
            //
            if (wd.checkedLinesThisFile > 1
                && statement.Length > 0
                && !statement.TrimStart(char.Parse(" "), char.Parse("\r"), char.Parse("\t")).StartsWith("\n")
                && !statement.Contains("<")
                && !statement.Contains(">")
                && statement != ")"
                && !statement.Contains("get")
                && !statement.Contains("set"))
            {
                wd.IncreaseCount((int)ErrorCodes.MultipleStatementError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.MultipleStatementError],
                                          wd.checkedLinesThisFile + 1));
                }
            }

            return;
        }
Exemple #6
0
        public static void Check(string statement, Watchdog wd)
        {
            // Trim leading spaces before check.
            // Ignore empty statements, e.g. inline 'new' statements.
            // Ignore comparison operators, as they most probably are part of a 'for' loop.
            // Ignore single closing braces, most probably closing inline lambdas.
            // Ignore 'get' and 'set': Properties are OK in a single line.
            //
            if (wd.checkedLinesThisFile > 1 &&
                statement.Length > 0 &&
                !statement.TrimStart(char.Parse(" "), char.Parse("\r"), char.Parse("\t")).StartsWith("\n") &&
                !statement.Contains("<") &&
                !statement.Contains(">") &&
                statement != ")" &&
                !statement.Contains("get") &&
                !statement.Contains("set"))
            {
                wd.IncreaseCount((int)ErrorCodes.MultipleStatementError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.MultipleStatementError],
                                          wd.checkedLinesThisFile + 1));
                }
            }

            return;
        }
        public static void Check(string startBlock, Watchdog wd)
        {
            if (startBlock.Contains("interface "))
            {
                var interfaceName = CamelCaseCSharpWatchdog.GetPossibleBlockIdentifier("interface", startBlock);

                if (interfaceName.Length > 2
                    && !interfaceName.StartsWith("I"))
                {
                    wd.IncreaseCount((int)ErrorCodes.InterfaceNamingError);

                    // TODO: The line report is inaccurate, as several lines may have passed.
                    // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                    //
                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0}: '{1}' (line {2})",
                                              wd.errorCodeStrings[(int)ErrorCodes.InterfaceNamingError],
                                              interfaceName,
                                              wd.checkedLinesThisFile));
                    }
                }
            }

            return;
        }
Exemple #8
0
        public static void Check(string startBlock, Watchdog wd)
        {
            if (!startBlock.Contains("class ") &&
                !startBlock.Contains("interface ") &&
                !startBlock.Contains("enum ") &&
                !startBlock.Contains("(") &&
                !startBlock.Contains(")"))
            {
                // Assuming it's a property

                string propertyName = "";

                Match propertyNameMatch = Regex.Match(startBlock, @"\s+(\w+)\s*$");

                if (propertyNameMatch.Success)
                {
                    propertyName = propertyNameMatch.Groups[1].Value;

                    Logging.Debug("Property name: " + propertyName);
                }

                // TODO: Use central reserved words list.
                // TODO: Check if any of these aren't already being ruled out by braces etc. checks above
                //
                if (propertyName != "if" &&
                    propertyName != "else" &&
                    propertyName != "while" &&
                    propertyName != "foreach" &&
                    propertyName != "for" &&
                    propertyName != "get" &&
                    propertyName != "set" &&
                    propertyName != "try" &&
                    propertyName != "catch" &&
                    propertyName != "delegate" &&
                    propertyName != "using" &&
                    propertyName != "switch" &&
                    propertyName.Length > 2 &&
                    char.IsLower(propertyName, 0))
                {
                    wd.IncreaseCount((int)ErrorCodes.PascalCaseError);

                    // TODO: The line report is inaccurate, as several lines may have passed.
                    // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                    //
                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0}: '{1}' (line {2})",
                                              wd.errorCodeStrings[(int)ErrorCodes.PascalCaseError],
                                              propertyName,
                                              wd.checkedLinesThisFile));
                    }
                }
            }

            return;
        }
        public static void Check(string startBlock, Watchdog wd)
        {
            if (!startBlock.Contains("class ")
                && !startBlock.Contains("interface ")
                && !startBlock.Contains("enum ")
                && !startBlock.Contains("(")
                && !startBlock.Contains(")"))
            {
                // Assuming it's a property

                string propertyName = "";

                Match propertyNameMatch = Regex.Match(startBlock, @"\s+(\w+)\s*$");

                if (propertyNameMatch.Success)
                {
                    propertyName = propertyNameMatch.Groups[1].Value;

                    Logging.Debug("Property name: " + propertyName);
                }

                // TODO: Use central reserved words list.
                // TODO: Check if any of these aren't already being ruled out by braces etc. checks above
                //
                if (propertyName != "if"
                    && propertyName != "else"
                    && propertyName != "while"
                    && propertyName != "foreach"
                    && propertyName != "for"
                    && propertyName != "get"
                    && propertyName != "set"
                    && propertyName != "try"
                    && propertyName != "catch"
                    && propertyName != "delegate"
                    && propertyName != "using"
                    && propertyName != "switch"
                    && propertyName.Length > 2
                    && char.IsLower(propertyName, 0))
                {
                    wd.IncreaseCount((int)ErrorCodes.PascalCaseError);

                    // TODO: The line report is inaccurate, as several lines may have passed.
                    // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                    //
                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0}: '{1}' (line {2})",
                                              wd.errorCodeStrings[(int)ErrorCodes.PascalCaseError],
                                              propertyName,
                                              wd.checkedLinesThisFile));
                    }
                }
            }

            return;
        }
        public static void Check(string comment, string precedingInput, Watchdog wd)
        {
            if (wd.checkedLinesThisFile > 1 &&
                !precedingInput.Contains("\n"))
            {
                wd.IncreaseCount((int)ErrorCodes.CommentOnSameLineError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.CommentOnSameLineError],
                                          wd.checkedLinesThisFile));
                }
            }

            return;
        }
        public static void Check(string comment, string precedingInput, Watchdog wd)
        {
            if (wd.checkedLinesThisFile > 1
                && !precedingInput.Contains("\n"))
            {
                wd.IncreaseCount((int)ErrorCodes.CommentOnSameLineError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.CommentOnSameLineError],
                                          wd.checkedLinesThisFile));
                }
            }

            return;
        }
        public static void Check(string statement, Watchdog wd)
        {
            var possibleIdentifier = CamelCaseCSharpWatchdog.GetPossibleIdentifier(statement);

            // TODO: Use central reserved words list.
            //
            if (possibleIdentifier != ""
                && possibleIdentifier != "if"
                && possibleIdentifier != "else"
                && possibleIdentifier != "while"
                && possibleIdentifier != "foreach"
                && possibleIdentifier != "for"
                && !statement.Contains("using")
                && possibleIdentifier != "get"
                && possibleIdentifier != "set"
                && possibleIdentifier != "try"
                && possibleIdentifier != "catch"
                && possibleIdentifier != "delegate"
                && possibleIdentifier != "public"
                && possibleIdentifier != "switch")
            {
                if (statement.Contains("const ")
                    && possibleIdentifier.Length > 2
                    && char.IsLower(possibleIdentifier, 0))
                {

                    wd.IncreaseCount((int)ErrorCodes.PascalCaseError);

                    // TODO: The line report is inaccurate, as several lines may have passed.
                    // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                    //
                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0}: '{1}' (line {2})",
                                              wd.errorCodeStrings[(int)ErrorCodes.PascalCaseError],
                                              possibleIdentifier,
                                              wd.checkedLinesThisFile + 1));
                    }
                }
            }

            return;
        }
Exemple #13
0
        public static void Check(string statement, Watchdog wd)
        {
            if (statement.Contains("\t"))
            {
                wd.IncreaseCount((int)ErrorCodes.TabError);

                // TODO: The line report is inaccurate, as several lines may have passed.
                // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                //
                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.TabError],
                                          wd.checkedLinesThisFile + 1));
                }
            }

            return;
        }
        public static void Check(string startBlock, Watchdog wd)
        {
            if (startBlock.Contains("class ") &&
                startBlock.Contains("public ") &&
                !wd.previousToken.Contains(wd.parsingParameters.startCommentDelimiter + "/") &&
                !wd.previousToken.Contains("</summary>"))
            {
                wd.IncreaseCount((int)ErrorCodes.ClassNotDocumentedError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.ClassNotDocumentedError],
                                          wd.checkedLinesThisFile));
                }
            }

            return;
        }
Exemple #15
0
        public static void Check(string statement, Watchdog wd)
        {
            if (statement.Contains("\t"))
            {
                wd.IncreaseCount((int)ErrorCodes.TabError);

                // TODO: The line report is inaccurate, as several lines may have passed.
                // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                //
                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.TabError],
                                          wd.checkedLinesThisFile + 1));
                }
            }

            return;
        }
        public static void Check(string startBlock, Watchdog wd)
        {
            if (startBlock.Contains("class ")
                && startBlock.Contains("public ")
                && !wd.previousToken.Contains(wd.parsingParameters.startCommentDelimiter + "/")
                && !wd.previousToken.Contains("</summary>"))
            {
                wd.IncreaseCount((int)ErrorCodes.ClassNotDocumentedError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.ClassNotDocumentedError],
                                          wd.checkedLinesThisFile));
                }
            }

            return;
        }
Exemple #17
0
        public static void Check(string statement, Watchdog wd)
        {
            var possibleIdentifier = CamelCaseCSharpWatchdog.GetPossibleIdentifier(statement);

            // TODO: Use central reserved words list.
            //
            if (possibleIdentifier != "" &&
                possibleIdentifier != "if" &&
                possibleIdentifier != "else" &&
                possibleIdentifier != "while" &&
                possibleIdentifier != "foreach" &&
                possibleIdentifier != "for" &&
                !statement.Contains("using") &&
                possibleIdentifier != "get" &&
                possibleIdentifier != "set" &&
                possibleIdentifier != "try" &&
                possibleIdentifier != "catch" &&
                possibleIdentifier != "delegate" &&
                possibleIdentifier != "public" &&
                possibleIdentifier != "switch")
            {
                if (!statement.Contains("const ") &&
                    possibleIdentifier.Length > 2 &&
                    char.IsUpper(possibleIdentifier, 0))
                {
                    wd.IncreaseCount((int)ErrorCodes.CamelCaseError);

                    // TODO: The line report is inaccurate, as several lines may have passed.
                    // HACK: Assuming the next line and using CheckedLinesOfCode + 1.
                    //
                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0}: '{1}' (line {2})",
                                              wd.errorCodeStrings[(int)ErrorCodes.CamelCaseError],
                                              possibleIdentifier,
                                              wd.checkedLinesThisFile + 1));
                    }
                }
            }

            return;
        }
        public static void Check(string comment, string precedingInput, Watchdog wd)
        {
            // Also include /// doc comments.
            // Ignore empty comments.
            // Ignore comments starting with "--", these are most probably auto-generated decorative lines.
            //
            if (!comment.Trim().EndsWith(wd.parsingParameters.startCommentDelimiter) &&
                !(comment.StartsWith(wd.parsingParameters.startCommentDelimiter + " ") ||
                  comment.StartsWith(wd.parsingParameters.startCommentDelimiter + "/ ")) &&
                !comment.StartsWith(wd.parsingParameters.startCommentDelimiter + "--"))
            {
                wd.IncreaseCount((int)ErrorCodes.CommentNoSpaceError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.CommentNoSpaceError],
                                          wd.checkedLinesThisFile));
                }
            }

            return;
        }
        public static void Check(string startBlock, Watchdog wd)
        {
            if (startBlock.Contains("(") && startBlock.Contains(")"))
            {
                // Make sure 'public' is before the first brace.
                //
                if (startBlock.Split(Char.Parse("("))[0].Contains("public ") &&
                    !wd.previousToken.Contains(wd.parsingParameters.startCommentDelimiter + "/") &&
                    !wd.previousToken.Contains("</summary>"))
                {
                    wd.IncreaseCount((int)ErrorCodes.MethodNotDocumentedError);

                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0} (line {1})",
                                              wd.errorCodeStrings[(int)ErrorCodes.MethodNotDocumentedError],
                                              wd.checkedLinesThisFile));
                    }
                }
            }

            return;
        }
        public static void Check(string startBlock, Watchdog wd)
        {
            if (startBlock.Contains("(") && startBlock.Contains(")"))
            {
                // Make sure 'public' is before the first brace.
                //
                if (startBlock.Split(Char.Parse("("))[0].Contains("public ")
                    && !wd.previousToken.Contains(wd.parsingParameters.startCommentDelimiter + "/")
                    && !wd.previousToken.Contains("</summary>"))
                {
                    wd.IncreaseCount((int)ErrorCodes.MethodNotDocumentedError);

                    if (wd.woff != null)
                    {
                        wd.woff(string.Format("{0} (line {1})",
                                              wd.errorCodeStrings[(int)ErrorCodes.MethodNotDocumentedError],
                                              wd.checkedLinesThisFile));
                    }
                }
            }

            return;
        }
        public static void Check(string comment, string precedingInput, Watchdog wd)
        {
            // Also include /// doc comments.
            // Ignore empty comments.
            // Ignore comments starting with "--", these are most probably auto-generated decorative lines.
            //
            if (!comment.Trim().EndsWith(wd.parsingParameters.startCommentDelimiter)
                && !(comment.StartsWith(wd.parsingParameters.startCommentDelimiter + " ")
                     || comment.StartsWith(wd.parsingParameters.startCommentDelimiter + "/ "))
                && !comment.StartsWith(wd.parsingParameters.startCommentDelimiter + "--"))
            {
                wd.IncreaseCount((int)ErrorCodes.CommentNoSpaceError);

                if (wd.woff != null)
                {
                    wd.woff(string.Format("{0} (line {1})",
                                          wd.errorCodeStrings[(int)ErrorCodes.CommentNoSpaceError],
                                          wd.checkedLinesThisFile));
                }
            }

            return;
        }