public void GetBuildFilesForSolution()
        {
            List <string> results = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: true,
                                                                           selectedItems: null, useTsConfig: false).ToList();

            // Should be the same as if we are linting the solution
            Assert.AreEqual(9, 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/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 GetTsconfigBuildFilesForSingleItem()
        {
            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 = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: false,
                                                                           selectedItems: selectedItems, useTsConfig: true).ToList();

            // Again we are going to build the project the item is in so should lint for all tsconfigs in the project
            Assert.AreEqual(3, results.Count);

            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.IsTrue(results.Contains(expected1));
            Assert.IsTrue(results.Contains(expected2));
            Assert.IsTrue(results.Contains(expected3));
        }
        public void GetTsconfigBuildFilesForSolution()
        {
            List <string> results = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: true,
                                                                           selectedItems: null, useTsConfig: true).ToList();

            // Should be the same as if we are linting the solution (see TsconfigLocationsTest.FindInSelectedItemsSolution)
            Assert.AreEqual(3, results.Count);

            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.IsTrue(results.Contains(expected1));
            Assert.IsTrue(results.Contains(expected2));
            Assert.IsTrue(results.Contains(expected3));
        }
        public void GetBuildFilesForProject()
        {
            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 };

            List <string> results = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: false,
                                                                           selectedItems: selectedItems, useTsConfig: false).ToList();

            Assert.AreEqual(1, results.Count);
            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");

            Assert.IsTrue(results.Contains(expected1));
        }
        public void GetBuildFilesForSingleItem()
        {
            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 = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: false,
                                                                           selectedItems: selectedItems, useTsConfig: false).ToList();

            // We're going to build the project that the individual file is in (tsconfigTest) and so need to lint
            // all the files in said project before the build.  Note NOT using tsconfig.json (useTsConfig: false above).
            Assert.AreEqual(8, 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/multiple/a/c/file6.tsx");
            string expected8 = 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));
        }
Example #6
0
 protected async System.Threading.Tasks.Task <bool> LintBuildSelection(bool isBuildingSolution)
 {
     try
     {
         if (!LinterService.IsLinterEnabled)
         {
             return(false);
         }
         UIHierarchyItem[]    selectedItems = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.SelectedItems as UIHierarchyItem[];
         IEnumerable <string> files         = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution, selectedItems,
                                                                                     WebLinterPackage.Settings.UseTsConfig);
         if (!files.Any())
         {
             return(false);
         }
         return(await LinterService.Lint(showErrorList : true, fixErrors : false, callSync : true, fileNames : files.ToArray()));
     }
     catch (Exception ex)
     {
         Logger.LogAndWarn(ex);
         Linter.Server.Down();
         return(false);
     }
 }