AdaCore / AdaCore/gnatformat

`gnatformat` removes space between attribute and argument list (e.g., `'Length (1)`)

Open
#7 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ada
Stars
21
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Description

I have encountered an issue where gnatformat incorrectly removes the whitespace between an Ada attribute (such as 'Length) and its argument list (the opening parenthesis).

While the formatter correctly handles the insertion of spaces before parentheses in other contexts (e.g., function calls), it seems to force the removal of the space when applied to attributes.

Steps to Reproduce
  1. Create a file with the following code (note the space between 'Length and (1)):
function Count_Pieces (Board : Board_Type; State : Square_State_Type) return Natural
with Ghost, Post => Count_Pieces'Result <= Board'Length (1) * Board'Length (2);
  1. Run gnatformat on this file.
Actual Behavior

The formatter removes the spaces, resulting in:

function Count_Pieces (Board : Board_Type; State : Square_State_Type) return Natural
with Ghost, Post => Count_Pieces'Result <= Board'Length(1) * Board'Length(2);
Expected Behavior

The formatter should preserve (or insert) the space before the opening parenthesis to maintain consistency with the rest of the code style, looking like this:

function Count_Pieces (Board : Board_Type; State : Square_State_Type) return Natural
with Ghost, Post => Count_Pieces'Result <= Board'Length (1) * Board'Length (2);
Additional Context

This issue seems specific to attributes. In other scenarios, the rule regarding "space before parenthesis" appears to be applied correctly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the Ada declaration and postcondition shown in the report, then trace gnatformat's handling of attribute references followed by parentheses. Done means formatting preserves or inserts a space between attributes such as 'Length and their argument lists, matching the expected output.

Written by the indexing model from the issue text.

Assessment

Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.