Permission declarations should be ordered alphabetically (FC0004)

Alphabetical ordering of Permissions property entries is not cosmetic. It directly reduces merge conflicts in source control.

When two developers (or agents) add a permission entry to the end of an unsorted list, that change touches the same line range and produces a conflict almost every time. In a sorted list, each entry lands at a deterministic position based on its name. Two additions to a sorted list are unlikely to collide unless they happen to be alphabetically adjacent. The result is fewer unexpected conflicts and less friction during code review and merging.

This matters most for permissionset objects, which routinely contain dozens of entries. But it applies equally to the Permissions property on codeunits, reports, queries, and xmlports.

Entries are sorted first by object type keyword (codeunit, page, report, table, tabledata, etc.) and then by object name (case-insensitive).

A code fix is available for this diagnostic.

Example

The following permissionset declares entries in arbitrary order:

permissionset 50100 "Sales Permissions"
{
    Assignable = true;
    Access = Public;

    Permissions = tabledata "Sales Header" = R,
                  codeunit "Sales-Post" = X,
                  page "Sales Order" = X,
                  tabledata Customer = R;
}
The Permissions property entries are not ordered alphabetically by type and name. [FC0004]

Sort the entries by type, then by name:

permissionset 50100 "Sales Permissions"
{
    Assignable = true;
    Access = Public;

    Permissions = codeunit "Sales-Post" = X,
                  page "Sales Order" = X,
                  tabledata Customer = R,
                  tabledata "Sales Header" = R;
}

Code fix

The ALCops: Sort permission declarations alphabetically code fix reorders all entries in the Permissions property. When the original declaration is on a single line, the fix converts it to multi-line format for readability.

See also

  • AC0031 and AC0032 validate the correctness of permission entries. FC0004 validates their ordering.