public async Task LintSolutionUseTsconfigs()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            MockErrorsTableDataSource mockErrorsTableDataSource = new MockErrorsTableDataSource();

            TableDataSource.InjectMockErrorsTableDataSource(mockErrorsTableDataSource);

            settings.UseTsConfig = true;

            try
            {
                bool hasVSErrors = await LintFilesCommandBase.LintLintLint(false, selectedItems);

                Assert.IsFalse(hasVSErrors);
                Assert.IsTrue(mockErrorsTableDataSource.HasErrors());
                Assert.AreEqual(7, mockErrorsTableDataSource.Snapshots.Count);

                // Note file5 is referenced by a tsconfig that isn't in the project, so doesn't get included
                string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
                string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file2.ts");
                string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts");
                string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
                //string expected5 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");
                string expected6 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx");
                string expected7 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/file7.ts");
                string expected8 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts");

                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected1));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected2));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected3));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected4));
                //Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected5));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected6));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected7));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected8));

                // Similar to TslintWithTsconfigTest.LintAll, again this level of detail may be too much
                Assert.AreEqual(3, mockErrorsTableDataSource.Snapshots[expected1].Count());
                Assert.AreEqual(4, mockErrorsTableDataSource.Snapshots[expected2].Count());
                Assert.AreEqual(3, mockErrorsTableDataSource.Snapshots[expected3].Count());
                Assert.AreEqual(3, mockErrorsTableDataSource.Snapshots[expected4].Count());
                //Assert.AreEqual(4, mockErrorsTableDataSource.Snapshots[expected5].Count());
                Assert.AreEqual(11, mockErrorsTableDataSource.Snapshots[expected6].Count());
                Assert.AreEqual(4, mockErrorsTableDataSource.Snapshots[expected7].Count());
                Assert.AreEqual(5, mockErrorsTableDataSource.Snapshots[expected8].Count());
            }
            finally
            {
                TableDataSource.InjectMockErrorsTableDataSource(null);
                settings.UseTsConfig = false;
            }
        }
Ejemplo n.º 2
0
        protected UIHierarchyItem[] Arrange(string solutionPath)
        {
            Initialize(solutionPath);
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            selectedItems             = new UIHierarchyItem[] { mockSolutionHierarchyItem };
            mockErrorsTableDataSource = new MockErrorsTableDataSource();
            TableDataSource.InjectMockErrorsTableDataSource(mockErrorsTableDataSource);
            return(selectedItems);
        }
        public async Task LintSolution()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            // TODO Don't like that singleton much, or my workaround to test:
            // any reason it can't be instantiated at startup and cached on the package?
            MockErrorsTableDataSource mockErrorsTableDataSource = new MockErrorsTableDataSource();

            TableDataSource.InjectMockErrorsTableDataSource(mockErrorsTableDataSource);

            settings.UseTsConfig       = false;
            settings.IgnoreNestedFiles = false;

            try
            {
                bool hasVSErrors = await LintFilesCommandBase.LintLintLint(false, selectedItems);

                Assert.IsFalse(hasVSErrors);
                Assert.IsTrue(mockErrorsTableDataSource.HasErrors());
                Assert.AreEqual(10, mockErrorsTableDataSource.Snapshots.Count);

                // See LintFileLocationsTest.GetLintFilesForSolutionIncludeNested
                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(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected1));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected2));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected3));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected4));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected5));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected6));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected7));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected8));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected9));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected10));

                // May be too painful when we upgrade tslint: I think since the tslint.json is fixed it should be OK though
                // 2017-08-30: tslint 5.7.0 changed no-namespace rule to 'ignore global augmentation', reduced 293->292 below
                // 2017-10-30: tslint 5.8.0 no-empty-interface now disregards interfaces with generic types #3260, reduced 292 -> 283 below
                Assert.AreEqual(8, mockErrorsTableDataSource.Snapshots[expected1].Count());
                Assert.AreEqual(283, mockErrorsTableDataSource.Snapshots[expected2].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected3].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected4].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected5].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected6].Count());
                Assert.AreEqual(3, mockErrorsTableDataSource.Snapshots[expected7].Count());
                Assert.AreEqual(9, mockErrorsTableDataSource.Snapshots[expected8].Count());
                Assert.AreEqual(3, mockErrorsTableDataSource.Snapshots[expected9].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected10].Count());

                // Pick an error and check we are generating all details - expected4 is file1.ts
                LintingError lintingError = mockErrorsTableDataSource.Snapshots[expected4].First(le => le.ErrorCode == "no-empty");
                Assert.AreEqual(expected4, lintingError.FileName);
                Assert.AreEqual("block is empty", lintingError.Message);
                Assert.AreEqual(2, lintingError.LineNumber);
                Assert.AreEqual(17, lintingError.ColumnNumber);
                Assert.AreEqual("https://palantir.github.io/tslint/rules/no-empty", lintingError.HelpLink);
                Assert.IsFalse(lintingError.IsError);
            }
            finally
            {
                TableDataSource.InjectMockErrorsTableDataSource(null);
                settings.UseTsConfig       = false;
                settings.IgnoreNestedFiles = true;
            }
        }