Skip to content

Commit

Permalink
Update analyzers and resolve warnings etc
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonGraal committed Jan 13, 2025
1 parent 3a0a434 commit 1cf19c0
Show file tree
Hide file tree
Showing 39 changed files with 129 additions and 140 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ max_line_length = 150
insert_final_newline = true
indent_size = 2
tab_width = 2
csharp_indent_labels = flush_left
csharp_using_directive_placement = outside_namespace:warning
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_prefer_method_group_conversion = true:suggestion
csharp_style_prefer_top_level_statements = true:suggestion
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
csharp_style_expression_bodied_constructors = when_on_single_line:suggestion
csharp_style_expression_bodied_operators = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = true:suggestion
csharp_prefer_static_local_function = true:suggestion
csharp_prefer_static_anonymous_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion

# Shell script files
[*.sh]
Expand Down Expand Up @@ -255,6 +276,7 @@ dotnet_diagnostic.CA1001.severity = warning
dotnet_diagnostic.CA1010.severity = warning
dotnet_diagnostic.CA1036.severity = suggestion
dotnet_diagnostic.CA1310.severity = warning
dotnet_diagnostic.CA1515.severity = none
dotnet_diagnostic.CA1708.severity = warning
dotnet_diagnostic.CA1716.severity = warning
dotnet_diagnostic.CA1725.severity = warning
Expand All @@ -272,3 +294,7 @@ dotnet_diagnostic.IDE0060.severity = warning

# IDE2001: Embedded statements must be on their own line
dotnet_diagnostic.IDE2001.severity = none

# IDE0045: Convert to conditional expression
dotnet_diagnostic.IDE0045.severity = none
dotnet_diagnostic.IDE0046.severity = none
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,4 @@ activities.yml
per-class/
runs-*.yml
Html/
format-report.json
format/
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisLevel>8.0-all</AnalysisLevel>
<AnalysisLevel>latest-all</AnalysisLevel>
<IsPublishable>false</IsPublishable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<RootNamespace>GqlPlus</RootNamespace>
Expand Down
3 changes: 1 addition & 2 deletions GqlPlus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
.globalconfig = .globalconfig
.prettierrc.yml = .prettierrc.yml
.github\dependabot.yml = .github\dependabot.yml
Directory.Build.props = Directory.Build.props
.github\workflows\dotnet-test.yml = .github\workflows\dotnet-test.yml
.config\dotnet-tools.json = .config\dotnet-tools.json
README.md = README.md
format.ps1 = format.ps1
README.md = README.md
update.ps1 = update.ps1
EndProjectSection
EndProject
Expand Down
4 changes: 3 additions & 1 deletion format.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
prettier -w .
dotnet format --verbosity detailed --report format-report.json
dotnet format whitespace --verbosity detailed --report format/whitespace-report.json
dotnet format style --verbosity detailed --report format/style-report.json
dotnet format analyzers --verbosity detailed --report format/analyzers-report.json
11 changes: 3 additions & 8 deletions src/GqlPlus.Modeller/Models/GlobalsModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ public record class AndTypeModel<TModel>
: ModelBase
where TModel : ModelBase
{
private readonly string _field;

public AndTypeModel(string field)
=> _field = field;

public TModel? And { get; set; }

public BaseTypeModel? Type { get; init; }
}

public record class CategoriesModel()
: AndTypeModel<CategoryModel>("category")
: AndTypeModel<CategoryModel>
{ }

public record class CategoryModel(
Expand All @@ -28,7 +23,7 @@ TypeRefModel<TypeKindModel> Output
}

public record class DirectivesModel()
: AndTypeModel<DirectiveModel>("directive")
: AndTypeModel<DirectiveModel>
{ }

public record class DirectiveModel(
Expand All @@ -41,7 +36,7 @@ string Name
}

public record class OperationsModel()
: AndTypeModel<OperationModel>("operation")
: AndTypeModel<OperationModel>
{ }

public record class OperationModel(
Expand Down
2 changes: 1 addition & 1 deletion src/GqlPlus.Modeller/Rendering/RenderStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public RenderStructure AddSet<TEnum>(string key, TEnum set, string? tag = null,
{
Type type = typeof(TEnum);

if (type.GetCustomAttributes(typeof(FlagsAttribute)).Any()) {
if (type.GetCustomAttributes<FlagsAttribute>().Any()) {
int flags = (int)(object)set;
IDict result = NewDict;

Expand Down
4 changes: 2 additions & 2 deletions src/GqlPlus.Parser/Ast/Schema/SchemaAst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public string Show()
{
using StringWriter sw = new();
int indent = 0;
string[] begins = new[] { "(", "{", "[", "<" };
string[] ends = new[] { ")", "}", "]", ">" };
string[] begins = ["(", "{", "[", "<"];
string[] ends = [")", "}", "]", ">"];
foreach (string? field in GetFields()) {
if (string.IsNullOrWhiteSpace(field)) {
continue;
Expand Down
9 changes: 4 additions & 5 deletions src/GqlPlus.Parser/Parsing/ValueListParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

namespace GqlPlus.Parsing;

public sealed class ValueListParser<T> : Parser<T>.IA
public sealed class ValueListParser<T>(
Parser<T>.D value
) : Parser<T>.IA
{
private readonly Parser<T>.L _value;

public ValueListParser(Parser<T>.D value)
=> _value = value;
private readonly Parser<T>.L _value = value;

public IResultArray<T> Parse<TContext>(TContext tokens, string label)
where TContext : Tokenizer
Expand Down
9 changes: 4 additions & 5 deletions src/GqlPlus.Parser/Result/ResultArrayOk.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace GqlPlus.Result;

public readonly struct ResultArrayOk<TValue>
: IResultArray<TValue>, IResultOk<IEnumerable<TValue>>
public readonly struct ResultArrayOk<TValue>(
IEnumerable<TValue> result
) : IResultArray<TValue>, IResultOk<IEnumerable<TValue>>
{
public IEnumerable<TValue> Result { get; }

public ResultArrayOk(IEnumerable<TValue> result) => Result = result;
public IEnumerable<TValue> Result { get; } = result;

public IResult<TResult> AsPartial<TResult>(TResult result, Action<IEnumerable<TValue>>? withValue = null, Action? action = null)
{
Expand Down
9 changes: 4 additions & 5 deletions src/GqlPlus.Parser/Result/ResultError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace GqlPlus.Result;

public readonly struct ResultError<TValue>
: IResultError<TValue>
public readonly struct ResultError<TValue>(
TokenMessage message
) : IResultError<TValue>
{
public TokenMessage Message { get; }

public ResultError(TokenMessage message) => Message = message;
public TokenMessage Message { get; } = message;

public IResult<TResult> AsPartial<TResult>(TResult result, Action<TValue>? withValue = null, Action? action = null)
{
Expand Down
1 change: 1 addition & 0 deletions src/GqlPlus.Verifier/Verifying/Schema/AstParentVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private void CheckTypedParentType(ParentUsage<TAst> input, TContext context, boo
onParent?.Invoke(parentType);
}
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ protected override void UsageValue(IGqlpUnion usage, UsageContext context)
}

void CheckTypeLabel(string name, IGqlpType type)
{
context.AddError(usage, "union", $"Type kind mismatch for {name}. Found {type?.Label}", type is not IGqlpSimple and not IGqlpTypeSpecial);
}
=> context.AddError(
usage,
"union",
$"Type kind mismatch for {name}. Found {type?.Label}",
type is not IGqlpSimple and not IGqlpTypeSpecial);
}

private static bool CheckMember(string name, IGqlpUnionItem member, UsageContext context, Action<string, IGqlpType>? checkType = null)
Expand Down
2 changes: 1 addition & 1 deletion test/GqlPlus.ComponentTestBase/BuildData.t4
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void BuildData(string directory, string prefix) {
var gitFile = samplesDir.GetFiles("git-details.txt")[0];
string gitDetails;
using (var gitText = gitFile.OpenText()) {
gitDetails = gitText.ReadToEnd();
gitDetails = gitText.ReadToEnd().Trim();
}#>
// Generated from <#= relative #>
// Collected from <#= gitDetails #>
Expand Down
3 changes: 1 addition & 2 deletions test/GqlPlus.ComponentTestBase/OperationData.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated from .\test\GqlPlus.ComponentTestBase\Samples\Operation
// Collected from 6d0b249 (HEAD -> operation, origin/operation) 2025-01-13 Update docfx and tweak specs

// Collected from 37de024 (HEAD -> operation, origin/operation) 2025-01-13 Tweak category name in valid operation

namespace GqlPlus;

Expand Down
3 changes: 1 addition & 2 deletions test/GqlPlus.ComponentTestBase/SampleData.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated from .\test\GqlPlus.ComponentTestBase\Samples
// Collected from 6d0b249 (HEAD -> operation, origin/operation) 2025-01-13 Update docfx and tweak specs

// Collected from 37de024 (HEAD -> operation, origin/operation) 2025-01-13 Tweak category name in valid operation

namespace GqlPlus;

Expand Down
3 changes: 1 addition & 2 deletions test/GqlPlus.ComponentTestBase/SchemaData.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated from .\test\GqlPlus.ComponentTestBase\Samples\Schema
// Collected from 6d0b249 (HEAD -> operation, origin/operation) 2025-01-13 Update docfx and tweak specs

// Collected from 37de024 (HEAD -> operation, origin/operation) 2025-01-13 Tweak category name in valid operation

namespace GqlPlus;

Expand Down
1 change: 0 additions & 1 deletion test/GqlPlus.Modeller.ComponentTests/BuiltInTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void ModelAllBasicTypes()
Declarations = BuiltIn.Basic
};


ITypesContext context = renderer.Context();
RenderStructure result = renderer.RenderAst(schema, context);

Expand Down
15 changes: 6 additions & 9 deletions test/GqlPlus.Parser.ClassTests/Ast/AstDirectivesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,18 @@ private static string Directives(string[] directives)
=> " " + directives.Joined(d => $"( !d {d} )");
}

internal sealed class AstDirectivesChecks<TAst>
: AstDirectivesChecks<string, TAst>, IAstDirectivesChecks
internal sealed class AstDirectivesChecks<TAst>(
BaseAstChecks<TAst>.CreateBy<string> create
) : AstDirectivesChecks<string, TAst>(create), IAstDirectivesChecks
where TAst : AstAbbreviated, IGqlpDirectives
{
public AstDirectivesChecks(CreateBy<string> create)
: base(create) { }
}

internal class AstDirectivesChecks<TInput, TAst>
: AstAbbreviatedChecks<TInput, TAst>, IAstDirectivesChecks<TInput>
internal class AstDirectivesChecks<TInput, TAst>(
BaseAstChecks<TAst>.CreateBy<TInput> create
) : AstAbbreviatedChecks<TInput, TAst>(create), IAstDirectivesChecks<TInput>
where TAst : AstAbbreviated, IGqlpDirectives
{
public AstDirectivesChecks(CreateBy<TInput> create)
: base(create) { }

public void HashCode(TInput input, string[] directives)
=> HashCode(
() => CreateDirective(input, directives),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,26 @@ public void ModifiedType_WithModifiersAndArgs(AlternateInput input, string[] arg
internal abstract IAstObjectAlternateChecks<TObjBase> AlternateChecks { get; }
}

internal sealed class AstObjectAlternateChecks<TObjAltAst, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>
: AstAbbreviatedChecks<AlternateInput, TObjAltAst>
internal sealed class AstObjectAlternateChecks<TObjAltAst, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>(
AstObjectAlternateChecks<TObjAltAst, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.AlternateBy createAlternate,
AstObjectAlternateChecks<TObjAltAst, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.BaseBy createBase,
AstObjectAlternateChecks<TObjAltAst, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.ArgsBy createArgs
) : AstAbbreviatedChecks<AlternateInput, TObjAltAst>(input => createAlternate(input, createBase(input)))
, IAstObjectAlternateChecks<TObjBase>
where TObjAltAst : AstObjAlternate<TObjBase>
where TObjBase : IGqlpObjBase
where TObjBaseAst : AstObjBase<TObjArg>, TObjBase
where TObjArg : IGqlpObjArg
where TObjArgAst : AstObjArg, TObjArg
{
private readonly AlternateBy _createAlternate;
private readonly BaseBy _createBase;
private readonly ArgsBy _createArgs;
private readonly AlternateBy _createAlternate = createAlternate;
private readonly BaseBy _createBase = createBase;
private readonly ArgsBy _createArgs = createArgs;

internal delegate TObjBaseAst BaseBy(AlternateInput input);
internal delegate TObjAltAst AlternateBy(AlternateInput input, TObjBase refBase);
internal delegate TObjArgAst[] ArgsBy(string[] arguments);

public AstObjectAlternateChecks(AlternateBy createAlternate, BaseBy createBase, ArgsBy createArgs)
: base(input => createAlternate(input, createBase(input)))
{
_createAlternate = createAlternate;
_createBase = createBase;
_createArgs = createArgs;
}

public void HashCode_WithModifiers(AlternateInput input)
=> HashCode(() => CreateModifiers(input));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,18 @@ public void FullType_WithIsTypeParamAndArgs(string input, string[] arguments)
internal abstract IAstObjBaseChecks<TObjBase> ObjBaseChecks { get; }
}

internal sealed class AstObjBaseChecks<TObjBase, TObjBaseAst, TObjArg, TObjArgAst>
: AstAbbreviatedChecks<string, TObjBase>
internal sealed class AstObjBaseChecks<TObjBase, TObjBaseAst, TObjArg, TObjArgAst>(
AstObjBaseChecks<TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.BaseBy createBase,
AstObjBaseChecks<TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.ArgsBy createArgs
) : AstAbbreviatedChecks<string, TObjBase>(input => createBase(input))
, IAstObjBaseChecks<TObjBase>
where TObjBase : IGqlpObjBase
where TObjBaseAst : AstObjBase<TObjArg>, TObjBase
where TObjArg : IGqlpObjArg
where TObjArgAst : AstObjArg, TObjArg
{
private readonly BaseBy _createBase;
private readonly ArgsBy _createArgs;

public AstObjBaseChecks(
BaseBy createBase,
ArgsBy createArgs
) : base(input => createBase(input))
{
_createBase = createBase;
_createArgs = createArgs;
}
private readonly BaseBy _createBase = createBase;
private readonly ArgsBy _createArgs = createArgs;

internal delegate TObjBaseAst BaseBy(string input);
internal delegate TObjArg[] ArgsBy(string[] argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,26 @@ public void ModifiedType_WithModifiersAndArgs(FieldInput input, string[] argumen
internal abstract IAstObjectFieldChecks<TObjBase> FieldChecks { get; }
}

internal sealed class AstObjectFieldChecks<TObjField, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>
: AstAliasedChecks<FieldInput, TObjField>
internal sealed class AstObjectFieldChecks<TObjField, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>(
AstObjectFieldChecks<TObjField, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.FieldBy createField,
AstObjectFieldChecks<TObjField, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.BaseBy createBase,
AstObjectFieldChecks<TObjField, TObjBase, TObjBaseAst, TObjArg, TObjArgAst>.ArgsBy createArgs
) : AstAliasedChecks<FieldInput, TObjField>(input => createField(input, createBase(input)))
, IAstObjectFieldChecks<TObjBase>
where TObjField : AstObjField<TObjBase>
where TObjBase : IGqlpObjBase
where TObjBaseAst : AstObjBase<TObjArg>, TObjBase
where TObjArg : IGqlpObjArg
where TObjArgAst : AstObjArg, TObjArg
{
private readonly FieldBy _createField;
private readonly BaseBy _createBase;
private readonly ArgsBy _createArgs;
private readonly FieldBy _createField = createField;
private readonly BaseBy _createBase = createBase;
private readonly ArgsBy _createArgs = createArgs;

internal delegate TObjBaseAst BaseBy(FieldInput input);
internal delegate TObjField FieldBy(FieldInput input, TObjBase refBase);
internal delegate TObjArgAst[] ArgsBy(string[] arguments);

public AstObjectFieldChecks(FieldBy createField, BaseBy createBase, ArgsBy createArgs)
: base(input => createField(input, createBase(input)))
{
_createField = createField;
_createBase = createBase;
_createArgs = createArgs;
}

public void HashCode_WithModifiers(FieldInput input)
=> HashCode(() => CreateModifiers(input));

Expand Down
Loading

0 comments on commit 1cf19c0

Please sign in to comment.