public void DoCheck(IContext context) { ScriptChecker checker = new ScriptChecker(rtb.Text, Output); rtb_output.Clear(); rtb_output.SelectionColor = Color.DodgerBlue; rtb_output.AppendText("Checking contents..." + Environment.NewLine); if (checker.Verify(context)) { rtb_output.SelectionColor = Color.ForestGreen; rtb_output.AppendText("OK! File parsed without errors!" + Environment.NewLine); rtb_output.Focus(); rtb_output.Select(rtb_output.TextLength - 1, 0); } else { int p0 = rtb_output.TextLength; rtb_output.SelectionColor = Color.Red; rtb_output.AppendText("An error has been encountered: " + Environment.NewLine); rtb_output.Focus(); int p1 = rtb_output.TextLength - 1; rtb_output.AppendText(checker.Error); rtb_output.Select(p0, 0); // move the horizontal scroll to the left rtb_output.Select(p1, 0); } }
public void Highlight(FlickerFreeRichEditTextBox box) { box._ignore = true; box._Paint = false; box.SuspendLayout(); box.SuspendDrawing(); int p0 = box.SelectionStart; int p1 = box.SelectionLength; box.SelectAll(); box.SelectionColor = Color.Black; if (_context != null) { string txt = box.Text; try { ScriptChecker checker = new ScriptChecker(txt, null); SortedList <Pair <int, int>, LintType> lints = checker.Lint(_context); string[] lines = box.Lines; if (lines.Length > 0) { box.Rtf = MakeRTF(lines, lints); /* * LinterType prev = LinterType.NONE; * LinterStep current = new LinterStep(0, 0, LinterType.NONE); * foreach (LinterStep lint in lints) * { * if (current.Line <= lint.Line && current.Position < lint.Position) * { * if (current.Lint != prev) * { * box.Select(box.GetFirstCharIndexFromLine(current.Line - 1) + current.Position, lint.Position - current.Position); * if (box.SelectionColor == Color.Black) * box.SelectionColor = LintColors[current.Lint]; * } * } * prev = current.Lint; * current = lint; * } */ } } catch { box.Text = txt; } } box.SelectionStart = p0; box.SelectionLength = p1; box._Paint = true; box.ResumeLayout(); box.ResumeDrawing(); box._ignore = false; }
private IScriptCheckerConsumer CreateChecker() { var checker = new ScriptChecker(); foreach (var pattern in _config.ValidationFilterConfig.WarnOn) { checker.AddValidationPattern(pattern, ScriptCheck.Warning); } foreach (var pattern in _config.ValidationFilterConfig.HaltOn) { checker.AddValidationPattern(pattern, ScriptCheck.Failed); } return(checker); }
/// <summary> /// Command to check for common issues in script pastes. /// </summary> public void CMD_ScriptCheck(string[] cmds, IUserMessage message) { if (cmds.Length == 0) { SendErrorMessageReply(message, "Command Syntax Incorrect", "`!script <link>`"); return; } string data = GetWebLinkDataForCommand(cmds[0], message); if (data == null) { return; } ScriptChecker checker = new ScriptChecker(data); checker.Run(); SendReply(message, GetResult(checker)); }
private Returned LoadAndValidateScripts(DirectoryInfo projectDirectory) { var scriptFiles = projectDirectory.GetFiles("*.sql", SearchOption.AllDirectories); var result = Returned.Success; var errors = 0; var check = ScriptCheck.Passed; var messages = new List <string>(); foreach (var file in scriptFiles) { string text; messages.Clear(); using (var reader = file.OpenText()) { text = reader.ReadToEnd(); } text = ReplaceVars(text, messages); if (ScriptChecker != null) { check = ScriptChecker.Validate(text, messages); } var script = ScriptParser.Parse(file.Name, text); script.Validate(messages); if ((check == ScriptCheck.Passed || check == ScriptCheck.Warning) && script.IsValid && messages.Count == 0) { _allScripts.Add(script); continue; } LogScriptIssues(file.FullName, messages); result = Returned.Failure; errors++; } _logger.PostEntry("loaded and parsed {0} file(s), {1} had errors", scriptFiles.Length, errors); return(result); }
/// <summary> /// Gets the result Discord embed for the script check. /// </summary> /// <returns>The embed to send.</returns> public Embed GetResult(ScriptChecker checker) { int totalWarns = checker.Errors.Count + checker.Warnings.Count + checker.MinorWarnings.Count; EmbedBuilder embed = new EmbedBuilder().WithTitle("Script Check Results").WithThumbnailUrl((totalWarns > 0) ? Constants.WARNING_ICON : Constants.INFO_ICON); int linesMissing = 0; int shortened = 0; void embedList(List <ScriptChecker.ScriptWarning> list, string title) { if (list.Count > 0) { HashSet <string> usedKeys = new HashSet <string>(); StringBuilder thisListResult = new StringBuilder(list.Count * 200); foreach (ScriptChecker.ScriptWarning entry in list) { if (usedKeys.Contains(entry.WarningUniqueKey)) { continue; } usedKeys.Add(entry.WarningUniqueKey); StringBuilder lines = new StringBuilder(50); if (entry.Line != -1) { lines.Append(entry.Line + 1); } foreach (ScriptChecker.ScriptWarning subEntry in list.SkipWhile(s => s != entry).Skip(1).Where(s => s.WarningUniqueKey == entry.WarningUniqueKey)) { shortened++; if (lines.Length < 40) { lines.Append(", ").Append(subEntry.Line + 1); if (lines.Length >= 40) { lines.Append(", ..."); } } } string message = $"On line {lines}: {entry.CustomMessageForm}"; if (thisListResult.Length + message.Length < 1000 && embed.Length + thisListResult.Length + message.Length < 1800) { thisListResult.Append($"{message}\n"); } else { linesMissing++; } } if (thisListResult.Length > 0) { embed.AddField(title, thisListResult.ToString()); } Console.WriteLine($"Script Checker {title}: {string.Join('\n', list.Select(s => $"{s.Line + 1}: {s.CustomMessageForm}"))}"); } } embedList(checker.Errors, "Encountered Critical Errors"); embedList(checker.Warnings, "Script Warnings"); embedList(checker.MinorWarnings, "Minor Warnings"); embedList(checker.Infos, "Other Script Information"); if (linesMissing > 0) { embed.AddField("Missing Lines", $"There are {linesMissing} lines not able to fit in this result. Fix the listed errors to see the rest."); } if (shortened > 0) { embed.AddField("Shortened Lines", $"There are {shortened} lines that were merged into other lines."); } foreach (string debug in checker.Debugs) { Console.WriteLine($"Script checker debug: {debug}"); } return(embed.Build()); }