Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RS0046: Avoid Opt suffix in nullable-enabled code #3352

Merged
merged 20 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
RS0040 | RoslynDiagnosticsReliability | Warning | DefaultableTypeShouldHaveDefaultableFieldsAnalyzer
RS0042 | RoslynDiagnosticsDesign | Disabled | AvoidOptSuffixForNullableEnableCode

### Changed Rules
Rule ID | New Category | New Severity | Old Category | Old Severity | Notes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using System.Linq;
using Analyzer.Utilities;
using Analyzer.Utilities.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Roslyn.Diagnostics.Analyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class AvoidOptSuffixForNullableEnableCode : DiagnosticAnalyzer
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(RoslynDiagnosticsAnalyzersResources.AvoidOptSuffixForNullableEnableCodeRuleIdTitle), RoslynDiagnosticsAnalyzersResources.ResourceManager, typeof(RoslynDiagnosticsAnalyzersResources));

private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(RoslynDiagnosticsAnalyzersResources.AvoidOptSuffixForNullableEnableCodeRuleIdMessage), RoslynDiagnosticsAnalyzersResources.ResourceManager, typeof(RoslynDiagnosticsAnalyzersResources));
private static readonly LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(RoslynDiagnosticsAnalyzersResources.AvoidOptSuffixForNullableEnableCodeRuleIdDescription), RoslynDiagnosticsAnalyzersResources.ResourceManager, typeof(RoslynDiagnosticsAnalyzersResources));

internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(
RoslynDiagnosticIds.AvoidOptSuffixForNullableEnableCodeRuleId,
s_localizableTitle,
s_localizableMessage,
DiagnosticCategory.RoslynDiagnosticsDesign,
DiagnosticSeverity.Warning,
isEnabledByDefault: false,
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
description: s_localizableDescription,
helpLinkUri: null,
customTags: WellKnownDiagnosticTags.Telemetry);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

public sealed override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);

context.RegisterSymbolAction(context =>
{
if (context.Symbol.Name.EndsWith("Opt", System.StringComparison.Ordinal) &&
context.Symbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is { } node &&
context.Compilation.GetSemanticModel(node.SyntaxTree).GetNullableContext(node.SpanStart).AnnotationsEnabled())
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
{
context.ReportDiagnostic(context.Symbol.CreateDiagnostic(Rule));
}
}, SymbolKind.Parameter, SymbolKind.Field);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ internal static class RoslynDiagnosticIds
public const string RelaxTestNamingSuppressionRuleId = "RS0039";
public const string DefaultableTypeShouldHaveDefaultableFieldsRuleId = "RS0040";
public const string ObliviousPublicApiRuleId = "RS0041";
public const string AvoidOptSuffixForNullableEnableCodeRuleId = "RS0042";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,13 @@
<data name="DefaultableTypeShouldHaveDefaultableFieldsTitle" xml:space="preserve">
<value>Defaultable types should have defaultable fields</value>
</data>
<data name="AvoidOptSuffixForNullableEnableCodeRuleIdDescription" xml:space="preserve">
<value>Avoid the 'Opt' suffix in a nullable-enabled code.</value>
</data>
<data name="AvoidOptSuffixForNullableEnableCodeRuleIdMessage" xml:space="preserve">
<value>Avoid the 'Opt' suffix in a nullable-enabled code</value>
</data>
<data name="AvoidOptSuffixForNullableEnableCodeRuleIdTitle" xml:space="preserve">
<value>Avoid the 'Opt' suffix</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Typy, které se dají nastavit jako výchozí, by měly mít pole, která se tak dají nastavit taky.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Auf den Standard festlegbare Typen müssen auf den Standard festlegbare Felder aufweisen.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Los tipos defaultable deben tener campos defaultable</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Les types par défaut doivent avoir des champs par défaut</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">I tipi defaultable devono avere campi defaultable</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">既定に設定可能な型には、既定に設定可能なフィールドが必要です</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">기본값 설정 가능 형식에는 기본값 설정 가능 필드가 있어야 합니다.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Typy dopuszczające wartość domyślną powinny mieć pola z wartościami domyślnymi</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Os tipos usados como padrão devem ter campos usados como padrão</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Типы, допускающие значения по умолчанию, должны иметь соответствующие поля.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../RoslynDiagnosticsAnalyzersResources.resx">
<body>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdDescription">
<source>Avoid the 'Opt' suffix in a nullable-enabled code.</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code.</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdMessage">
<source>Avoid the 'Opt' suffix in a nullable-enabled code</source>
<target state="new">Avoid the 'Opt' suffix in a nullable-enabled code</target>
<note />
</trans-unit>
<trans-unit id="AvoidOptSuffixForNullableEnableCodeRuleIdTitle">
<source>Avoid the 'Opt' suffix</source>
<target state="new">Avoid the 'Opt' suffix</target>
<note />
</trans-unit>
<trans-unit id="DefaultableTypeShouldHaveDefaultableFieldsDescription">
<source>Defaultable types should have defaultable fields</source>
<target state="translated">Varsayılan değer atanabilir türler varsayılan değer atanabilir alanlara sahip olmalıdır</target>
Expand Down
Loading