コード例 #1
0
        public static Func <TestSettings, TestSettings> RollForwardOnNoCandidateFxSetting(
            SettingLocation location,
            int?value,
            string frameworkReferenceName = MicrosoftNETCoreApp)
        {
            if (!value.HasValue || location == SettingLocation.None)
            {
                return(testSettings => testSettings);
            }

            switch (location)
            {
            case SettingLocation.Environment:
                return(testSettings => testSettings.WithEnvironment(Constants.RollForwardOnNoCandidateFxSetting.EnvironmentVariable, value.ToString()));

            case SettingLocation.CommandLine:
                return(testSettings => testSettings.WithCommandLine(Constants.RollForwardOnNoCandidateFxSetting.CommandLineArgument, value.ToString()));

            case SettingLocation.RuntimeOptions:
                return(testSettings => testSettings.WithRuntimeConfigCustomizer(rc => rc.WithRollForwardOnNoCandidateFx(value)));

            case SettingLocation.FrameworkReference:
                return(testSettings => testSettings.WithRuntimeConfigCustomizer(rc =>
                {
                    rc.GetFramework(frameworkReferenceName).WithRollForwardOnNoCandidateFx(value);
                    return rc;
                }));

            default:
                throw new Exception($"RollForwardOnNoCandidateFx doesn't support setting location {location}.");
            }
        }
コード例 #2
0
        public AnalyzerSetting(DiagnosticDescriptor descriptor,
                               ReportDiagnostic effectiveSeverity,
                               AnalyzerSettingsUpdater settingsUpdater,
                               Language language,
                               SettingLocation location)
        {
            _descriptor      = descriptor;
            _settingsUpdater = settingsUpdater;
            DiagnosticSeverity severity = default;

            if (effectiveSeverity == ReportDiagnostic.Default)
            {
                severity = descriptor.DefaultSeverity;
            }
            else if (effectiveSeverity.ToDiagnosticSeverity() is DiagnosticSeverity severity1)
            {
                severity = severity1;
            }

            var enabled = effectiveSeverity != ReportDiagnostic.Suppress;

            IsEnabled         = enabled;
            Severity          = severity;
            Language          = language;
            IsNotConfigurable = descriptor.CustomTags.Any(t => t == WellKnownDiagnosticTags.NotConfigurable);
            Location          = location;
        }
コード例 #3
0
 protected WhitespaceSetting(string description, OptionUpdater updater, SettingLocation location, string?language = null)
 {
     Description = description ?? throw new ArgumentNullException(nameof(description));
     Updater     = updater;
     Location    = location;
     Language    = language;
 }
        public void CollisionsInRuntimeConfig(
            SettingLocation rollForwardLocation,
            SettingLocation rollForwardOnNoCandidateFxLocation,
            SettingLocation applyPatchesLocation,
            bool passes)
        {
            CommandResult result = RunTest(
                new TestSettings()
                .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                             .WithFramework(MicrosoftNETCoreApp, "5.0.0"))
                .With(RollForwardSetting(rollForwardLocation, Constants.RollForwardSetting.Minor))
                .With(RollForwardOnNoCandidateFxSetting(rollForwardOnNoCandidateFxLocation, 1))
                .With(ApplyPatchesSetting(applyPatchesLocation, false)));

            if (passes)
            {
                result.ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3");
            }
            else
            {
                result.Should().Fail()
                .And.HaveStdErrContaining(
                    $"It's invalid to use both `{Constants.RollForwardSetting.RuntimeConfigPropertyName}` and one of " +
                    $"`{Constants.RollForwardOnNoCandidateFxSetting.RuntimeConfigPropertyName}` or " +
                    $"`{Constants.ApplyPatchesSetting.RuntimeConfigPropertyName}` in the same runtime config.");
            }
        }
コード例 #5
0
        private IEnumerable <AnalyzerSetting> GetSettings(AnalyzerReference analyzerReference, AnalyzerConfigOptions editorConfigOptions)
        {
            IEnumerable <DiagnosticAnalyzer> csharpAnalyzers      = analyzerReference.GetAnalyzers(LanguageNames.CSharp);
            IEnumerable <DiagnosticAnalyzer> visualBasicAnalyzers = analyzerReference.GetAnalyzers(LanguageNames.VisualBasic);
            var dotnetAnalyzers = csharpAnalyzers.Intersect(visualBasicAnalyzers, DiagnosticAnalyzerComparer.Instance);

            csharpAnalyzers      = csharpAnalyzers.Except(dotnetAnalyzers, DiagnosticAnalyzerComparer.Instance);
            visualBasicAnalyzers = visualBasicAnalyzers.Except(dotnetAnalyzers, DiagnosticAnalyzerComparer.Instance);

            var csharpSettings = ToAnalyzerSetting(csharpAnalyzers, Language.CSharp);
            var csharpAndVisualBasicSettings = csharpSettings.Concat(ToAnalyzerSetting(visualBasicAnalyzers, Language.VisualBasic));

            return(csharpAndVisualBasicSettings.Concat(ToAnalyzerSetting(dotnetAnalyzers, Language.CSharp | Language.VisualBasic)));

            IEnumerable <AnalyzerSetting> ToAnalyzerSetting(IEnumerable <DiagnosticAnalyzer> analyzers,
                                                            Language language)
            {
                return(analyzers
                       .SelectMany(a => _analyzerService.AnalyzerInfoCache.GetDiagnosticDescriptors(a))
                       .GroupBy(d => d.Id)
                       .OrderBy(g => g.Key, StringComparer.CurrentCulture)
                       .Select(g =>
                {
                    var selectedDiagnostic = g.First();
                    var isEditorconfig = selectedDiagnostic.IsDefinedInEditorConfig(editorConfigOptions);
                    var settingLocation = new SettingLocation(isEditorconfig ? LocationKind.EditorConfig : LocationKind.VisualStudio, FileName);
                    var severity = selectedDiagnostic.GetEffectiveSeverity(editorConfigOptions);
                    return new AnalyzerSetting(selectedDiagnostic, severity, SettingsUpdater, language, settingLocation);
                }));
            }
        }
 private static string?GetLocationString(SettingLocation location)
 {
     return(location.LocationKind switch
     {
         LocationKind.EditorConfig or LocationKind.GlobalConfig => location.Path,
         _ => ServicesVSResources.Analyzer_Defaults
     });
コード例 #7
0
 private static string?GetLocationString(SettingLocation location)
 {
     return(location.LocationKind switch
     {
         LocationKind.EditorConfig or LocationKind.GlobalConfig => location.Path,
         _ => ServicesVSResources.Visual_Studio_Settings
     });
コード例 #8
0
        public static Func <TestSettings, TestSettings> ApplyPatchesSetting(
            SettingLocation location,
            bool?value,
            string frameworkReferenceName = MicrosoftNETCoreApp)
        {
            if (!value.HasValue || location == SettingLocation.None)
            {
                return(testSettings => testSettings);
            }

            switch (location)
            {
            case SettingLocation.RuntimeOptions:
                return(testSettings => testSettings.WithRuntimeConfigCustomizer(rc => rc.WithApplyPatches(value)));

            case SettingLocation.FrameworkReference:
                return(testSettings => testSettings.WithRuntimeConfigCustomizer(rc =>
                {
                    rc.GetFramework(frameworkReferenceName).WithApplyPatches(value);
                    return rc;
                }));

            default:
                throw new Exception($"ApplyPatches doesn't support setting location {location}.");
            }
        }
コード例 #9
0
            public override void ChangeValue(int valueIndex)
            {
                ICodeStyleOption option = GetOption();

                Location = Location with {
                    LocationKind = LocationKind.EditorConfig
                };
                Updater.QueueUpdate(_option, option.WithValue(_enumValues[valueIndex]));
            }
コード例 #10
0
            protected override void ChangeSeverity(NotificationOption2 severity)
            {
                ICodeStyleOption option = GetOption();

                Location = Location with {
                    LocationKind = LocationKind.EditorConfig
                };
                Updater.QueueUpdate(_option, option.WithNotification(severity));
            }
コード例 #11
0
 public void NoInheritance(SettingLocation settingLocation)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MiddleWare, "2.1.2"))
         .With(ApplyPatchesSetting(settingLocation, false, MiddleWare)))
     .ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3");
 }
コード例 #12
0
 public void AllLocations(SettingLocation location)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardSetting(location, Constants.RollForwardSetting.Major)))
     .ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3");
 }
コード例 #13
0
 public void AllLocations(SettingLocation location)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MicrosoftNETCoreApp, "5.1.2"))
         .With(ApplyPatchesSetting(location, false)))
     .ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.2");
 }
コード例 #14
0
 public void RuntimeOptionsPriority(SettingLocation settingLocation, bool runtimeOptionWins)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithRollForwardOnNoCandidateFx(2)
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 0)))
     .ShouldHaveResolvedFrameworkOrFailToFind(MicrosoftNETCoreApp, runtimeOptionWins ? "5.1.3" : null);
 }
コード例 #15
0
 public void CommandLinePriority(SettingLocation settingLocation, bool commandLineWins)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 0))
         .WithCommandLine(Constants.RollForwardOnNoCandidateFxSetting.CommandLineArgument, "2"))
     .ShouldHaveResolvedFrameworkOrFailToFind(MicrosoftNETCoreApp, commandLineWins ? "5.1.3" : null);
 }
コード例 #16
0
 public void EnvironmentPriority(SettingLocation settingLocation, bool envVariableWins)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 0))
         .WithEnvironment(Constants.RollForwardOnNoCandidateFxSetting.EnvironmentVariable, "2"))
     .ShouldHaveResolvedFrameworkOrFailToFind(MicrosoftNETCoreApp, envVariableWins ? "5.1.3" : null);
 }
コード例 #17
0
 public void CommandLinePriority(SettingLocation settingLocation, string resolvedFramework)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 0))
         .WithCommandLine(Constants.RollForwardOnNoCandidateFxSetting.CommandLineArgument, "2"),
         resolvedFramework: resolvedFramework);
 }
コード例 #18
0
 public void InvalidValue(SettingLocation settingLocation)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardSetting(settingLocation, "InvalidValue")))
     .Should().Fail()
     .And.DidNotRecognizeRollForwardValue("InvalidValue");
 }
コード例 #19
0
 public void EnvironmentPriority(SettingLocation settingLocation, string resolvedFramework)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 0))
         .WithEnvironment(Constants.RollForwardOnNoCandidateFxSetting.EnvironmentVariable, "2"),
         resolvedFramework: resolvedFramework);
 }
コード例 #20
0
 public void RuntimeConfigPriority(SettingLocation settingLocation, string resolvedFramework)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithRollForwardOnNoCandidateFx(2)
                                      .WithFramework(MicrosoftNETCoreApp, "4.0.0"))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 0)),
         resolvedFramework: resolvedFramework);
 }
コード例 #21
0
 public void NoInheritance_MoreRelaxed(SettingLocation settingLocation, bool appWins)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(MiddleWare, "1.0.0"))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 2, MiddleWare))
         .WithDotnetCustomizer(dotnetCustomizer => dotnetCustomizer
                               .Framework(MiddleWare).RuntimeConfig(runtimeConfig => runtimeConfig
                                                                    .GetFramework(MicrosoftNETCoreApp).Version = "4.0.0")))
     .ShouldHaveResolvedFrameworkOrFailToFind(MicrosoftNETCoreApp, appWins ? "5.1.3" : null);
 }
コード例 #22
0
 public void NoInheritance_MoreRestrictive(SettingLocation settingLocation, bool appWins)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(new RuntimeConfig.Framework(MiddleWare, "2.1.2")))
         .With(RollForwardSetting(settingLocation, Constants.RollForwardSetting.LatestPatch, MiddleWare))
         .WithDotnetCustomizer(dotnetCustomizer => dotnetCustomizer
                               .Framework(MiddleWare).RuntimeConfig(runtimeConfig => runtimeConfig
                                                                    .GetFramework(MicrosoftNETCoreApp).Version = "5.0.0")))
     .ShouldHaveResolvedFrameworkOrFailToFind(MicrosoftNETCoreApp, appWins ? null : "5.1.3");
 }
コード例 #23
0
 [InlineData(SettingLocation.Environment, null)]           // Since none is specified for the inner reference, environment is used
 public void NoInheritance_MoreRestrictive(SettingLocation settingLocation, string resolvedFramework)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(new RuntimeConfig.Framework(MiddleWare, "2.1.2")))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 0, MiddleWare)),
         dotnetCustomizer => dotnetCustomizer.Framework(MiddleWare).RuntimeConfig(runtimeConfig =>
                                                                                  runtimeConfig
                                                                                  .GetFramework(MicrosoftNETCoreApp).Version = "5.0.0"),
         resolvedFramework);
 }
コード例 #24
0
 public PerLanguageWhitespaceSetting(PerLanguageOption2 <T> option,
                                     string description,
                                     AnalyzerConfigOptions editorConfigOptions,
                                     OptionSet visualStudioOptions,
                                     OptionUpdater updater,
                                     SettingLocation location)
     : base(description, updater, location)
 {
     _option = option;
     _editorConfigOptions = editorConfigOptions;
     _visualStudioOptions = visualStudioOptions;
 }
コード例 #25
0
 public void InnerFrameworkReference(SettingLocation settingLocation, bool innerReferenceWins)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(new RuntimeConfig.Framework(MiddleWare, "2.1.0")))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 1, MiddleWare))
         .WithDotnetCustomizer(dotnetCustomizer => dotnetCustomizer
                               .Framework(MiddleWare).RuntimeConfig(runtimeConfig => runtimeConfig
                                                                    .WithRollForwardOnNoCandidateFx(2)
                                                                    .GetFramework(MicrosoftNETCoreApp).Version = "4.0.0")))
     .ShouldHaveResolvedFrameworkOrFailToFind(MicrosoftNETCoreApp, innerReferenceWins ? "5.1.3" : null);
 }
コード例 #26
0
        public static WhitespaceSetting <TOption> Create <TOption>(Option2 <TOption> option,
                                                                   string description,
                                                                   AnalyzerConfigOptions editorConfigOptions,
                                                                   OptionSet visualStudioOptions,
                                                                   OptionUpdater updater,
                                                                   string fileName)
            where TOption : struct
        {
            var isDefinedInEditorConfig = editorConfigOptions.TryGetEditorConfigOption <TOption>(option, out _);
            var location = new SettingLocation(isDefinedInEditorConfig ? LocationKind.EditorConfig : LocationKind.VisualStudio, fileName);

            return(new WhitespaceSetting <TOption>(option, description, editorConfigOptions, visualStudioOptions, updater, location));
        }
コード例 #27
0
 public void InnerFrameworkReference(SettingLocation settingLocation, string resolvedFramework)
 {
     RunTest(
         new TestSettings()
         .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                      .WithFramework(new RuntimeConfig.Framework(MiddleWare, "2.1.0")))
         .With(RollForwardOnNoCandidateFxSetting(settingLocation, 1, MiddleWare)),
         dotnetCustomizer => dotnetCustomizer.Framework(MiddleWare).RuntimeConfig(runtimeConfig =>
                                                                                  runtimeConfig
                                                                                  .WithRollForwardOnNoCandidateFx(2)
                                                                                  .GetFramework(MicrosoftNETCoreApp).Version = "4.0.0"),
         resolvedFramework);
 }
コード例 #28
0
 public EnumCodeStyleSetting(Option2 <CodeStyleOption2 <T> > option,
                             string description,
                             T[] enumValues,
                             string[] valueDescriptions,
                             AnalyzerConfigOptions editorConfigOptions,
                             OptionSet visualStudioOptions,
                             OptionUpdater updater,
                             string fileName)
     : base(description, enumValues, valueDescriptions, option.Group.Description, updater)
 {
     _option = option;
     _editorConfigOptions = editorConfigOptions;
     _visualStudioOptions = visualStudioOptions;
     Location             = new SettingLocation(IsDefinedInEditorConfig ? LocationKind.EditorConfig : LocationKind.VisualStudio, fileName);
 }
コード例 #29
0
 public BooleanCodeStyleSetting(Option2 <CodeStyleOption2 <bool> > option,
                                string description,
                                string?trueValueDescription,
                                string?falseValueDescription,
                                AnalyzerConfigOptions editorConfigOptions,
                                OptionSet visualStudioOptions,
                                OptionUpdater updater,
                                string fileName)
     : base(description, option.Group.Description, trueValueDescription, falseValueDescription, updater)
 {
     _option = option;
     _editorConfigOptions = editorConfigOptions;
     _visualStudioOptions = visualStudioOptions;
     Location             = new SettingLocation(IsDefinedInEditorConfig ? LocationKind.EditorConfig : LocationKind.VisualStudio, fileName);
 }
コード例 #30
0
        private void ValidateValueIgnoresCase(SettingLocation settingLocation, string rollForward)
        {
            string[] values = new string[]
            {
                rollForward,
                rollForward.ToLowerInvariant(),
                rollForward.ToUpperInvariant()
            };

            foreach (string value in values)
            {
                RunTest(
                    new TestSettings()
                    .WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
                                                 .WithFramework(MicrosoftNETCoreApp, "5.1.3"))
                    .With(RollForwardSetting(settingLocation, value)))
                .Should().Pass()
                .And.HaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3");
            }
        }