dotnet / dotnet/sdk

Add code fixer to apply opinionated sort of #: directives in file-based apps

Open
#51,763 0 comments 3 reactions 0 assignees View on GitHub
Area-run-file untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

File-based apps support the following directives:

- `#:sdk`
- `#:property`
- `#:project`
- `#:package`

These can be placed in any order at the top of the file. Commands like `dotnet package add/remove` can add/remove `#:package` lines too.

Currently there is no consistency or opinion on the ordering of lines using these directives. We should consider adding a code fixer to allow for easy application of an opinionated ordering.

My current preference for the order would be:

- `#:sdk` lines first
- `#:property` lines second
- `#:project` lines third
- `#:package` lines fourth
- Within each directive group, sort alphabetically (a-zA-Z)

Optionally we could consider applying preferential sorting within the `#:sdk` and `#:package` groups for references starting with `System.` and `Microsoft.`, so that they sort higher than other references.

My reasoning for this ordering is it generally matches what I've sees in regular project files.

The logic would need to consider and preserve comment lines and blocks, blank lines, as well as regular compiler directives. I imagine this is similar to the existing logic for sorting `using` statements.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.