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 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]);
        }
Example #4
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 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 };

            Dictionary <string, string> fileToProjectMap;

            string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap);

            Assert.AreEqual(0, results.Length);
            Assert.AreEqual(0, fileToProjectMap.Keys.Count);
        }
        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 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);
        }