public static List <JSLintError> FindTodos(string file) { int lastindex = -1; int lastline = 1; List <JSLintError> todos = new List <JSLintError>(); MatchCollection matches = FindTodoRegex.Matches(file); foreach (Match match in matches) { int indexOfTODO = -1; while (true) { indexOfTODO = match.Captures[0].Value.IndexOf("TODO", indexOfTODO + 1, StringComparison.InvariantCultureIgnoreCase); if (indexOfTODO < 0) { break; } char characterBefore = indexOfTODO > 2 ? match.Captures[0].Value[indexOfTODO - 1] : ' '; char characterAfter = indexOfTODO + 4 >= match.Captures[0].Value.Length ? ' ' : match.Captures[0].Value[indexOfTODO + 4]; if (char.IsWhiteSpace(characterBefore) && !char.IsLetter(characterAfter)) { break; } } if (indexOfTODO < 0) { continue; } while (true) { int i = file.IndexOf('\n', lastindex + 1); if (i > match.Index || i <= 0) { break; } lastline++; lastindex = i; } JSLintError jse = new JSLintError() { Column = match.Index - lastindex, Line = lastline, Message = match.Captures[0].Value.Substring(indexOfTODO).Trim('/', '*').Replace('\n', ' ').Replace('\r', ' ').Trim() }; todos.Add(jse); } return(todos); }
public void ProcessData(object data) { Dictionary <string, object> dataDict = data as Dictionary <string, object>; if (dataDict != null) { Action <Dictionary <string, object> > processor = (error) => { JSLintError jsError = new JSLintError(); if (error.ContainsKey("line")) { if (error["line"] is int) { jsError.Line = (int)error["line"]; } } if (error.ContainsKey("character")) { if (error["character"] is int) { jsError.Column = ((int)error["character"]) + 1; } } if (jsError.Column == 0) { jsError.Column = 1; } if (error.ContainsKey("reason")) { if (error["reason"] is string) { jsError.Message = (string)error["reason"]; } } if (error.ContainsKey("evidence")) { if (error["evidence"] is string) { jsError.Evidence = (string)error["evidence"]; } } _errors.Add(jsError); }; if (dataDict.ContainsKey("errors")) { ProcessListOfObject(dataDict["errors"], processor); } if (_processUnuseds && dataDict.ContainsKey("unused")) { ProcessListOfObject(dataDict["unused"], (unused) => { JSLintError jsError = new JSLintError(); if (unused.ContainsKey("line")) { jsError.Line = (int)unused["line"]; } jsError.Column = 1; if (unused.ContainsKey("name")) { jsError.Message = string.Format("Unused Variable '{0}'.", unused["name"]); } _errors.Add(jsError); }); } if (dataDict.ContainsKey("vsdocerr")) { ProcessListOfObject(dataDict["vsdocerr"], processor); } } }