Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Analyzers/Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<PropertyGroup>
<AnnotationsVersion>1.0.1</AnnotationsVersion>
<OxbindVersion>1.0.3</OxbindVersion>
<OxbindVersion>2.0.0-alpha</OxbindVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
29 changes: 17 additions & 12 deletions Analyzers/Config/ByteOrderMarkConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ namespace StyleChecker.Analyzers.Config;
/// The configuration data of ByteOrderMark analyzer.
/// </summary>
[ForElement(Analyzer.DiagnosticId, Namespace)]
public sealed class ByteOrderMarkConfig : AbstractConfig
public sealed class ByteOrderMarkConfig(
[ForAttribute("maxDepth")] BindResult<string>? maxDepthEvent,
[Multiple] IEnumerable<ByteOrderMarkConfig.File> files)
: AbstractConfig
{
#pragma warning disable IDE0052 // Remove unread private members
[ElementSchema]
private static readonly Schema TheSchema = Schema.Of(Multiple.Of<File>());
#pragma warning restore IDE0052 // Remove unread private members
/// <summary>
/// Initializes a new instance of the <see cref="ByteOrderMarkConfig"/>
/// class.
/// </summary>
[Ignored]
public ByteOrderMarkConfig()
: this(null, [])
{
}

[field: ForAttribute("maxDepth")]
private BindEvent<string>? MaxDepthEvent { get; }
private BindResult<string>? MaxDepthEvent { get; } = maxDepthEvent;

[field: ForChild]
private IEnumerable<File> Files { get; } = [];
private IEnumerable<File> Files { get; } = files;

/// <summary>
/// Gets the maximum number of directory levels to search.
Expand Down Expand Up @@ -56,13 +62,12 @@ public override IEnumerable<WhereWhy> Validate()
/// Represents the files that must not start with a BOM.
/// </summary>
[ForElement("files", Namespace)]
private sealed class File
public sealed class File([ForAttribute("glob")] string? glob)
{
/// <summary>
/// Gets the glob pattern representing files that are disallowed to
/// start with a BOM.
/// </summary>
[field: ForAttribute("glob")]
public string? Glob { get; }
public string? Glob { get; } = glob;
}
}
26 changes: 15 additions & 11 deletions Analyzers/Config/DiscardingReturnValueConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ namespace StyleChecker.Analyzers.Config;
/// The configuration data of DiscardingReturnValue analyzer.
/// </summary>
[ForElement("DiscardingReturnValue", Namespace)]
public sealed class DiscardingReturnValueConfig : AbstractConfig
public sealed class DiscardingReturnValueConfig(
[Multiple] IEnumerable<DiscardingReturnValueConfig.Method> methodElements)
: AbstractConfig
{
#pragma warning disable IDE0052 // Remove unread private members
[ElementSchema]
private static readonly Schema TheSchema = Schema.Of(
Multiple.Of<Method>());
#pragma warning restore IDE0052 // Remove unread private members
/// <summary>
/// Initializes a new instance of the <see
/// cref="DiscardingReturnValueConfig"/> class.
/// </summary>
[Ignored]
public DiscardingReturnValueConfig()
: this([])
{
}

[field: ForChild]
private IEnumerable<Method> MethodElements { get; } = [];
private IEnumerable<Method> MethodElements { get; } = methodElements;

/// <summary>
/// Gets the signatures of the methods whose return value must not be
Expand All @@ -40,12 +45,11 @@ public IEnumerable<string> GetMethodSignatures()
/// Represents the method whose return value must not be discarded.
/// </summary>
[ForElement("method", Namespace)]
private sealed class Method
public sealed class Method([ForAttribute("id")] string? id)
{
/// <summary>
/// Gets the signature of the method.
/// </summary>
[field: ForAttribute("id")]
public string? Id { get; }
public string? Id { get; } = id;
}
}
17 changes: 14 additions & 3 deletions Analyzers/Config/LongLineConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ namespace StyleChecker.Analyzers.Config;
/// The configuration data of LongLine analyzer.
/// </summary>
[ForElement("LongLine", Namespace)]
public sealed class LongLineConfig : AbstractConfig
public sealed class LongLineConfig(
[ForAttribute("maxLineLength")] BindResult<string>? maxLineLengthResult)
: AbstractConfig
{
private const int DefaultMaxLineLength = 80;

[field: ForAttribute("maxLineLength")]
private BindEvent<string>? MaxLineLengthEvent { get; }
/// <summary>
/// Initializes a new instance of the <see cref="LongLineConfig"/> class.
/// </summary>
[Ignored]
public LongLineConfig()
: this(null)
{
}

private BindResult<string>? MaxLineLengthEvent { get; }
= maxLineLengthResult;

/// <inheritdoc/>
public override IEnumerable<WhereWhy> Validate()
Expand Down
36 changes: 21 additions & 15 deletions Analyzers/Config/NoDocumentationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ namespace StyleChecker.Analyzers.Config;
/// The configuration data of NoDocumentation analyzer.
/// </summary>
[ForElement(Analyzer.DiagnosticId, Namespace)]
public sealed class NoDocumentationConfig : AbstractConfig
public sealed class NoDocumentationConfig(
[Multiple] IEnumerable<NoDocumentationConfig.Ignore> ignoreElements)
: AbstractConfig
{
#pragma warning disable IDE0052 // Remove unread private members
[ElementSchema]
private static readonly Schema TheSchema = Schema.Of(
Multiple.Of<Ignore>());
#pragma warning restore IDE0052 // Remove unread private members
/// <summary>
/// Initializes a new instance of the <see cref="NoDocumentationConfig"/>
/// class.
/// </summary>
[Ignored]
public NoDocumentationConfig()
: this([])
{
}

[field: ForChild]
private IEnumerable<Ignore> IgnoreElements { get; } = [];
private IEnumerable<Ignore> IgnoreElements { get; } = ignoreElements;

/// <summary>
/// Gets the attribute classes, with which the element annotated and
Expand Down Expand Up @@ -60,25 +65,26 @@ public override IEnumerable<WhereWhy> Validate()
/// must be ignored.
/// </summary>
[ForElement("ignore", Namespace)]
private sealed class Ignore : Validateable
public sealed class Ignore(
[ForAttribute("with")] string? with,
[ForAttribute("inclusive")] BindResult<string>? inclusiveResult)
: Validateable
{
/// <summary>
/// Gets the attribute class.
/// </summary>
[field: ForAttribute("with")]
public string? With { get; }
public string? With { get; } = with;

/// <summary>
/// Gets whether the element only is ignored or all the elements it
/// contains are ignored.
/// </summary>
[field: ForAttribute("inclusive")]
public BindEvent<string>? InclusiveEvent { get; }
public BindResult<string>? InclusiveResult { get; } = inclusiveResult;

/// <inheritdoc/>
public IEnumerable<WhereWhy> Validate()
=> ParseKit.ValidateBoolean(
InclusiveEvent,
InclusiveResult,
"invalid boolean value of 'inclusive' attribute");

/// <summary>
Expand All @@ -91,7 +97,7 @@ public IEnumerable<WhereWhy> Validate()
/// </returns>
public bool IsInclusive()
{
return ParseKit.ToBooleanValue(InclusiveEvent, false);
return ParseKit.ToBooleanValue(InclusiveResult, false);
}
}
}
48 changes: 26 additions & 22 deletions Analyzers/Config/ParseKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ private static readonly IReadOnlyDictionary<string, bool> BooleanMap
/// <summary>
/// Gets the boolean value of the specified BindEvent&lt;string&gt; object.
/// </summary>
/// <param name="ev">
/// The BindEvent&lt;string&gt; object that provides a boolean value.
/// <param name="result">
/// The BindResult&lt;string&gt; object that provides a boolean value.
/// </param>
/// <param name="defaultValue">
/// The default value.
Expand All @@ -36,19 +36,21 @@ private static readonly IReadOnlyDictionary<string, bool> BooleanMap
/// The boolean value if the specified BindEvent has a value and the value
/// is parsed successfully and valid, the default value otherwise.
/// </returns>
public static bool ToBooleanValue(BindEvent<string>? ev, bool defaultValue)
public static bool ToBooleanValue(
BindResult<string>? result,
bool defaultValue)
{
return (ev is null)
return (result is null)
? defaultValue
: ParseBoolean(ev.Value) ?? defaultValue;
: ParseBoolean(result.Value) ?? defaultValue;
}

/// <summary>
/// Gets the integer value of the specified BindEvent&lt;string&gt;
/// object.
/// </summary>
/// <param name="ev">
/// The BindEvent&lt;string&gt; object that provides an integer value.
/// The BindResult&lt;string&gt; object that provides an integer value.
/// </param>
/// <param name="defaultValue">
/// The default value.
Expand All @@ -63,7 +65,7 @@ public static bool ToBooleanValue(BindEvent<string>? ev, bool defaultValue)
/// otherwise.
/// </returns>
public static int ToIntValue(
BindEvent<string>? ev,
BindResult<string>? ev,
int defaultValue,
Func<int, bool> isValidValue)
{
Expand All @@ -81,8 +83,8 @@ public static int ToIntValue(
/// Validates the specified BindEvent&lt;string&gt; object and gets the
/// tuples representing the error information.
/// </summary>
/// <param name="ev">
/// The BindEvent&lt;string&gt; object.
/// <param name="result">
/// The BindResult&lt;string&gt; object.
/// </param>
/// <param name="invalidBooleanValueError">
/// The error message when it is unable to parse a boolean value.
Expand All @@ -92,25 +94,25 @@ public static int ToIntValue(
/// object can be parsed successfully. Otherwise, the errors.
/// </returns>
public static IEnumerable<WhereWhy> ValidateBoolean(
BindEvent<string>? ev,
BindResult<string>? 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;
}

/// <summary>
/// Validates the specified BindEvent&lt;string&gt; object and gets the
/// tuples representing the error information.
/// </summary>
/// <param name="ev">
/// The BindEvent&lt;string&gt; object.
/// <param name="result">
/// The BindResult&lt;string&gt; object.
/// </param>
/// <param name="isValidValue">
/// The function that returns whether a value of the argument is valid or
Expand All @@ -127,22 +129,24 @@ public static IEnumerable<WhereWhy> ValidateBoolean(
/// can be parsed successfully. Otherwise, the errors.
/// </returns>
public static IEnumerable<WhereWhy> ValidateInt(
BindEvent<string>? ev,
BindResult<string>? result,
Func<int, bool> 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<string> ev, string message)
=> new(ev.Line, ev.Column, $"{message}: '{ev.Value}'");
private static WhereWhy ToError(
BindResult<string> result,
string message)
=> new(result.Line, result.Column, $"{message}: '{result.Value}'");

/// <summary>
/// Gets the integer value that results from parsing the specified string.
Expand Down
40 changes: 20 additions & 20 deletions Analyzers/Config/RootConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,52 @@ namespace StyleChecker.Analyzers.Config;
/// The root configuration.
/// </summary>
[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<ByteOrderMarkConfig>(),
Optional.Of<DiscardingReturnValueConfig>(),
Optional.Of<LongLineConfig>(),
Optional.Of<NoDocumentationConfig>(),
Optional.Of<ThoughtlessNameConfig>());
#pragma warning restore IDE0052 // Remove unread private members
/// <summary>
/// Initializes a new instance of the <see cref="RootConfig"/> class.
/// </summary>
[Ignored]
public RootConfig()
: this(null, null, null, null, null)
{
}

/// <summary>
/// Gets the configuration of LongLine analyzer.
/// </summary>
[field: ForChild]
public ByteOrderMarkConfig ByteOrderMark { get; }
= new ByteOrderMarkConfig();
= byteOrderMark ?? new();

/// <summary>
/// Gets the configuration of ThoughtlessName analyzer.
/// </summary>
[field: ForChild]
public DiscardingReturnValueConfig DiscardingReturnValue { get; }
= new DiscardingReturnValueConfig();
= discardingReturnValue ?? new();

/// <summary>
/// Gets the configuration of LongLine analyzer.
/// </summary>
[field: ForChild]
public LongLineConfig LongLine { get; }
= new LongLineConfig();
= longLine ?? new();

/// <summary>
/// Gets the configuration of NoDocumentation analyzer.
/// </summary>
[field: ForChild]
public NoDocumentationConfig NoDocumentation { get; }
= new NoDocumentationConfig();
= noDocumentation ?? new();

/// <summary>
/// Gets the configuration of ThoughtlessName analyzer.
/// </summary>
[field: ForChild]
public ThoughtlessNameConfig ThoughtlessName { get; }
= new ThoughtlessNameConfig();
= thoughtlessName ?? new();

/// <inheritdoc/>
public override IEnumerable<WhereWhy> Validate()
Expand Down
Loading
Loading