private void MergeRoot(JSLintNetSettings merge) { if (merge.RunOnSave.HasValue) { this.RunOnSave = merge.RunOnSave; } if (merge.RunOnBuild.HasValue) { this.RunOnBuild = merge.RunOnBuild; } if (merge.CancelBuild.HasValue) { this.CancelBuild = merge.CancelBuild; } if (merge.ErrorLimit.HasValue) { this.ErrorLimit = merge.ErrorLimit; } if (merge.FileLimit.HasValue) { this.FileLimit = merge.FileLimit; } }
public JSLintNetSettings Load(string settingsPath, string configuration) { var mergePath = GetMergePath(settingsPath, configuration); JSLintNetSettings settings; if (this.TryGetSettings(settingsPath, out settings)) { JSLintNetSettings merge; if (!string.IsNullOrEmpty(mergePath) && this.TryGetSettings(mergePath, out merge)) { settings.Merge(merge); } } else { settings = new JSLintNetSettings(); } settings.Files.Add(settingsPath); if (!string.IsNullOrEmpty(mergePath)) { settings.Files.Add(mergePath); } return settings; }
public void Save(JSLintNetSettings settings, string settingsPath) { settings.Version = AssemblyInfo.InformationalVersion; var settingsJson = this.jsonProvider.SerializeSettings(settings); this.fileSystemWrapper.WriteAllText(settingsPath, settingsJson, Encoding.UTF8); }
private void CloneRoot(JSLintNetSettings target) { target.RunOnSave = this.RunOnSave; target.RunOnBuild = this.RunOnBuild; target.CancelBuild = this.CancelBuild; target.ErrorLimit = this.ErrorLimit; target.FileLimit = this.FileLimit; }
public void Spec02() { var target = new JSLintNetSettings(); target.Ignore.Add("target"); var merge = new JSLintNetSettings(); merge.Ignore.Add("merge"); target.Merge(merge); I.Expect(target.Ignore).ToContain("target"); I.Expect(target.Ignore).ToContain("merge"); }
public void Spec03() { var target = new JSLintNetSettings(); target.Ignore.Add("unique"); var merge = new JSLintNetSettings(); merge.Ignore.Add("unique"); target.Merge(merge); I.Expect(target.Ignore).ToContain("unique"); I.Expect(target.Ignore.Count).ToBe(1); }
public SettingsViewModel(JSLintNetSettings model) { this.Model = model; if (this.Model.Options == null) { this.Model.Options = new JSLintOptions(); } this.SettingsSavedCommand = new RelayCommand(this.OnSettingsSaved); this.SettingsCanceledCommand = new RelayCommand(this.OnSettingsCanceled); this.IgnoreAddCommand = new RelayCommand<TextBox>(this.OnIgnoreAdd); this.IgnoreDeleteCommand = new RelayCommand<int>(this.OnIgnoreDelete); }
/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public JSLintNetSettings TypedClone() { var clone = new JSLintNetSettings() { Files = new List <string>(this.Files), Version = this.Version, Output = this.Output, Ignore = new List <string>(this.Ignore), GlobalVariables = new List <string>(this.GlobalVariables), Options = this.Options == null ? null : this.Options.TypedClone() }; this.CloneRoot(clone); return(clone); }
public void Spec01() { var target = new JSLintNetSettings() { Output = Output.Error }; var merge = new JSLintNetSettings() { Output = Output.Message }; target.Merge(merge); I.Expect(target.Output).Not.ToBe(Output.Error); I.Expect(target.Output).ToBe(Output.Message); }
private bool TryGetSettings(string settingsPath, out JSLintNetSettings settings) { if (this.fileSystemWrapper.FileExists(settingsPath)) { var settingsSource = this.fileSystemWrapper.ReadAllText(settingsPath, Encoding.UTF8); if (!string.IsNullOrEmpty(settingsSource)) { settings = this.jsonProvider.DeserializeSettings(settingsSource); this.MaybeMigrate(settings, settingsSource); return(settings != null); } } settings = null; return(false); }
private void MaybeMigrate(JSLintNetSettings settings, string settingsSource) { if (settings != null && !AssemblyInfo.InformationalVersion.Equals(settings.Version, StringComparison.OrdinalIgnoreCase)) { try { dynamic oldSettings = this.jsonProvider.DeserializeObject <ExpandoObject>(settingsSource); var options = oldSettings.options as IDictionary <string, object>; if (options != null) { MigrateOptions(settings.Options, options); MigrateGlobalVariables(settings.GlobalVariables, options); } } catch { } } }
private void MergeIgnore(JSLintNetSettings merge) { if (merge.Ignore == null || merge.Ignore.Count < 1) { return; } if (this.Ignore == null || this.Ignore.Count < 1) { this.Ignore = merge.Ignore; return; } foreach (var ignore in merge.Ignore) { if (!this.Ignore.Contains(ignore)) { this.Ignore.Add(ignore); } } }
public void Spec04() { var target = new JSLintNetSettings(); target.Options = new JSLintOptions() { IndentationFactor = 2, AssumeBrowser = true }; var merge = new JSLintNetSettings(); merge.Options = new JSLintOptions() { IndentationFactor = 4, TolerateUnusedParameters = true }; target.Merge(merge); I.Expect(target.Options.IndentationFactor).ToBe(4); I.Expect(target.Options.AssumeBrowser).ToBeTrue(); I.Expect(target.Options.TolerateUnusedParameters).ToBeTrue(); I.Expect(target.Options.TolerateUncapitalizedConstructors).ToBeNull(); }
public void Spec04() { var target = new JSLintNetSettings(); target.Options = new JSLintOptions() { MaximumErrors = 2, AssumeBrowser = true }; var merge = new JSLintNetSettings(); merge.Options = new JSLintOptions() { MaximumErrors = 4, AssumeES6 = true }; target.Merge(merge); I.Expect(target.Options.MaximumErrors).ToBe(4); I.Expect(target.Options.AssumeBrowser).ToBeTrue(); I.Expect(target.Options.AssumeES6).ToBeTrue(); I.Expect(target.Options.TolerateEval).ToBeNull(); }
/// <summary> /// Merges the specified settings into this instance. /// </summary> /// <param name="merge">The settings to merge.</param> public void Merge(JSLintNetSettings merge) { this.MergeOutput(merge); this.MergeOptions(merge); this.MergeGlobal(merge); this.MergeIgnore(merge); this.MergeRoot(merge); }
public void Save(JSLintNetSettings settings, string settingsPath) { var settingsJson = this.jsonProvider.SerializeSettings(settings); this.fileSystemWrapper.WriteAllText(settingsPath, settingsJson, Encoding.UTF8); }
public void Spec03() { var instance = new JSLintNetSettings(); var ignore = instance.Ignore; ignore.Add(@"path\to\file.js"); var actual = instance.NormalizeIgnore(); I.Expect(actual[0]).ToStartWith(@"\path\to\file.js"); }
private void MergeIgnore(JSLintNetSettings merge) { this.Ignore = MergeLists(this.Ignore, merge.Ignore); }
/// <summary> /// Saves the settings for the specified project. /// </summary> /// <param name="project">The project.</param> /// <param name="settings">The settings.</param> public void SaveSettings(Project project, JSLintNetSettings settings) { var settingsPath = GetSettingsPath(project); this.settingsRepository.Save(settings, settingsPath); var item = project.ProjectItems.Locate().Item(JSLintNetSettings.FileName); if (item == null) { project.ProjectItems.AddFromFile(settingsPath); } }
private void MergeOutput(JSLintNetSettings merge) { if (merge.Output.HasValue) { this.Output = merge.Output; } }
private void MergeGlobal(JSLintNetSettings merge) { this.GlobalVariables = MergeLists(this.GlobalVariables, merge.GlobalVariables); }
public void Spec07() { var target = new JSLintNetSettings(); target.ErrorLimit = 50; target.RunOnBuild = false; target.CancelBuild = true; var merge = new JSLintNetSettings(); merge.ErrorLimit = 100; merge.RunOnBuild = true; merge.RunOnSave = false; target.Merge(merge); I.Expect(target.ErrorLimit).ToBe(100); I.Expect(target.RunOnBuild).ToBeTrue(); I.Expect(target.CancelBuild).ToBeTrue(); I.Expect(target.RunOnSave).ToBeFalse(); }
public void Spec01() { var instance = new JSLintNetSettings(); var ignore = instance.Ignore; ignore.Add(@"some/path"); ignore.Add(@"/some/other/path"); ignore.Add(@"other/path"); var actual = instance.NormalizeIgnore(); I.Expect(actual[0]).ToContain(@"some\path"); I.Expect(actual[1]).ToContain(@"\some\other\path"); I.Expect(actual[2]).ToContain(@"other\path"); }
public void Spec05() { var instance = new JSLintNetSettings(); var ignore = instance.Ignore; ignore.Add(@"path\to"); ignore.Add(@"another\path\"); ignore.Add(@"looks/like/a.file"); var actual = instance.NormalizeIgnore(); I.Expect(actual[0]).ToEndWith(@"\"); I.Expect(actual[2]).ToEndWith(@"\"); }
public void Spec04() { var instance = new JSLintNetSettings(); var ignore = instance.Ignore; ignore.Add(@"root\data.json"); var actual = instance.NormalizeIgnore(); I.Expect(actual[0]).ToBe(@"\root\data.json"); }
/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public JSLintNetSettings TypedClone() { var clone = new JSLintNetSettings() { Files = new List<string>(this.Files), Version = this.Version, Output = this.Output, Ignore = new List<string>(this.Ignore), GlobalVariables = new List<string>(this.GlobalVariables), Options = this.Options == null ? null : this.Options.TypedClone() }; this.CloneRoot(clone); return clone; }
/// <summary> /// Serializes the settings. /// </summary> /// <param name="value">The value.</param> /// <returns> /// A serialized string. /// </returns> public string SerializeSettings(JSLintNetSettings value) { return JsonConvert.SerializeObject(value, serializerSettings); }
private void MergeOptions(JSLintNetSettings merge) { if (merge.Options == null) { return; } if (this.Options == null) { this.Options = merge.Options; return; } this.Options.Merge(merge.Options); }
private IList<TaskFile> GetSourceFiles(JSLintNetSettings settings) { var ignored = settings.NormalizeIgnore(); var taskFiles = new List<TaskFile>(); if (this.sourceFilesSet) { foreach (var item in this.SourceFiles) { if (JSLint.CanLint(item.ItemSpec)) { var taskFile = new TaskFile(this.SourceDirectory, item); if (!taskFile.IsIgnored(ignored)) { taskFiles.Add(taskFile); } } } return taskFiles; } var files = this.fileSystemWrapper.GetFiles(this.SourceDirectory, "*", SearchOption.AllDirectories); foreach (var file in files) { if (JSLint.CanLint(file)) { var taskFile = new TaskFile(this.SourceDirectory, file); if (!taskFile.IsIgnored(ignored)) { taskFiles.Add(taskFile); } } } return taskFiles; }
/// <summary> /// Validates the specified project items using JSLint. /// </summary> /// <param name="projectItems">The project items.</param> /// <param name="settings">The settings.</param> /// <returns> /// The total number of JSLint errors found. /// </returns> public int LintProjectItems(IList<ProjectItem> projectItems, JSLintNetSettings settings) { if (projectItems.Count < 1) { return 0; } var hierarchy = this.GetHierarchy(projectItems[0].ContainingProject); var errors = 0; var files = 0; var errorFiles = 0; var exceptions = 0; var errorLimit = settings.ErrorLimitOrDefault(); var filesLimit = settings.FileLimitOrDefault(); using (var jsLintContext = this.jsLintFactory.CreateContext()) { foreach (var item in projectItems) { var fileName = item.Access().FileName; this.errorListProvider.ClearJSLintErrors(fileName); var isOpen = item.Document != null; var result = ExecutionHelper.Try(() => { string source; if (isOpen) { source = item.Document.Access().Source; } else { source = this.fileSystemWrapper.ReadAllText(fileName, Encoding.UTF8); } return jsLintContext.Lint(source, settings.Options); }); if (result.Success) { var data = result.Data; if (data.Errors.Count > 0) { errors += data.Errors.Count; errorFiles += 1; this.errorListProvider.AddJSLintErrors(fileName, data.Errors, settings.Output, hierarchy); if (errors >= errorLimit) { this.errorListProvider.AddCustomError(CoreResources.ErrorLimitReachedFormat, errors); break; } } } else { var ex = result.Exception; this.errorListProvider.AddCustomError(CoreResources.ProcessingExceptionFormat, fileName, ex.Message); exceptions += 1; if (exceptions >= JSLintNetSettings.ExceptionLimit) { this.errorListProvider.AddCustomError(CoreResources.ExceptionLimitReachedFormat, exceptions); break; } } files += 1; if (files >= filesLimit) { this.errorListProvider.AddCustomError(CoreResources.FileLimitReachedFormat, files); break; } } } var text = GetMessageText(projectItems.Count, errorFiles, errors); this.SetStatusBar(text); return errors; }
private void MaybeMigrate(JSLintNetSettings settings, string settingsSource) { if (settings != null && !AssemblyInfo.InformationalVersion.Equals(settings.Version, StringComparison.OrdinalIgnoreCase)) { try { dynamic oldSettings = this.jsonProvider.DeserializeObject<ExpandoObject>(settingsSource); var options = oldSettings.options as IDictionary<string, object>; if (options != null) { MigrateOptions(settings.Options, options); MigrateGlobalVariables(settings.GlobalVariables, options); } } catch { } } }
/// <summary> /// Validates the specified document using JSLint. /// </summary> /// <param name="document">The document.</param> /// <param name="settings">The settings.</param> /// <returns> /// The total number of JSLint errors found. /// </returns> public int LintDocument(Document document, JSLintNetSettings settings) { this.errorListProvider.ClearJSLintErrors(document.FullName); int errors; var source = document.Access().Source; var hierarchy = this.GetHierarchy(document.ProjectItem.ContainingProject); using (var jsLintContext = this.jsLintFactory.CreateContext()) { var result = jsLintContext.Lint(source, settings.Options); this.errorListProvider.AddJSLintErrors(document.FullName, result.Errors, settings.Output, hierarchy); errors = result.Errors.Count; var text = GetMessageText(errors); this.SetStatusBar(text); } return errors; }
private bool TryGetSettings(string settingsPath, out JSLintNetSettings settings) { if (this.fileSystemWrapper.FileExists(settingsPath)) { var settingsSource = this.fileSystemWrapper.ReadAllText(settingsPath, Encoding.UTF8); if (!string.IsNullOrEmpty(settingsSource)) { settings = this.jsonProvider.DeserializeSettings(settingsSource); this.MaybeMigrate(settings, settingsSource); return settings != null; } } settings = null; return false; }
public void Spec05() { var target = new JSLintNetSettings(); target.Options = null; var merge = new JSLintNetSettings(); merge.Options = new JSLintOptions(); target.Merge(merge); I.Expect(target.Options).Not.ToBeNull(); I.Expect(target.Options).ToBe(merge.Options); }
public void Spec02() { var instance = new JSLintNetSettings(); var ignore = instance.Ignore; ignore.Add(@"some\path"); ignore.Add(@"\some\other\path"); ignore.Add(@"other\path"); var actual = instance.NormalizeIgnore(); I.Expect(actual[0]).ToStartWith(@"\"); I.Expect(actual[2]).ToStartWith(@"\"); }