Skip to content

Commit 2c6474f

Browse files
jfversluisCopilot
andauthored
Add PublicAPI.Unshipped.txt BOM sort warning to Copilot instructions (dotnet#34327)
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description PR dotnet#34320 fixed RS0017 analyzer errors caused by `#nullable enable` being sorted to the bottom of 14 Maps `PublicAPI.Unshipped.txt` files. The root cause was a prior Copilot agent session that used `LC_ALL=C sort -u` to resolve merge conflicts — the BOM bytes (`0xEF 0xBB 0xBF`) sort after all ASCII characters, pushing the directive below the API entries. This updates the Copilot instructions to prevent this from recurring: - Explains that `#nullable enable` must remain on line 1 - Warns against using plain `sort` on these files (BOM sort ordering) - Provides a safe conflict resolution script that preserves the header before sorting API entries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2f22928 commit 2c6474f

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ When working with public API changes:
138138
- **Use `dotnet format analyzers`** if having trouble
139139
- **If files are incorrect**: Revert all changes, then add only the necessary new API entries
140140

141+
**🚨 CRITICAL: `#nullable enable` must be line 1**
142+
143+
Every `PublicAPI.Unshipped.txt` file starts with `#nullable enable` (often BOM-prefixed: `#nullable enable`) on the **first line**. If this line is moved or removed, the analyzer treats it as a declared API symbol and emits **RS0017** errors.
144+
145+
**Never sort these files with plain `sort`** — the BOM bytes (`0xEF 0xBB 0xBF`) sort after ASCII characters under `LC_ALL=C`, pushing `#nullable enable` to the bottom of the file.
146+
147+
When resolving merge conflicts or adding entries, use this safe pattern that preserves line 1:
148+
```bash
149+
for f in $(git diff --name-only --diff-filter=U | grep "PublicAPI.Unshipped.txt"); do
150+
# Extract and preserve the #nullable enable line (with or without BOM)
151+
HEADER=$(head -1 "$f" | grep -o '.*#nullable enable' || echo '#nullable enable')
152+
# Strip conflict markers, remove all #nullable lines, sort+dedup the API entries
153+
grep -v '^<<<<<<\|^======\|^>>>>>>\|#nullable enable' "$f" | LC_ALL=C sort -u | sed '/^$/d' > /tmp/api_fix.txt
154+
# Reassemble: header first, then sorted entries
155+
printf '%s\n' "$HEADER" > "$f"
156+
cat /tmp/api_fix.txt >> "$f"
157+
git add "$f"
158+
done
159+
```
160+
141161
### Branching
142162
- `main` - For bug fixes without API changes
143163
- `net10.0` - For new features and API changes

0 commit comments

Comments
 (0)