protected async System.Threading.Tasks.Task <bool> LintBuildSelection(bool isBuildingSolution) { try { Benchmark.Start(); if (!LinterService.IsLinterEnabled) { return(false); } UIHierarchyItem[] selectedItems = BuildSelectedItems.Get(isBuildingSolution); Dictionary <string, string> fileToProjectMap; string[] files = WebLinterPackage.Settings.UseTsConfig ? TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap) : LintFileLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap); if (!files.Any()) { return(false); } return(await LinterService.Lint(showErrorList : true, fixErrors : false, callSync : true, fileNames : files, clearAllErrors : true, fileToProjectMap)); } catch (Exception ex) { Logger.LogAndWarn(ex); Linter.Server.Down(); return(true); // Return value is true if we have VS errors } finally { Benchmark.End(); } }
public void GetLintFilesForSolution() { MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem() { Object = solution }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem }; string[] results = LintFileLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap); Assert.AreEqual(9, results.Length); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react-dom.d.ts"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react.d.ts"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts"); string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts"); string expected5 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts"); string expected6 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts"); string expected7 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts"); string expected8 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx"); string expected9 = Path.GetFullPath(@"../../artifacts/tsconfig/file9.ts"); // Linked file Assert.IsTrue(results.Contains(expected1)); Assert.IsTrue(results.Contains(expected2)); Assert.IsTrue(results.Contains(expected3)); Assert.IsTrue(results.Contains(expected4)); Assert.IsTrue(results.Contains(expected5)); Assert.IsTrue(results.Contains(expected6)); Assert.IsTrue(results.Contains(expected7)); Assert.IsTrue(results.Contains(expected8)); Assert.IsTrue(results.Contains(expected9)); }
public void GetLintFilesForProject() { string projectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj"); Project project = TsconfigLocationsTest.FindProject(projectFullName, solution); MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem() { Object = project }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem }; string[] results = LintFileLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap); Assert.AreEqual(1, results.Length); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts"); Assert.IsTrue(results.Contains(expected1)); }
public void GetLintFilesForSolutionIncludeNested() { MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem() { Object = solution }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem }; settings.IgnoreNestedFiles = false; try { List <string> results = LintFileLocations.FindPathsFromSelectedItems(selectedItems).ToList(); Assert.AreEqual(10, results.Count); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react-dom.d.ts"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react.d.ts"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts"); string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts"); string expected5 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts"); string expected6 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts"); string expected7 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts"); string expected8 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx"); string expected9 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/file7.ts"); string expected10 = Path.GetFullPath(@"../../artifacts/tsconfig/file9.ts"); // Linked file Assert.IsTrue(results.Contains(expected1)); Assert.IsTrue(results.Contains(expected2)); Assert.IsTrue(results.Contains(expected3)); Assert.IsTrue(results.Contains(expected4)); Assert.IsTrue(results.Contains(expected5)); Assert.IsTrue(results.Contains(expected6)); Assert.IsTrue(results.Contains(expected7)); Assert.IsTrue(results.Contains(expected8)); Assert.IsTrue(results.Contains(expected9)); Assert.IsTrue(results.Contains(expected10)); } finally { settings.IgnoreNestedFiles = true; } }
internal static async System.Threading.Tasks.Task <bool> LintLintLint(bool fixErrors, UIHierarchyItem[] selectedItems) { IEnumerable <string> files = WebLinterPackage.Settings.UseTsConfig ? TsconfigLocations.FindPathsFromSelectedItems(selectedItems) : LintFileLocations.FindPathsFromSelectedItems(selectedItems); if (files.Any()) { string[] filterFileNames = WebLinterPackage.Settings.UseTsConfig ? TsconfigLocations.FindFilterFiles(selectedItems) : null; return(await LinterService.Lint(showErrorList : true, fixErrors : fixErrors, callSync : false, fileNames : files.ToArray(), filterFileNames : filterFileNames)); } else { WebLinterPackage.Dte.StatusBar.Text = $"No {(WebLinterPackage.Settings.UseTsConfig ? "tsconfig.json" : "ts or tsx")} files found to {(fixErrors ? "fix" : "lint")}"; return(false); } }
internal static async System.Threading.Tasks.Task <bool> LintSelectedItems(bool fixErrors, UIHierarchyItem[] selectedItems) { Dictionary <string, string> fileToProjectMap; IEnumerable <string> files = WebLinterPackage.Settings.UseTsConfig ? TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap) : LintFileLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap); if (files.Any()) { bool clearAllErrors = AnyItemNotLintableSingleFile(selectedItems); return(await LinterService.Lint(showErrorList : true, fixErrors : fixErrors, callSync : false, fileNames : files.ToArray(), clearAllErrors, fileToProjectMap)); } else { WebLinterPackage.Dte.StatusBar.Text = $"No {(WebLinterPackage.Settings.UseTsConfig ? "tsconfig.json" : "ts or tsx")}" + $" files found to {(fixErrors ? "fix" : "lint")}"; return(false); } }
public void GetLintFilesForSingleItem() { string projectItemFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts"); string projectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project project = TsconfigLocationsTest.FindProject(projectFullName, solution); ProjectItem projectItem = TsconfigLocationsTest.FindProjectItemInProject(projectItemFullName, project); MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem() { Object = projectItem }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem }; List <string> results = LintFileLocations.FindPathsFromSelectedItems(selectedItems).ToList(); Assert.AreEqual(1, results.Count); Assert.AreEqual(projectItemFullName, results[0]); //string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts"); //Assert.IsTrue(results.Contains(expected1)); }