public List <JSLintError> Lint(string javascript, JSLintOptions configuration, bool isJavaScript) { if (string.IsNullOrEmpty(javascript)) { throw new ArgumentNullException("javascript"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } lock (_lock) { Linters linterToUse = isJavaScript ? configuration.SelectedLinter : Linters.JSLint; JavascriptContext context = GetLinterContext(linterToUse); LintDataCollector dataCollector = new LintDataCollector(configuration.ErrorOnUnused); // Setting the externals parameters of the context context.SetParameter("dataCollector", dataCollector); context.SetParameter("javascript", javascript); context.SetParameter("options", configuration.ToJsOptionVar(linterToUse)); // Running the script context.Run("lintRunner(linterName, dataCollector, javascript, options);"); return(dataCollector.Errors); } }
private JavascriptContext GetLinterContext(Linters linter) { if (_contexts.ContainsKey(linter)) { return(_contexts[linter]); } JavascriptContext context = null; switch (linter) { case Linters.JSLint: context = setupContext("fulljslint.js"); context.SetParameter("linterName", "JSLINT"); break; case Linters.JSLintOld: context = setupContext("old_fulljslint.js"); context.SetParameter("linterName", "JSLINT"); break; case Linters.JSHint: context = setupContext("jshint.js"); context.SetParameter("linterName", "JSHINT"); break; default: throw new Exception("Invalid linter to create context for"); } _contexts.Add(linter, context); return(context); }
public LintBooleanSettingModel(string jsname, string label, string tooltip, Linters appliesTo, bool onByDefault = false) { JSName = jsname; Tooltip = tooltip; LintersAppliesTo = appliesTo; Label = label; DefaultOn = onByDefault; }
public static bool AppliesTo(string jsName, Linters linter) { foreach (LintBooleanSettingModel option in AllOptions) { if (option.JSName == jsName) { return((option.LintersAppliesTo & linter) > 0); } } return(false); }
public static bool AppliesTo(string jsName, Linters linter) { foreach (LintBooleanSettingModel option in AllOptions) { if (option.JSName == jsName) { return (option.LintersAppliesTo & linter) > 0; } } return false; }
internal void LoadLinterSettings(Linters linter, SerializableDictionary <string, bool> boolOptions) { if (boolOptions != this._options.BoolOptions2) { this._options.BoolOptions2.Clear(); foreach (KeyValuePair <string, bool> option in boolOptions) { this._options.BoolOptions2[option.Key] = option.Value; } Selected.TriggerSettingsChange(); } _options.SelectedLinter = linter; LoadSelected(); }
internal void LoadLinterSettings(Linters linter, SerializableDictionary<string, bool> boolOptions) { if (boolOptions != this._options.BoolOptions2) { this._options.BoolOptions2.Clear(); foreach (KeyValuePair<string, bool> option in boolOptions) { this._options.BoolOptions2[option.Key] = option.Value; } Selected.TriggerSettingsChange(); } _options.SelectedLinter = linter; LoadSelected(); }
private JavascriptContext GetLinterContext(Linters linter) { if (_contexts.ContainsKey(linter)) { return _contexts[linter]; } JavascriptContext context = null; switch (linter) { case Linters.JSLint: context = setupContext("fulljslint.js"); context.SetParameter("linterName", "JSLINT"); break; case Linters.JSLintOld: context = setupContext("old_fulljslint.js"); context.SetParameter("linterName", "JSLINT"); break; case Linters.JSHint: context = setupContext("jshint.js"); context.SetParameter("linterName", "JSHINT"); break; default: throw new Exception("Invalid linter to create context for"); } _contexts.Add(linter, context); return context; }
/// <summary> /// Creates an (javascript compatible) object that JsLint can use for options. /// </summary> /// <returns></returns> public Dictionary<string, object> ToJsOptionVar(Linters linterToUse) { Dictionary<string, object> returner = new Dictionary<string, object>(); foreach (KeyValuePair<string, bool> option in BoolOptions2) { if (LintBooleanSettingModel.AppliesTo(option.Key, linterToUse)) { returner[option.Key.TrimEnd('.')] = option.Value; } } if (PreDefined != null && PreDefined.Count > 0) { returner["predef"] = PreDefined.ToArray(); } if (MaxLength.HasValue) { returner["maxlen"] = MaxLength.Value; } if (IndentSize.HasValue) { returner["indent"] = IndentSize.Value; } if (QuoteMark != null) { switch (QuoteMark) { case "On": returner["quotmark"] = true; break; case "Off": returner["quotmark"] = false; break; case "Single": returner["quotmark"] = "single"; break; case "Double": returner["quotmark"] = "double"; break; } } if (MaxComplexity != null) { returner["maxcomplexity"] = MaxComplexity.Value; } if (MaxDepth != null) { returner["maxdepth"] = MaxDepth.Value; } if (MaxStatements != null) { returner["maxstatements"] = MaxStatements.Value; } if (MaxParams != null) { returner["maxparams"] = MaxParams.Value; } returner["maxerr"] = 499; //we stop at 499 errors in connect so we may as well let lint stop and generate a 499th error telling us where it got to. return returner; }
public LinterModel(string name, Linters type) { Name = name; Type = type; }
/// <summary> /// Creates an (javascript compatible) object that JsLint can use for options. /// </summary> /// <returns></returns> public Dictionary <string, object> ToJsOptionVar(Linters linterToUse) { Dictionary <string, object> returner = new Dictionary <string, object>(); foreach (KeyValuePair <string, bool> option in BoolOptions2) { if (LintBooleanSettingModel.AppliesTo(option.Key, linterToUse)) { returner[option.Key.TrimEnd('.')] = option.Value; } } if (PreDefined != null && PreDefined.Count > 0) { returner["predef"] = PreDefined.ToArray(); } if (MaxLength.HasValue) { returner["maxlen"] = MaxLength.Value; } if (IndentSize.HasValue) { returner["indent"] = IndentSize.Value; } if (QuoteMark != null) { switch (QuoteMark) { case "On": returner["quotmark"] = true; break; case "Off": returner["quotmark"] = false; break; case "Single": returner["quotmark"] = "single"; break; case "Double": returner["quotmark"] = "double"; break; } } if (MaxComplexity != null) { returner["maxcomplexity"] = MaxComplexity.Value; } if (MaxDepth != null) { returner["maxdepth"] = MaxDepth.Value; } if (MaxStatements != null) { returner["maxstatements"] = MaxStatements.Value; } if (MaxParams != null) { returner["maxparams"] = MaxParams.Value; } returner["maxerr"] = 499; //we stop at 499 errors in connect so we may as well let lint stop and generate a 499th error telling us where it got to. return(returner); }