GFlisch / Arc4u.Guidance.Doc

Other
5 stars 1 forks source link

(2022.1.13) Avoid some SonarQube complaints with the generated code #214

Closed vvdb-architecture closed 5 months ago

vvdb-architecture commented 9 months ago

The guidance generates a shared project containing the operations and scopes of the application. For example:

public static class Operations
{
    public static readonly Operation[] Values = Enum.GetValues<Access>().Select(o => new Operation { Name = o.ToString(), ID = (int)o }).ToArray();

    public static readonly string[] Scopes = Array.Empty<string>();
}

This generates the following complaints by SonarQube:

Use an immutable collection or reduce the accessibility of the field(s) 'Values'. ?
Code Smell Minor Open Not assigned 15min effort cwe, unpredictable

See why SonarQube thinks this is a bad idea.

Whether SonarQube is correct or not, the code can be generated as follows to avoid these messages:

public static class Operations
{
    public static readonly ImmutableArray<Operation> Values = ImmutableArray.CreateRange(Enum.GetValues<Access>().Select(o => new Operation { Name = o.ToString(), ID = (int)o }));

    public static readonly ImmutableArray<string> Scopes = ImmutableArray<string>.Empty;
}

Nothing else needs to change. The overhead in release mode is negligible.

vvdb-architecture commented 7 months ago

Confirmed fixed in ACC