diff --git a/Analyzers/Analyzers.csproj b/Analyzers/Analyzers.csproj index 33a8b6b..0596447 100644 --- a/Analyzers/Analyzers.csproj +++ b/Analyzers/Analyzers.csproj @@ -13,7 +13,7 @@ 1.0.1 - 1.0.3 + 2.0.0-alpha diff --git a/Analyzers/Config/ByteOrderMarkConfig.cs b/Analyzers/Config/ByteOrderMarkConfig.cs index 1d3e630..2acc47c 100644 --- a/Analyzers/Config/ByteOrderMarkConfig.cs +++ b/Analyzers/Config/ByteOrderMarkConfig.cs @@ -10,18 +10,24 @@ namespace StyleChecker.Analyzers.Config; /// The configuration data of ByteOrderMark analyzer. /// [ForElement(Analyzer.DiagnosticId, Namespace)] -public sealed class ByteOrderMarkConfig : AbstractConfig +public sealed class ByteOrderMarkConfig( + [ForAttribute("maxDepth")] BindResult? maxDepthEvent, + [Multiple] IEnumerable files) + : AbstractConfig { -#pragma warning disable IDE0052 // Remove unread private members - [ElementSchema] - private static readonly Schema TheSchema = Schema.Of(Multiple.Of()); -#pragma warning restore IDE0052 // Remove unread private members + /// + /// Initializes a new instance of the + /// class. + /// + [Ignored] + public ByteOrderMarkConfig() + : this(null, []) + { + } - [field: ForAttribute("maxDepth")] - private BindEvent? MaxDepthEvent { get; } + private BindResult? MaxDepthEvent { get; } = maxDepthEvent; - [field: ForChild] - private IEnumerable Files { get; } = []; + private IEnumerable Files { get; } = files; /// /// Gets the maximum number of directory levels to search. @@ -56,13 +62,12 @@ public override IEnumerable Validate() /// Represents the files that must not start with a BOM. /// [ForElement("files", Namespace)] - private sealed class File + public sealed class File([ForAttribute("glob")] string? glob) { /// /// Gets the glob pattern representing files that are disallowed to /// start with a BOM. /// - [field: ForAttribute("glob")] - public string? Glob { get; } + public string? Glob { get; } = glob; } } diff --git a/Analyzers/Config/DiscardingReturnValueConfig.cs b/Analyzers/Config/DiscardingReturnValueConfig.cs index a2c51d4..fdfce3d 100644 --- a/Analyzers/Config/DiscardingReturnValueConfig.cs +++ b/Analyzers/Config/DiscardingReturnValueConfig.cs @@ -9,16 +9,21 @@ namespace StyleChecker.Analyzers.Config; /// The configuration data of DiscardingReturnValue analyzer. /// [ForElement("DiscardingReturnValue", Namespace)] -public sealed class DiscardingReturnValueConfig : AbstractConfig +public sealed class DiscardingReturnValueConfig( + [Multiple] IEnumerable methodElements) + : AbstractConfig { -#pragma warning disable IDE0052 // Remove unread private members - [ElementSchema] - private static readonly Schema TheSchema = Schema.Of( - Multiple.Of()); -#pragma warning restore IDE0052 // Remove unread private members + /// + /// Initializes a new instance of the class. + /// + [Ignored] + public DiscardingReturnValueConfig() + : this([]) + { + } - [field: ForChild] - private IEnumerable MethodElements { get; } = []; + private IEnumerable MethodElements { get; } = methodElements; /// /// Gets the signatures of the methods whose return value must not be @@ -40,12 +45,11 @@ public IEnumerable GetMethodSignatures() /// Represents the method whose return value must not be discarded. /// [ForElement("method", Namespace)] - private sealed class Method + public sealed class Method([ForAttribute("id")] string? id) { /// /// Gets the signature of the method. /// - [field: ForAttribute("id")] - public string? Id { get; } + public string? Id { get; } = id; } } diff --git a/Analyzers/Config/LongLineConfig.cs b/Analyzers/Config/LongLineConfig.cs index b7f4a08..e2e2e7b 100644 --- a/Analyzers/Config/LongLineConfig.cs +++ b/Analyzers/Config/LongLineConfig.cs @@ -7,12 +7,23 @@ namespace StyleChecker.Analyzers.Config; /// The configuration data of LongLine analyzer. /// [ForElement("LongLine", Namespace)] -public sealed class LongLineConfig : AbstractConfig +public sealed class LongLineConfig( + [ForAttribute("maxLineLength")] BindResult? maxLineLengthResult) + : AbstractConfig { private const int DefaultMaxLineLength = 80; - [field: ForAttribute("maxLineLength")] - private BindEvent? MaxLineLengthEvent { get; } + /// + /// Initializes a new instance of the class. + /// + [Ignored] + public LongLineConfig() + : this(null) + { + } + + private BindResult? MaxLineLengthEvent { get; } + = maxLineLengthResult; /// public override IEnumerable Validate() diff --git a/Analyzers/Config/NoDocumentationConfig.cs b/Analyzers/Config/NoDocumentationConfig.cs index 8460fa5..cada22a 100644 --- a/Analyzers/Config/NoDocumentationConfig.cs +++ b/Analyzers/Config/NoDocumentationConfig.cs @@ -10,16 +10,21 @@ namespace StyleChecker.Analyzers.Config; /// The configuration data of NoDocumentation analyzer. /// [ForElement(Analyzer.DiagnosticId, Namespace)] -public sealed class NoDocumentationConfig : AbstractConfig +public sealed class NoDocumentationConfig( + [Multiple] IEnumerable ignoreElements) + : AbstractConfig { -#pragma warning disable IDE0052 // Remove unread private members - [ElementSchema] - private static readonly Schema TheSchema = Schema.Of( - Multiple.Of()); -#pragma warning restore IDE0052 // Remove unread private members + /// + /// Initializes a new instance of the + /// class. + /// + [Ignored] + public NoDocumentationConfig() + : this([]) + { + } - [field: ForChild] - private IEnumerable IgnoreElements { get; } = []; + private IEnumerable IgnoreElements { get; } = ignoreElements; /// /// Gets the attribute classes, with which the element annotated and @@ -60,25 +65,26 @@ public override IEnumerable Validate() /// must be ignored. /// [ForElement("ignore", Namespace)] - private sealed class Ignore : Validateable + public sealed class Ignore( + [ForAttribute("with")] string? with, + [ForAttribute("inclusive")] BindResult? inclusiveResult) + : Validateable { /// /// Gets the attribute class. /// - [field: ForAttribute("with")] - public string? With { get; } + public string? With { get; } = with; /// /// Gets whether the element only is ignored or all the elements it /// contains are ignored. /// - [field: ForAttribute("inclusive")] - public BindEvent? InclusiveEvent { get; } + public BindResult? InclusiveResult { get; } = inclusiveResult; /// public IEnumerable Validate() => ParseKit.ValidateBoolean( - InclusiveEvent, + InclusiveResult, "invalid boolean value of 'inclusive' attribute"); /// @@ -91,7 +97,7 @@ public IEnumerable Validate() /// public bool IsInclusive() { - return ParseKit.ToBooleanValue(InclusiveEvent, false); + return ParseKit.ToBooleanValue(InclusiveResult, false); } } } diff --git a/Analyzers/Config/ParseKit.cs b/Analyzers/Config/ParseKit.cs index 2b8055c..c1df24f 100644 --- a/Analyzers/Config/ParseKit.cs +++ b/Analyzers/Config/ParseKit.cs @@ -26,8 +26,8 @@ private static readonly IReadOnlyDictionary BooleanMap /// /// Gets the boolean value of the specified BindEvent<string> object. /// - /// - /// The BindEvent<string> object that provides a boolean value. + /// + /// The BindResult<string> object that provides a boolean value. /// /// /// The default value. @@ -36,11 +36,13 @@ private static readonly IReadOnlyDictionary BooleanMap /// The boolean value if the specified BindEvent has a value and the value /// is parsed successfully and valid, the default value otherwise. /// - public static bool ToBooleanValue(BindEvent? ev, bool defaultValue) + public static bool ToBooleanValue( + BindResult? result, + bool defaultValue) { - return (ev is null) + return (result is null) ? defaultValue - : ParseBoolean(ev.Value) ?? defaultValue; + : ParseBoolean(result.Value) ?? defaultValue; } /// @@ -48,7 +50,7 @@ public static bool ToBooleanValue(BindEvent? ev, bool defaultValue) /// object. /// /// - /// The BindEvent<string> object that provides an integer value. + /// The BindResult<string> object that provides an integer value. /// /// /// The default value. @@ -63,7 +65,7 @@ public static bool ToBooleanValue(BindEvent? ev, bool defaultValue) /// otherwise. /// public static int ToIntValue( - BindEvent? ev, + BindResult? ev, int defaultValue, Func isValidValue) { @@ -81,8 +83,8 @@ public static int ToIntValue( /// Validates the specified BindEvent<string> object and gets the /// tuples representing the error information. /// - /// - /// The BindEvent<string> object. + /// + /// The BindResult<string> object. /// /// /// The error message when it is unable to parse a boolean value. @@ -92,16 +94,16 @@ public static int ToIntValue( /// object can be parsed successfully. Otherwise, the errors. /// public static IEnumerable ValidateBoolean( - BindEvent? ev, + BindResult? result, string invalidBooleanValueError) { - if (ev is null) + if (result is null) { return NoError; } - var v = ParseBoolean(ev.Value); + var v = ParseBoolean(result.Value); return !v.HasValue - ? [ToError(ev, invalidBooleanValueError)] + ? [ToError(result, invalidBooleanValueError)] : NoError; } @@ -109,8 +111,8 @@ public static IEnumerable ValidateBoolean( /// Validates the specified BindEvent<string> object and gets the /// tuples representing the error information. /// - /// - /// The BindEvent<string> object. + /// + /// The BindResult<string> object. /// /// /// The function that returns whether a value of the argument is valid or @@ -127,22 +129,24 @@ public static IEnumerable ValidateBoolean( /// can be parsed successfully. Otherwise, the errors. /// public static IEnumerable ValidateInt( - BindEvent? ev, + BindResult? result, Func isValidValue, string invalidIntegerValueError, string invalidValueRangeError) { - return (ev is null) + return (result is null) ? NoError - : (ParseInt(ev.Value) is not {} v) - ? [ToError(ev, invalidIntegerValueError)] + : (ParseInt(result.Value) is not {} v) + ? [ToError(result, invalidIntegerValueError)] : !isValidValue(v) - ? [ToError(ev, invalidValueRangeError)] + ? [ToError(result, invalidValueRangeError)] : NoError; } - private static WhereWhy ToError(BindEvent ev, string message) - => new(ev.Line, ev.Column, $"{message}: '{ev.Value}'"); + private static WhereWhy ToError( + BindResult result, + string message) + => new(result.Line, result.Column, $"{message}: '{result.Value}'"); /// /// Gets the integer value that results from parsing the specified string. diff --git a/Analyzers/Config/RootConfig.cs b/Analyzers/Config/RootConfig.cs index 342d605..27ab933 100644 --- a/Analyzers/Config/RootConfig.cs +++ b/Analyzers/Config/RootConfig.cs @@ -8,52 +8,52 @@ namespace StyleChecker.Analyzers.Config; /// The root configuration. /// [ForElement("config", Namespace)] -public sealed class RootConfig : AbstractConfig +public sealed class RootConfig( + [Optional] ByteOrderMarkConfig? byteOrderMark, + [Optional] DiscardingReturnValueConfig? discardingReturnValue, + [Optional] LongLineConfig? longLine, + [Optional] NoDocumentationConfig? noDocumentation, + [Optional] ThoughtlessNameConfig? thoughtlessName) + : AbstractConfig { -#pragma warning disable IDE0052 // Remove unread private members - [ElementSchema] - private static readonly Schema TheSchema = Schema.Of( - Optional.Of(), - Optional.Of(), - Optional.Of(), - Optional.Of(), - Optional.Of()); -#pragma warning restore IDE0052 // Remove unread private members + /// + /// Initializes a new instance of the class. + /// + [Ignored] + public RootConfig() + : this(null, null, null, null, null) + { + } /// /// Gets the configuration of LongLine analyzer. /// - [field: ForChild] public ByteOrderMarkConfig ByteOrderMark { get; } - = new ByteOrderMarkConfig(); + = byteOrderMark ?? new(); /// /// Gets the configuration of ThoughtlessName analyzer. /// - [field: ForChild] public DiscardingReturnValueConfig DiscardingReturnValue { get; } - = new DiscardingReturnValueConfig(); + = discardingReturnValue ?? new(); /// /// Gets the configuration of LongLine analyzer. /// - [field: ForChild] public LongLineConfig LongLine { get; } - = new LongLineConfig(); + = longLine ?? new(); /// /// Gets the configuration of NoDocumentation analyzer. /// - [field: ForChild] public NoDocumentationConfig NoDocumentation { get; } - = new NoDocumentationConfig(); + = noDocumentation ?? new(); /// /// Gets the configuration of ThoughtlessName analyzer. /// - [field: ForChild] public ThoughtlessNameConfig ThoughtlessName { get; } - = new ThoughtlessNameConfig(); + = thoughtlessName ?? new(); /// public override IEnumerable Validate() diff --git a/Analyzers/Config/ThoughtlessNameConfig.cs b/Analyzers/Config/ThoughtlessNameConfig.cs index 171753c..d1c3677 100644 --- a/Analyzers/Config/ThoughtlessNameConfig.cs +++ b/Analyzers/Config/ThoughtlessNameConfig.cs @@ -9,16 +9,20 @@ namespace StyleChecker.Analyzers.Config; /// The configuration data of ThoughtlessName analyzer. /// [ForElement("ThoughtlessName", Namespace)] -public sealed class ThoughtlessNameConfig : AbstractConfig +public sealed class ThoughtlessNameConfig( + [Multiple] IEnumerable disallowElements) + : AbstractConfig { -#pragma warning disable IDE0052 // Remove unread private members - [ElementSchema] - private static readonly Schema TheSchema = Schema.Of( - Multiple.Of()); -#pragma warning restore IDE0052 // Remove unread private members + /// + /// Initializes a new instance of the + /// class. + /// + public ThoughtlessNameConfig() + : this([]) + { + } - [field: ForChild] - private IEnumerable DisallowElements { get; } = []; + private IEnumerable DisallowElements { get; } = disallowElements; /// /// Gets the identifiers that must not be used. @@ -39,12 +43,12 @@ public IEnumerable GetDisallowedIdentifiers() /// Represents the identifier that must not be used. /// [ForElement("disallow", Namespace)] - private sealed class Disallow + public sealed class Disallow( + [ForAttribute("id")] string? id) { /// /// Gets the identifier to be disallowed. /// - [field: ForAttribute("id")] - public string? Id { get; } + public string? Id { get; } = id; } } diff --git a/BeliefCrucible/Atmosphere.cs b/BeliefCrucible/Atmosphere.cs index 3644fc1..683dabd 100644 --- a/BeliefCrucible/Atmosphere.cs +++ b/BeliefCrucible/Atmosphere.cs @@ -65,7 +65,7 @@ public Atmosphere() null, false, DocumentationMode.Parse, - LanguageVersion.CSharp12) + LanguageVersion.CSharp13) { } diff --git a/Package/Package.csproj b/Package/Package.csproj index 1ad250e..1b9c3bf 100644 --- a/Package/Package.csproj +++ b/Package/Package.csproj @@ -27,7 +27,7 @@ README.md COPYRIGHT.txt 1.0.1 - 1.0.3 + 2.0.0-alpha en-US @@ -37,7 +37,7 @@ - + diff --git a/TestSuite/Settings/InvalidConfig/AnalyzerTest.cs b/TestSuite/Settings/InvalidConfig/AnalyzerTest.cs index 7a3638e..e5e9c76 100644 --- a/TestSuite/Settings/InvalidConfig/AnalyzerTest.cs +++ b/TestSuite/Settings/InvalidConfig/AnalyzerTest.cs @@ -40,9 +40,9 @@ public void ConfigElementNotClosed() var result = NewErrorResult( NewLocations(5, 1), "InvalidConfig", - "Unexpected end of file has occurred. " - + "The following elements are not closed: " - + "config. Line 5, position 1."); + """ + Unexpected end of file has occurred. The following elements are not closed: config. Line 5, position 1. + """); VerifyDiagnostic(code, atmosphere, result); } @@ -57,7 +57,9 @@ public void ValidationErrorOfLongLine() var result = NewErrorResult( NewLocations(5, 13), "InvalidConfig", - "invalid integer value of maxLineLength attribute: 'a'"); + """ + invalid integer value of maxLineLength attribute: 'a' + """); VerifyDiagnostic(code, atmosphere, result); } @@ -73,9 +75,9 @@ public void UnexpectedChildElement() var result = NewErrorResult( NewLocations(5, 4), "InvalidConfig", - "unexpected node type: Element of the element " - + $"'{ns}:Unexpected' (it is expected that the element " - + $"'{ns}:config' ends)"); + $""" + Unexpected node type: Element of the element '{ns}:Unexpected'. (Expected the end of element '{ns}:config'.) + """); VerifyDiagnostic(code, atmosphere, result); } @@ -92,9 +94,9 @@ public void UnexpectedRootElement() var result = NewErrorResult( NewLocations(2, 2), "InvalidConfig", - "unexpected node type: Element of the element " - + $"'{actualNs}:Unexpected' (it is expected that the " - + $"element '{ns}:config' starts)"); + $""" + Unexpected node type: Element of the element '{actualNs}:Unexpected'. (Expected the start of element '{ns}:config'.) + """); VerifyDiagnostic(code, atmosphere, result); } diff --git a/TestSuite/TestSuite.csproj b/TestSuite/TestSuite.csproj index c280049..3449994 100644 --- a/TestSuite/TestSuite.csproj +++ b/TestSuite/TestSuite.csproj @@ -566,7 +566,7 @@ - +