Skip to content

Commit

Permalink
Merge pull request #2739 from dotnet/merges/master-to-3.x
Browse files Browse the repository at this point in the history
Merge master to 3.x
  • Loading branch information
mavasani committed Aug 2, 2019
2 parents 2d26adf + 558ca61 commit b4364fd
Show file tree
Hide file tree
Showing 106 changed files with 861 additions and 729 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Expand Up @@ -53,6 +53,14 @@ dotnet_style_readonly_field = true:warning
# Parameter preferences
dotnet_code_quality_unused_parameters = all:warning

# Expression preferences
dotnet_style_prefer_compound_assignment = true:warning

# Dispose rules (CA2000 and CA2213) ported to IDE analyzers. We already execute the CA rules on the repo, so disable the IDE ones.
dotnet_diagnostic.IDE0067.severity = none
dotnet_diagnostic.IDE0068.severity = none
dotnet_diagnostic.IDE0069.severity = none

### CSharp code style settings ###
[*.cs]

Expand All @@ -77,6 +85,8 @@ csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
csharp_prefer_static_local_function = true:warning
csharp_prefer_simple_using_statement = true:warning

# Newline settings
csharp_new_line_before_open_brace = all
Expand All @@ -88,6 +98,7 @@ csharp_new_line_before_members_in_anonymous_types = true

# Expression-level preferences
csharp_style_unused_value_assignment_preference = discard_variable:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning

### Visual Basic code style settings ###
[*.vb]
Expand Down
5 changes: 3 additions & 2 deletions PostReleaseActivities.md
Expand Up @@ -14,8 +14,9 @@ Please follow the below steps after publishing analyzer NuGet packages from this
4. Update `eng\Versions.props`:
1. Bump up the `VersionPrefix`.
2. Reset `PreReleaseVersionLabel` to `beta1`.
3. Update `MicrosoftCodeAnalysisFXCopAnalyersVersion` to the latest released package version. Build the repo by invoking `Build.cmd` and fix/suppress any new CA diagnostics, as appropriate.
5. Create and submit a PR with the above changes.
3. Update `MicrosoftCodeAnalysisFXCopAnalyersVersion` to the latest released package version.
5. Build the repo by invoking `eng\common\CIBuild.cmd` and fix/suppress any new CA diagnostics, as appropriate. This should also update the analyzer documentation files in the repo to use the new version prefix.
6. Create and submit a PR with the above changes.

Steps to generate Release Notes
=================================================================
Expand Down
Expand Up @@ -16,6 +16,9 @@
-->
<PackageId>*$(MSBuildProjectFullPath)*</PackageId>
<DevelopmentDependency>false</DevelopmentDependency>

<!-- Override the version prefix for this package to append a "revision" field to allow more frequent stable releases -->
<VersionPrefix>$(VersionPrefix).0</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/GenerateAnalyzerRulesets/CodeFixerExtensions.cs
Expand Up @@ -40,7 +40,7 @@ public static ImmutableArray<CodeFixProvider> GetFixers(this AnalyzerFileReferen
ExportCodeFixProviderAttribute attribute = typeInfo.GetCustomAttribute<ExportCodeFixProviderAttribute>();
if (attribute != null)
{
builder = builder ?? ImmutableArray.CreateBuilder<CodeFixProvider>();
builder ??= ImmutableArray.CreateBuilder<CodeFixProvider>();
var fixer = (CodeFixProvider)Activator.CreateInstance(typeInfo.AsType());
if (HasImplementation(fixer))
{
Expand Down
155 changes: 76 additions & 79 deletions src/GenerateAnalyzerRulesets/Program.cs
Expand Up @@ -64,7 +64,7 @@ public static int Main(string[] args)
var analyzers = analyzerFileReference.GetAnalyzersForAllLanguages();
var rulesById = new SortedList<string, DiagnosticDescriptor>();

var assemblyRulesMetadata = (path: path, rules: new SortedList<string, (DiagnosticDescriptor rule, string typeName, string[] languages)>());
var assemblyRulesMetadata = (path, rules: new SortedList<string, (DiagnosticDescriptor rule, string typeName, string[] languages)>());

foreach (var analyzer in analyzers)
{
Expand Down Expand Up @@ -337,7 +337,7 @@ void createPropsFile()
File.WriteAllText(fileWithPath, fileContents);
}

string getFlowAnalysisFeatureFlag()
static string getFlowAnalysisFeatureFlag()
{
return @"
Expand Down Expand Up @@ -404,7 +404,7 @@ string getRulesetOverrides()
return string.Empty;
}

string getEditorConfigAsAdditionalFile()
static string getEditorConfigAsAdditionalFile()
{
return $@"
<!--
Expand Down Expand Up @@ -475,116 +475,113 @@ void createAnalyzerSarifFile()
var directory = Directory.CreateDirectory(analyzerSarifFileDir);
var fileWithPath = Path.Combine(directory.FullName, analyzerSarifFileName);

using (var textWriter = new StreamWriter(fileWithPath, false, Encoding.UTF8))
using (var writer = new Roslyn.Utilities.JsonWriter(textWriter))
using var textWriter = new StreamWriter(fileWithPath, false, Encoding.UTF8);
using var writer = new Roslyn.Utilities.JsonWriter(textWriter);
writer.WriteObjectStart(); // root
writer.Write("$schema", "http://json.schemastore.org/sarif-1.0.0");
writer.Write("version", "1.0.0");
writer.WriteArrayStart("runs");

foreach (var assemblymetadata in rulesMetadata)
{
writer.WriteObjectStart(); // root
writer.Write("$schema", "http://json.schemastore.org/sarif-1.0.0");
writer.Write("version", "1.0.0");
writer.WriteArrayStart("runs");
writer.WriteObjectStart(); // run

foreach (var assemblymetadata in rulesMetadata)
{
writer.WriteObjectStart(); // run
writer.WriteObjectStart("tool");
writer.Write("name", assemblymetadata.Key);

writer.WriteObjectStart("tool");
writer.Write("name", assemblymetadata.Key);
if (!string.IsNullOrWhiteSpace(analyzerVersion))
{
writer.Write("version", analyzerVersion);
}

if (!string.IsNullOrWhiteSpace(analyzerVersion))
{
writer.Write("version", analyzerVersion);
}
writer.Write("language", culture.Name);
writer.WriteObjectEnd(); // tool

writer.Write("language", culture.Name);
writer.WriteObjectEnd(); // tool
writer.WriteObjectStart("rules"); // rules

writer.WriteObjectStart("rules"); // rules
foreach (var rule in assemblymetadata.Value.rules)
{
var ruleId = rule.Key;
var descriptor = rule.Value.rule;

foreach (var rule in assemblymetadata.Value.rules)
{
var ruleId = rule.Key;
var descriptor = rule.Value.rule;
writer.WriteObjectStart(descriptor.Id); // rule
writer.Write("id", descriptor.Id);

writer.WriteObjectStart(descriptor.Id); // rule
writer.Write("id", descriptor.Id);
writer.Write("shortDescription", descriptor.Title.ToString(culture));

writer.Write("shortDescription", descriptor.Title.ToString(culture));
string fullDescription = descriptor.Description.ToString(culture);
writer.Write("fullDescription", !string.IsNullOrEmpty(fullDescription) ? fullDescription : descriptor.MessageFormat.ToString());

string fullDescription = descriptor.Description.ToString(culture);
writer.Write("fullDescription", !string.IsNullOrEmpty(fullDescription) ? fullDescription : descriptor.MessageFormat.ToString());
writer.Write("defaultLevel", getLevel(descriptor.DefaultSeverity));

writer.Write("defaultLevel", getLevel(descriptor.DefaultSeverity));
if (!string.IsNullOrEmpty(descriptor.HelpLinkUri))
{
writer.Write("helpUri", descriptor.HelpLinkUri);
}

if (!string.IsNullOrEmpty(descriptor.HelpLinkUri))
{
writer.Write("helpUri", descriptor.HelpLinkUri);
}
writer.WriteObjectStart("properties");

writer.WriteObjectStart("properties");
writer.Write("category", descriptor.Category);

writer.Write("category", descriptor.Category);
writer.Write("isEnabledByDefault", descriptor.IsEnabledByDefault);

writer.Write("isEnabledByDefault", descriptor.IsEnabledByDefault);
writer.Write("typeName", rule.Value.typeName);

writer.Write("typeName", rule.Value.typeName);
if ((rule.Value.languages?.Length ?? 0) > 0)
{
writer.WriteArrayStart("languages");

if ((rule.Value.languages?.Length ?? 0) > 0)
foreach (var language in rule.Value.languages.OrderBy(l => l, StringComparer.InvariantCultureIgnoreCase))
{
writer.WriteArrayStart("languages");

foreach (var language in rule.Value.languages.OrderBy(l => l, StringComparer.InvariantCultureIgnoreCase))
{
writer.Write(language);
}

writer.WriteArrayEnd(); // languages
writer.Write(language);
}

if (descriptor.CustomTags.Any())
{
writer.WriteArrayStart("tags");
writer.WriteArrayEnd(); // languages
}

foreach (string tag in descriptor.CustomTags)
{
writer.Write(tag);
}
if (descriptor.CustomTags.Any())
{
writer.WriteArrayStart("tags");

writer.WriteArrayEnd(); // tags
foreach (string tag in descriptor.CustomTags)
{
writer.Write(tag);
}

writer.WriteObjectEnd(); // properties
writer.WriteObjectEnd(); // rule
writer.WriteArrayEnd(); // tags
}

writer.WriteObjectEnd(); // rules
writer.WriteObjectEnd(); // run
writer.WriteObjectEnd(); // properties
writer.WriteObjectEnd(); // rule
}

writer.WriteArrayEnd(); // runs
writer.WriteObjectEnd(); // root
writer.WriteObjectEnd(); // rules
writer.WriteObjectEnd(); // run
}

return;
writer.WriteArrayEnd(); // runs
writer.WriteObjectEnd(); // root

string getLevel(DiagnosticSeverity severity)
return;
static string getLevel(DiagnosticSeverity severity)
{
switch (severity)
{
switch (severity)
{
case DiagnosticSeverity.Info:
return "note";
case DiagnosticSeverity.Info:
return "note";

case DiagnosticSeverity.Error:
return "error";
case DiagnosticSeverity.Error:
return "error";

case DiagnosticSeverity.Warning:
return "warning";
case DiagnosticSeverity.Warning:
return "warning";

case DiagnosticSeverity.Hidden:
default:
// hidden diagnostics are not reported on the command line and therefore not currently given to
// the error logger. We could represent it with a custom property in the SARIF log if that changes.
Debug.Assert(false);
goto case DiagnosticSeverity.Warning;
}
case DiagnosticSeverity.Hidden:
default:
// hidden diagnostics are not reported on the command line and therefore not currently given to
// the error logger. We could represent it with a custom property in the SARIF log if that changes.
Debug.Assert(false);
goto case DiagnosticSeverity.Warning;
}
}
}
Expand Down
Expand Up @@ -5,7 +5,7 @@
{
"tool": {
"name": "MetaCompilation.Analyzers",
"version": "2.9.4",
"version": "2.9.5",
"language": "en-US"
},
"rules": {
Expand Down
Expand Up @@ -322,8 +322,7 @@ out ImmutableArray<(string prefix, int start, int end)> allowedIdsInfoList)
{
ruleId = (string)argument.Value.ConstantValue.Value;
var location = argument.Value.Syntax.GetLocation();

string GetAnalyzerName(INamedTypeSymbol a) => a.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
static string GetAnalyzerName(INamedTypeSymbol a) => a.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);

// Factory methods to track declaration locations for every analyzer rule ID.
ConcurrentBag<Location> AddLocationFactory(string analyzerName)
Expand Down Expand Up @@ -367,7 +366,7 @@ ConcurrentBag<Location> UpdateLocationsFactory(string analyzerName, ConcurrentBa
Debug.Assert(additionalTextOpt != null);

var foundMatch = false;
bool ShouldValidateRange((string prefix, int start, int end) range)
static bool ShouldValidateRange((string prefix, int start, int end) range)
=> range.start >= 0 && range.end >= 0;

// Check if ID matches any one of the required ranges.
Expand Down Expand Up @@ -576,7 +575,7 @@ private static AdditionalText TryGetCategoryAndAllowedIdsInfoFile(ImmutableArray
string arg2 = Path.GetFileName(additionalText.Path);
LinePositionSpan linePositionSpan = lines.GetLinePositionSpan(line.Span);
Location location = Location.Create(additionalText.Path, line.Span, linePositionSpan);
invalidFileDiagnostics = invalidFileDiagnostics ?? new List<Diagnostic>();
invalidFileDiagnostics ??= new List<Diagnostic>();
var diagnostic = Diagnostic.Create(AnalyzerCategoryAndIdRangeFileInvalidRule, location, arg1, arg2);
invalidFileDiagnostics.Add(diagnostic);
}
Expand Down
Expand Up @@ -41,8 +41,7 @@ private async Task<Document> ConvertToEqualsAsync(Document document, TextSpan so
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var expression = root.FindNode(sourceSpan, getInnermostNodeForTie: true);
var operation = semanticModel.GetOperation(expression, cancellationToken) as IBinaryOperation;
if (operation is null)
if (!(semanticModel.GetOperation(expression, cancellationToken) is IBinaryOperation operation))
{
return document;
}
Expand Down
Expand Up @@ -444,7 +444,7 @@ private void AnalyzeParameterDeclaration(IParameterSymbol parameter)
{
if (IsContextType(parameter.Type, _compilationStartAnalysisContext, _codeBlockStartAnalysisContext, _operationBlockStartAnalysisContext))
{
_declaredStartAnalysisContextParams = _declaredStartAnalysisContextParams ?? new HashSet<IParameterSymbol>();
_declaredStartAnalysisContextParams ??= new HashSet<IParameterSymbol>();
_declaredStartAnalysisContextParams.Add(parameter);
}
}
Expand All @@ -455,7 +455,7 @@ private void AnalyzeParameterReference(IParameterSymbol parameter)
// This is to avoid false positives, as the registration responsibility is not on the current method.
if (IsContextType(parameter.Type, _compilationStartAnalysisContext, _codeBlockStartAnalysisContext, _operationBlockStartAnalysisContext))
{
_startAnalysisContextParamsToSkip = _startAnalysisContextParamsToSkip ?? new HashSet<IParameterSymbol>();
_startAnalysisContextParamsToSkip ??= new HashSet<IParameterSymbol>();
_startAnalysisContextParamsToSkip.Add(parameter);
}
}
Expand Down Expand Up @@ -486,7 +486,7 @@ private void NoteRegisterActionInvocation(IMethodSymbol method, TInvocationExpre
return;
}

_nestedActionsMap = _nestedActionsMap ?? new Dictionary<IParameterSymbol, List<NodeAndSymbol>>();
_nestedActionsMap ??= new Dictionary<IParameterSymbol, List<NodeAndSymbol>>();
if (!_nestedActionsMap.TryGetValue(contextParameter, out List<NodeAndSymbol> registerInvocations))
{
registerInvocations = new List<NodeAndSymbol>();
Expand Down
Expand Up @@ -5,7 +5,7 @@
{
"tool": {
"name": "Microsoft.CodeAnalysis.Analyzers",
"version": "2.9.4",
"version": "2.9.5",
"language": "en-US"
},
"rules": {
Expand Down Expand Up @@ -299,7 +299,7 @@
{
"tool": {
"name": "Microsoft.CodeAnalysis.CSharp.Analyzers",
"version": "2.9.4",
"version": "2.9.5",
"language": "en-US"
},
"rules": {
Expand Down Expand Up @@ -479,7 +479,7 @@
{
"tool": {
"name": "Microsoft.CodeAnalysis.VisualBasic.Analyzers",
"version": "2.9.4",
"version": "2.9.5",
"language": "en-US"
},
"rules": {
Expand Down

0 comments on commit b4364fd

Please sign in to comment.