Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore legitimately out-of-order visibility sections in VisibilitySectionOrder #44

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

fourls
Copy link
Collaborator

@fourls fourls commented Oct 13, 2023

The VisibilitySectionOrder check currently requires that visibility sections be exactly in ascending order of visibility. There are times in which this is impractical, particularly when public types or constants are then used in later declarations:

type
  TFoo = class(TObject)
  public type
    TBar = class(TObject)
      // ...
    end;
  protected
    procedure ProtectedBarProc(Bar: TBar);
  public
    procedure PublicBarProc(Bar: TBar);
  end;

This PR excludes visibility sections with only a single type or const from being checked by the ordering rule.

Copy link
Collaborator

@Cirras Cirras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some offline design review on this one that basically boiled down to:

  • the "single type section or const section" heuristic is fine, but could have a lot of false negatives
  • a more appropriate solution (with its own set of false negatives) would be to exclude any visibility section that we can verify contains a declaration with a usage further down in the type declaration

@fourls fourls force-pushed the visibility-section-order-fix branch from d4d03bb to 048caef Compare October 31, 2023 06:33
@fourls
Copy link
Collaborator Author

fourls commented Oct 31, 2023

Reimplemented with new design considerations.

@fourls fourls requested a review from Cirras October 31, 2023 06:34
@fourls fourls changed the title Ignore order of visibility sections with a single "type" or "const" in VisibilitySectionOrder Ignore legitimately out-of-order visibility sections in VisibilitySectionOrder Oct 31, 2023
@fourls fourls force-pushed the visibility-section-order-fix branch from 048caef to 243a1ea Compare November 3, 2023 05:03
@fourls
Copy link
Collaborator Author

fourls commented Nov 3, 2023

Reimplemented:

As the check loops over the sequential visibility sections, it maintains a stack of previous sections. When the current section has a lower visibility than the section before it, the stack is popped until the top element is not excluded. If the stack is now empty, does not raise an issue. If the current section has a lower visibility than the new "previous section", raises an issue.

@fourls fourls requested a review from Cirras November 3, 2023 05:11
Copy link
Collaborator

@Cirras Cirras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Cirras Cirras merged commit 56a4d88 into master Nov 5, 2023
2 checks passed
@Cirras Cirras deleted the visibility-section-order-fix branch November 5, 2023 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants