public void FindInSelectedItemsSingleFile() { // Arrange string mainProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project mainProject = FindProject(mainProjectFullName, solution); string mainFile4FullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts"); ProjectItem file4 = FindProjectItemInProject(mainFile4FullName, mainProject); MockUIHierarchyItem mockFile4HierarchyItem = new MockUIHierarchyItem() { Object = file4 }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockFile4HierarchyItem }; // Act string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap); // Assert string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); Assert.AreEqual(1, results.Length); Assert.IsTrue(results.Contains(expected)); Assert.AreEqual(1, fileToProjectMap.Keys.Count); Assert.AreEqual("tsconfigTest", fileToProjectMap[mainFile4FullName]); }
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 FindForSingleItemNotsconfig() { // Note there's a tsconfig.json in the folder, but it's not in the project: it shouldn't be picked up string projectItemFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file2.ts"); string result = TsconfigLocations.FindParentTsconfig(projectItemFullName); Assert.IsNull(result); }
public void FindForSingleItemSubfolder() { string projectItemFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts"); Tsconfig result = TsconfigLocations.FindFromProjectItem(projectItemFullName); string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); Assert.AreEqual(expected, result.FullName); }
public void FindForSingleItemRoot() { string projectItemFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts"); string result = TsconfigLocations.FindParentTsconfig(projectItemFullName); string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); Assert.AreEqual(expected, result); }
public void FindInProjectNotsconfig() { string projectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj"); Project project = FindProject(projectFullName, solution); Tsconfig[] results = TsconfigLocations.FindInProject(project).ToArray(); Assert.IsNotNull(results); Assert.AreEqual(0, results.Length); }
public void FindInSolution() { Tsconfig[] results = TsconfigLocations.FindInSolution(solution).ToArray(); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(3, results.Length); Assert.IsTrue(Contains(results, expected1)); Assert.IsTrue(Contains(results, expected2)); Assert.IsTrue(Contains(results, expected3)); }
public void FindInProjectNotsconfig() { // Folder b contains a tsconfig on disk that's not included in the VS project // Folder c contains a tsconfig in the VS project (tsconfigEmptyTest.csproj) that doesn't exist on disk // In both cases we don't lint with these string projectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj"); Project project = FindProject(projectFullName, solution); HashSet <string> results = new HashSet <string>(StringComparer.OrdinalIgnoreCase); TsconfigLocations.FindTsconfigsInProject(project, results); Assert.IsNotNull(results); Assert.AreEqual(0, results.Count); }
public void FindInSolution() { HashSet <string> results = new HashSet <string>(StringComparer.OrdinalIgnoreCase); TsconfigLocations.FindTsconfigsInSolution(solution, results); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(3, results.Count); Assert.IsTrue(results.Contains(expected1)); Assert.IsTrue(results.Contains(expected2)); Assert.IsTrue(results.Contains(expected3)); }
public void FindInSelectedItemsMultipleFiles() { // Includes two files with the same tsconfig.json and one with none string mainProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project mainProject = FindProject(mainProjectFullName, solution); string emptyProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj"); Project emptyProject = FindProject(emptyProjectFullName, solution); string mainFile4FullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts"); ProjectItem file4 = FindProjectItemInProject(mainFile4FullName, mainProject); MockUIHierarchyItem mockFile4HierarchyItem = new MockUIHierarchyItem() { Object = file4 }; string emptyFile2FullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file2.ts"); ProjectItem file2 = FindProjectItemInProject(emptyFile2FullName, emptyProject); MockUIHierarchyItem mockFile2HierarchyItem = new MockUIHierarchyItem() { Object = file2 }; string mainFile1FullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts"); ProjectItem file1 = FindProjectItemInProject(mainFile1FullName, mainProject); MockUIHierarchyItem mockFile1HierarchyItem = new MockUIHierarchyItem() { Object = file1 }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockFile1HierarchyItem, mockFile2HierarchyItem, mockFile4HierarchyItem }; string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap); string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); Assert.AreEqual(1, results.Length); Assert.IsTrue(results.Contains(expected)); // We create the fileToProjectMap for single selected files only, which is what we have here Assert.AreEqual(2, fileToProjectMap.Keys.Count); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts"); Assert.AreEqual("tsconfigTest", fileToProjectMap[expected1]); Assert.AreEqual("tsconfigTest", fileToProjectMap[expected2]); }
public void FindInProject() { string projectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project project = FindProject(projectFullName, solution); Tsconfig[] results = TsconfigLocations.FindInProject(project).ToArray(); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(3, results.Length); Assert.IsTrue(Contains(results, expected1)); Assert.IsTrue(Contains(results, expected2)); Assert.IsTrue(Contains(results, expected3)); }
public void FindInProject() { string projectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project project = FindProject(projectFullName, solution); HashSet <string> results = new HashSet <string>(StringComparer.OrdinalIgnoreCase); TsconfigLocations.FindTsconfigsInProject(project, results); string expectedConfig1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expectedConfig2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expectedConfig3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(3, results.Count); Assert.IsTrue(results.Contains(expectedConfig1)); Assert.IsTrue(results.Contains(expectedConfig2)); Assert.IsTrue(results.Contains(expectedConfig3)); }
public void FindInSelectedItemsNoTsconfig() { string emptyProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj"); Project emptyProject = FindProject(emptyProjectFullName, solution); string emptyFile2FullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file2.ts"); ProjectItem file2 = FindProjectItemInProject(emptyFile2FullName, emptyProject); MockUIHierarchyItem mockFile2HierarchyItem = new MockUIHierarchyItem() { Object = file2 }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockFile2HierarchyItem }; Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray(); Assert.AreEqual(0, results.Length); }
private static async Task CallLinterService(string filePath) { if (WebLinterPackage.Settings.UseTsConfig) { Tsconfig tsconfig = TsconfigLocations.FindFromProjectItem(filePath); if (tsconfig == null) { return; } await LinterService.Lint(false, false, false, new string[] { tsconfig.FullName }, new string[] { filePath }); } else { await LinterService.Lint(false, false, false, new string[] { filePath }); } }
public void FindInSolutionIgnorePath() { settings.IgnorePatterns = new string[] { @"\multiple\a\" }; try { Tsconfig[] results = TsconfigLocations.FindInSolution(solution).ToArray(); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(2, results.Length); Assert.IsTrue(Contains(results, expected1)); Assert.IsFalse(Contains(results, expected2)); // IsFalse test: the file has been excluded Assert.IsTrue(Contains(results, expected3)); } finally { settings.IgnorePatterns = new string[0]; } }
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); } }
public void FindInSelectedItemsMultipleFiles() { // Includes two files with the same tsconfig.json and one with none string mainProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project mainProject = FindProject(mainProjectFullName, solution); string emptyProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj"); Project emptyProject = FindProject(emptyProjectFullName, solution); string mainFile4FullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts"); ProjectItem file4 = FindProjectItemInProject(mainFile4FullName, mainProject); MockUIHierarchyItem mockFile4HierarchyItem = new MockUIHierarchyItem() { Object = file4 }; string emptyFile2FullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file2.ts"); ProjectItem file2 = FindProjectItemInProject(emptyFile2FullName, emptyProject); MockUIHierarchyItem mockFile2HierarchyItem = new MockUIHierarchyItem() { Object = file2 }; string mainFile1FullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts"); ProjectItem file1 = FindProjectItemInProject(mainFile1FullName, mainProject); MockUIHierarchyItem mockFile1HierarchyItem = new MockUIHierarchyItem() { Object = file1 }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockFile1HierarchyItem, mockFile2HierarchyItem, mockFile4HierarchyItem }; Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray(); string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); Assert.AreEqual(1, results.Length); Assert.IsTrue(Contains(results, expected)); }
public void FindInSelectedItemsTsconfig() { string mainProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project mainProject = FindProject(mainProjectFullName, solution); string mainProjectTsconfigFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); ProjectItem tsconfig = FindProjectItemInProject(mainProjectTsconfigFullName, mainProject); MockUIHierarchyItem mockTsconfigHierarchyItem = new MockUIHierarchyItem() { Object = tsconfig }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockTsconfigHierarchyItem }; Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray(); string expected = mainProjectTsconfigFullName; Assert.AreEqual(1, results.Length); Assert.IsTrue(Contains(results, expected)); }
public void FindInSolutionIgnorePath() { settings.IgnorePatterns = new string[] { @"\multiple\a\" }; try { HashSet <string> results = new HashSet <string>(StringComparer.OrdinalIgnoreCase); TsconfigLocations.FindTsconfigsInSolution(solution, results); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(2, results.Count); Assert.IsTrue(results.Contains(expected1)); Assert.IsFalse(results.Contains(expected2)); // IsFalse test: the file has been excluded Assert.IsTrue(results.Contains(expected3)); } finally { settings.IgnorePatterns = new string[0]; } }
public void FindInSelectedItemsSolution() { MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem() { Object = solution }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem }; Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray(); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(3, results.Length); Assert.IsTrue(Contains(results, expected1)); Assert.IsTrue(Contains(results, expected2)); Assert.IsTrue(Contains(results, expected3)); }
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); } }
private static async Task LintFile(string filePath) { Benchmark.Start(); Benchmark.Log("In SourceFileCreationListener.LintFile, path=" + filePath); if (WebLinterPackage.Settings.UseTsConfig) { string tsconfig = TsconfigLocations.FindParentTsconfig(filePath); if (tsconfig == null) { return; } await LinterService.Lint(false, false, false, new string[] { tsconfig }, clearAllErrors : false, CreateFileToProjectMap(filePath)); } else { await LinterService.Lint(false, false, false, new string[] { filePath }, clearAllErrors : false, CreateFileToProjectMap(filePath)); } Benchmark.End(); }
public void FindInSelectedItemsSolution() { MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem() { Object = solution }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem }; string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap); string expectedConfig1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expectedConfig2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expectedConfig3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); Assert.AreEqual(3, results.Length); Assert.IsTrue(results.Contains(expectedConfig1)); Assert.IsTrue(results.Contains(expectedConfig2)); Assert.IsTrue(results.Contains(expectedConfig3)); Assert.AreEqual(0, fileToProjectMap.Keys.Count); }
public void FindInSelectedItemsTsconfig() { string mainProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj"); Project mainProject = FindProject(mainProjectFullName, solution); string mainProjectTsconfigFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); ProjectItem tsconfig = FindProjectItemInProject(mainProjectTsconfigFullName, mainProject); MockUIHierarchyItem mockTsconfigHierarchyItem = new MockUIHierarchyItem() { Object = tsconfig }; UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockTsconfigHierarchyItem }; string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap); string expected = mainProjectTsconfigFullName; Assert.AreEqual(1, results.Length); Assert.IsTrue(results.Contains(expected)); Assert.AreEqual(0, fileToProjectMap.Keys.Count); }
public void FindInSolutionIncludeNested() { settings.IgnoreNestedFiles = false; try { Tsconfig[] results = TsconfigLocations.FindInSolution(solution).ToArray(); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); // Nested tsconfig in tsconfigEmptyTest string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfig.json"); // C:\Source\typescript-analyzer2\src\WebLinterTest\artifacts\tsconfig\none\tsconfig.json Assert.AreEqual(4, results.Length); Assert.IsTrue(Contains(results, expected1)); Assert.IsTrue(Contains(results, expected2)); Assert.IsTrue(Contains(results, expected3)); Assert.IsTrue(Contains(results, expected4)); } finally { settings.IgnoreNestedFiles = true; } }
public void FindInSolutionIncludeNested() { settings.IgnoreNestedFiles = false; try { HashSet <string> results = new HashSet <string>(StringComparer.OrdinalIgnoreCase); TsconfigLocations.FindTsconfigsInSolution(solution, results); string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json"); string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json"); string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json"); // Nested tsconfig in tsconfigEmptyTest string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfig.json"); // C:\Source\typescript-analyzer\src\WebLinterTest\artifacts\tsconfig\none\tsconfig.json Assert.AreEqual(4, results.Count); Assert.IsTrue(results.Contains(expected1)); Assert.IsTrue(results.Contains(expected2)); Assert.IsTrue(results.Contains(expected3)); Assert.IsTrue(results.Contains(expected4)); } finally { settings.IgnoreNestedFiles = true; } }