From aa80139f16a435291e118b4ae827e3ad90ede762 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 2 Oct 2023 19:51:11 +1100 Subject: [PATCH] use negation pattern --- .../ParseNodes/MapNode.cs | 2 +- .../ParseNodes/OpenApiAnyConverter.cs | 2 +- .../ParseNodes/ParseNode.cs | 2 +- .../ParseNodes/ValueNode.cs | 2 +- .../Validations/Rules/RuleHelpers.cs | 30 +++++++++---------- .../Validations/ValidationRule.cs | 2 +- test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs index 0ee5934ce..2ce5e3431 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs @@ -30,7 +30,7 @@ public MapNode(ParsingContext context, string yamlString) : public MapNode(ParsingContext context, YamlNode node) : base( context) { - if (!(node is YamlMappingNode mapNode)) + if (node is not YamlMappingNode mapNode) { throw new OpenApiReaderException("Expected map.", Context); } diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs index ae9254fe8..a12142075 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs @@ -50,7 +50,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS return newObject; } - if (!(openApiAny is OpenApiString)) + if (openApiAny is not OpenApiString) { return openApiAny; } diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/ParseNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/ParseNode.cs index 295b02bf3..24a49f6cc 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/ParseNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/ParseNode.cs @@ -24,7 +24,7 @@ protected ParseNode(ParsingContext parsingContext) public MapNode CheckMapNode(string nodeName) { - if (!(this is MapNode mapNode)) + if (this is not MapNode mapNode) { throw new OpenApiReaderException($"{nodeName} must be a map/object", Context); } diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs index 68f4bd7ea..6efdcf04d 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs @@ -15,7 +15,7 @@ internal class ValueNode : ParseNode public ValueNode(ParsingContext context, YamlNode node) : base( context) { - if (!(node is YamlScalarNode scalarNode)) + if (node is not YamlScalarNode scalarNode) { throw new OpenApiReaderException("Expected a value.", node); } diff --git a/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs b/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs index 630dc8e65..731bd8693 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs @@ -75,7 +75,7 @@ public static void ValidateDataTypeMismatch( } // If value is not a string and also not an object, there is a data mismatch. - if (!(value is OpenApiObject)) + if (value is not OpenApiObject) { context.CreateWarning( ruleName, @@ -115,7 +115,7 @@ public static void ValidateDataTypeMismatch( } // If value is not a string and also not an array, there is a data mismatch. - if (!(value is OpenApiArray)) + if (value is not OpenApiArray) { context.CreateWarning( ruleName, @@ -139,7 +139,7 @@ public static void ValidateDataTypeMismatch( if (type == "integer" && format == "int32") { - if (!(value is OpenApiInteger)) + if (value is not OpenApiInteger) { context.CreateWarning( ruleName, @@ -151,7 +151,7 @@ public static void ValidateDataTypeMismatch( if (type == "integer" && format == "int64") { - if (!(value is OpenApiLong)) + if (value is not OpenApiLong) { context.CreateWarning( ruleName, @@ -161,9 +161,9 @@ public static void ValidateDataTypeMismatch( return; } - if (type == "integer" && !(value is OpenApiInteger)) + if (type == "integer" && value is not OpenApiInteger) { - if (!(value is OpenApiInteger)) + if (value is not OpenApiInteger) { context.CreateWarning( ruleName, @@ -175,7 +175,7 @@ public static void ValidateDataTypeMismatch( if (type == "number" && format == "float") { - if (!(value is OpenApiFloat)) + if (value is not OpenApiFloat) { context.CreateWarning( ruleName, @@ -187,7 +187,7 @@ public static void ValidateDataTypeMismatch( if (type == "number" && format == "double") { - if (!(value is OpenApiDouble)) + if (value is not OpenApiDouble) { context.CreateWarning( ruleName, @@ -199,7 +199,7 @@ public static void ValidateDataTypeMismatch( if (type == "number") { - if (!(value is OpenApiDouble)) + if (value is not OpenApiDouble) { context.CreateWarning( ruleName, @@ -211,7 +211,7 @@ public static void ValidateDataTypeMismatch( if (type == "string" && format == "byte") { - if (!(value is OpenApiByte)) + if (value is not OpenApiByte) { context.CreateWarning( ruleName, @@ -223,7 +223,7 @@ public static void ValidateDataTypeMismatch( if (type == "string" && format == "date") { - if (!(value is OpenApiDate)) + if (value is not OpenApiDate) { context.CreateWarning( ruleName, @@ -235,7 +235,7 @@ public static void ValidateDataTypeMismatch( if (type == "string" && format == "date-time") { - if (!(value is OpenApiDateTime)) + if (value is not OpenApiDateTime) { context.CreateWarning( ruleName, @@ -247,7 +247,7 @@ public static void ValidateDataTypeMismatch( if (type == "string" && format == "password") { - if (!(value is OpenApiPassword)) + if (value is not OpenApiPassword) { context.CreateWarning( ruleName, @@ -259,7 +259,7 @@ public static void ValidateDataTypeMismatch( if (type == "string") { - if (!(value is OpenApiString)) + if (value is not OpenApiString) { context.CreateWarning( ruleName, @@ -271,7 +271,7 @@ public static void ValidateDataTypeMismatch( if (type == "boolean") { - if (!(value is OpenApiBoolean)) + if (value is not OpenApiBoolean) { context.CreateWarning( ruleName, diff --git a/src/Microsoft.OpenApi/Validations/ValidationRule.cs b/src/Microsoft.OpenApi/Validations/ValidationRule.cs index fdbf5c330..97a66034d 100644 --- a/src/Microsoft.OpenApi/Validations/ValidationRule.cs +++ b/src/Microsoft.OpenApi/Validations/ValidationRule.cs @@ -59,7 +59,7 @@ internal override void Evaluate(IValidationContext context, object item) return; } - if (!(item is T)) + if (item is not T) { throw Error.Argument(string.Format(SRResource.InputItemShouldBeType, typeof(T).FullName)); } diff --git a/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs b/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs index 6d2eafc01..e11be6225 100644 --- a/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs +++ b/test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs @@ -62,7 +62,7 @@ public static IEnumerable GetSchemas() JToken GetProp(JToken obj, string prop) { - if (!(obj is JObject jObj)) + if (obj is not JObject jObj) return null; if (!jObj.TryGetValue(prop, out var jToken)) return null;