/// <summary> /// Parses a string and extracts the options, returning a new JsLintConfiguration object /// </summary> /// <param name="s"></param> /// <returns></returns> public static JsLintConfiguration ParseString(string s, LinterType type) { JsLintConfiguration returner = new JsLintConfiguration(); returner.LinterType = type; // if there are no options we return an empty default object if (!string.IsNullOrWhiteSpace(s)) { // otherwise, wipe the bool options //returner.BoolOptions = (JsLintBoolOption)0; // now go through each string string[] options = s.Split(','); foreach (string option in options) { string[] optionValue = option.Split(':', '='); // test if it is a single value without assigment ("evil" == "evil:true") if (optionValue.Length == 1) { returner.SetOption(optionValue[0], true); } else if (optionValue.Length == 2) { // otherwise we have key value pair string key = optionValue[0].Trim(); returner.SetOption(optionValue[0], optionValue[1].Trim()); } else { throw new Exception("Unrecognised option format - too many colons"); } } } return returner; }
/// <summary> /// Parse a global format config file /// </summary> /// <param name="configFileData"></param> /// <returns></returns> public static JsLintConfiguration ParseConfigFile(string configFileData, LinterType linterType) { JsLintConfiguration config = new JsLintConfiguration(); config.LinterType = linterType; ConfigFileParser parser = new ConfigFileParser(); parser.ConfigData = configFileData; foreach (var kvp in parser.GetKVPSection("jslint")) { config.SetOption(kvp.Key, kvp.Value); } foreach (var kvp in parser.GetKVPSection("global")) { config.SetGlobal(kvp.Key); } foreach (var item in parser.GetValueSection("exclude", "\n,")) { config.SetFileExclude(item); } foreach (var item in parser.GetKVPSection("sharplinter")) { switch (item.Key.ToLower()) { case "ignorestart": config.IgnoreStart = item.Value; break; case "ignoreend": config.IgnoreEnd = item.Value; break; case "ignorefile": config.IgnoreFile = item.Value; break; default: throw new Exception("Unknown sharpLinter option '" + item.Key + "'"); } } return(config); }