Skip to content

Update the DeclarePublicAPI analyzer to consider return types#359

Merged
tmeschter merged 1 commit intodotnet:masterfrom
tmeschter:ReturnTypesInDeclarePublicAPI
Feb 10, 2015
Merged

Update the DeclarePublicAPI analyzer to consider return types#359
tmeschter merged 1 commit intodotnet:masterfrom
tmeschter:ReturnTypesInDeclarePublicAPI

Conversation

@tmeschter
Copy link
Contributor

Fixes #289.

The DeclarePublicAPI draws attention to changes to the public API
surface area in order to prevent breaking changes and to encourage
careful design when adding new APIs. It requires that every project with
a public API capture the public types and members in a file called
PublicAPI.txt, and creates errors when this file does not match the
actual symbols in the project. This makes changes very obvious in code
reviews and source control history.

Currently PublicAPI.txt does not capture the return types of members
(field, properties, methods, and events) so these can changes without it
being caught by the tool. This changes updates the analyzer to include
the return type.

A nice feature of the associated code fix is that it sorts PublicAPI.txt
alphabetically, and since type names are fully qualified this naturally
groups together types in the same namespace, members in the same type,
overloads, etc. To preserve this property we put the return type at the
end of the line, after the type and member name.

The DeclarePublicAPI draws attention to changes to the public API
surface area in order to prevent breaking changes and to encourage
careful design when adding new APIs. It requires that every project with
a public API capture the public types and members in a file called
PublicAPI.txt, and creates errors when this file does not match the
actual symbols in the project. This makes changes very obvious in code
reviews and source control history.

Currently PublicAPI.txt does not capture the return types of members
(field, properties, methods, and events) so these can changes without it
being caught by the tool. This changes updates the analyzer to include
the return type.

A nice feature of the associated code fix is that it sorts PublicAPI.txt
alphabetically, and since type names are fully qualified this naturally
groups together types in the same namespace, members in the same type,
overloads, etc. To preserve this property we put the return type at the
end of the line, after the type and member name.
@jmarolf
Copy link
Contributor

jmarolf commented Feb 10, 2015

👍

@tmeschter
Copy link
Contributor Author

FYI, the Jenkins build failed for unrelated reasons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this method, can you not simply update your SymbolDisplayFormat to set IncludeType ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered that, but then the call to symbol.ToDisplayString(PublicApiFormat) would put the return type at the beginning of the string. Since the code fix does a simple alphabetical sort of the lines in PublicAPI.txt, the symbols would then be sorted primarily by return type, rather than by type and member name.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Ok.

@srivatsn
Copy link
Contributor

👍

tmeschter added a commit that referenced this pull request Feb 10, 2015
Update the DeclarePublicAPI analyzer to consider return types
@tmeschter tmeschter merged commit a410115 into dotnet:master Feb 10, 2015
@tmeschter tmeschter deleted the ReturnTypesInDeclarePublicAPI branch February 10, 2015 20:23
dibarbet pushed a commit to dibarbet/roslyn that referenced this pull request Nov 21, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

DeclarePublicAPI analyzer does not include return type as part of the API

3 participants