Пример #1
0
        public void AllRules_SonarWayTagPresenceMatchesIsEnabledByDefault()
        {
            var allAnalyzers = new RuleFinder().AllAnalyzerTypes
                               .Select(type => (DiagnosticAnalyzer)Activator.CreateInstance(type))
                               .SelectMany(analyzer => analyzer.SupportedDiagnostics)
                               .ToList();

            var parameterizedAnalyzers = new RuleFinder().AllAnalyzerTypes
                                         .Where(RuleFinder.IsParameterized)
                                         .Select(type => (DiagnosticAnalyzer)Activator.CreateInstance(type))
                                         .SelectMany(analyzer => analyzer.SupportedDiagnostics)
                                         .ToHashSet();

            foreach (var analyzer in allAnalyzers)
            {
                var isInSonarWay = analyzer.CustomTags.Contains(DiagnosticDescriptorBuilder.SonarWayTag);

                if (parameterizedAnalyzers.Contains(analyzer))
                {
                    analyzer.IsEnabledByDefault.Should().BeFalse();
                }
                else if (isInSonarWay)
                {
                    analyzer.IsEnabledByDefault.Should().BeTrue();
                }
                else
                {
                    analyzer.IsEnabledByDefault.Should().BeFalse();
                }
            }
        }
Пример #2
0
        public void AllRules_SonarWayTagPresenceMatchesIsEnabledByDefault()
        {
            var allAnalyzers = new RuleFinder().AllAnalyzerTypes
                               .Select(type => (DiagnosticAnalyzer)Activator.CreateInstance(type))
                               .SelectMany(analyzer => analyzer.SupportedDiagnostics)
                               .ToList();

            var parameterizedAnalyzers = new RuleFinder().AllAnalyzerTypes
                                         .Where(RuleFinder.IsParameterized)
                                         .Select(type => (DiagnosticAnalyzer)Activator.CreateInstance(type))
                                         .SelectMany(analyzer => analyzer.SupportedDiagnostics)
                                         .ToHashSet();

            foreach (var analyzer in allAnalyzers)
            {
                var isInSonarWay = analyzer.CustomTags.Contains(DiagnosticDescriptorBuilder.SonarWayTag);

                if (IsSecurityHotspot(analyzer))
                {
                    // Security hotspots are enabled by default, but they will report issues only
                    // when their ID is contained in SonarLint.xml
                    analyzer.IsEnabledByDefault.Should().BeTrue($"{analyzer.Id} should be enabled by default");
                }
                else if (parameterizedAnalyzers.Contains(analyzer))
                {
                    // Even if a a parametrized rule is in Sonar way profile, it is still disabled by default.
                    // See https://github.com/SonarSource/sonar-dotnet/issues/1274
                    analyzer.IsEnabledByDefault.Should().BeFalse($"{analyzer.Id} has parameters and should be disabled by default");
                }
                else if (isInSonarWay)
                {
                    analyzer.IsEnabledByDefault.Should().BeTrue($"{analyzer.Id} is in SonarWay");
                }
                else
                {
                    analyzer.IsEnabledByDefault.Should().BeFalse($"{analyzer.Id} is not in SonarWay");
                }
            }
        }
Пример #3
0
        public void AllRules_SonarWayTagPresenceMatchesIsEnabledByDefault()
        {
            var parameterized = new RuleFinder().AllAnalyzerTypes
                                .Where(RuleFinder.IsParameterized)
                                .SelectMany(type => ((DiagnosticAnalyzer)Activator.CreateInstance(type)).SupportedDiagnostics)
                                .ToHashSet();

            foreach (var diagnostic in new RuleFinder().AllAnalyzerTypes.SelectMany(SupportedDiagnostics))
            {
                if (IsSecurityHotspot(diagnostic))
                {
                    // Security hotspots are enabled by default, but they will report issues only when their ID is contained in SonarLint.xml
                    // Rule activation is done in DiagnosticDescriptorBuilder.WithNotConfigurable() to prevent rule supression and deactivation.
                    diagnostic.IsEnabledByDefault.Should().BeTrue($"{diagnostic.Id} should be enabled by default");
                }
                else if (IsDeprecated(diagnostic))
                {
                    // Deprecated rules should be removed from SonarWay
                    diagnostic.IsEnabledByDefault.Should().BeFalse($"{diagnostic.Id} is deprecated and should be disabled by default (removed from SonarWay)");
                }
                else if (parameterized.Contains(diagnostic))
                {
                    // Even if a a parametrized rule is in Sonar way profile, it is still disabled by default.
                    // See https://github.com/SonarSource/sonar-dotnet/issues/1274
                    diagnostic.IsEnabledByDefault.Should().BeFalse($"{diagnostic.Id} has parameters and should be disabled by default");
                }
                else if (IsSonarWay(diagnostic))
                {
                    diagnostic.IsEnabledByDefault.Should().BeTrue($"{diagnostic.Id} is in SonarWay");
                }
                else
                {
                    diagnostic.IsEnabledByDefault.Should().BeFalse($"{diagnostic.Id} is not in SonarWay");
                }
            }
        }