diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index ec846e1..f614930 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "csharpier": { - "version": "1.4.0", + "version": "1.4.1", "commands": [ "csharpier" ], diff --git a/.config/purview-build-sdk.json b/.config/purview-build-sdk.json index fb67ecb..94c4512 100644 --- a/.config/purview-build-sdk.json +++ b/.config/purview-build-sdk.json @@ -1,5 +1,8 @@ { "Skills": { - "Agents": ["universal"] + "Runner": "bun", + "Agents": [ + "universal" + ] } -} +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b4fe76..4c7a882 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). `NextJsAppResource` kit that declares `ProjectPath`/`ResourcePath` and writes no `BuildResource` gets the `AddDotnetProject`/`AddViteApp`/`AddNextJsApp` registration generated from the declared path. It is not generated when the kit writes the override or an explicit base class implements it. +- **SG0045** (Error) reports a `[ResourceGroup]` class nested inside another type, and **SG0046** (Error) + reports a group declared with a different accessibility than its host kit. Both block generation, so the + failure is one diagnostic on the declaration instead of a wall of errors in generated code: a nested group + lost its containing types (`CS0426`) while still referencing its `*Options` through them, a `public` group + under an `internal` host kit derived from a less accessible base (`CS9338`/`CS0051`), and the inverse + pairing exposed an `internal` group from the host kit's public `Groups` accessor (`CS0053`). - **SG0044** (Info) reports a `BuildResource` override that only repeats the generated call; its code fix removes the override, first moving the path into `ProjectPath`/`ResourcePath` when the attribute does not declare it. diff --git a/README.md b/README.md index e545054..4e6a796 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ From your `[HostKit]` and `[ResourceDefinition]` declarations, ResourceKit gener - a host resource base class, - typed parent/child properties and constructors for hierarchical kits, - host + per-resource options (when enabled), including nested child options, -- typed resource groups (`[ResourceGroup]`, `[InGroup]`) that switch sets of resources on or off and nest them in the dashboard, +- typed resource groups (`[ResourceGroup]`, `[InGroup]`) that switch sets of resources on or off and nest them in the dashboard — a group is a namespace-scope partial class declared with the same accessibility as the host kit (SG0045, SG0046), - named dashboard URLs (`[ResourceUrl]`, `[EndpointUrl]`) that options can override, - an AppHost extension method to build/configure/register your host kit, - typed project, app and file/directory paths (`AppHostProjects`) from `ResourceKitProject` / diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..134cdf1 --- /dev/null +++ b/bun.lock @@ -0,0 +1,96 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "aspire-resourcekit", + "devDependencies": { + "oxfmt": "^0.79.0", + "oxlint": "^1.94.0", + }, + }, + }, + "packages": { + "@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.79.0", "", { "os": "android", "cpu": "arm" }, "sha512-xOCQ/rvokUXs8SxOQY5Wy2ukPaZJZ0PmdJovN0ryB1c8DVEtbcvliLdYtINUYh8QOTpmBOctIisSJk9tvh+J6w=="], + + "@oxfmt/binding-android-arm64": ["@oxfmt/binding-android-arm64@0.79.0", "", { "os": "android", "cpu": "arm64" }, "sha512-WMLDvCjjchUYtI6zXKOdzTDGm72BaYZiz1/VhB1rrxdakUZRlJh1aMr3CT6ui51uHcWVBycULIXSZHpw6u2pTQ=="], + + "@oxfmt/binding-darwin-arm64": ["@oxfmt/binding-darwin-arm64@0.79.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-+LzSN7w7tULz96ntS1Uqe5oI00XZ0o/m/t3+eSfiQp3aTPnj2eGUafqEWryMLk84j7x9NiF+GEP2YT4/BfClgA=="], + + "@oxfmt/binding-darwin-x64": ["@oxfmt/binding-darwin-x64@0.79.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-KFiMRhKeiiooaS1dKc4r8AZgOrfOhwVe1yf/aRef+8BajJwtVjMtlsQl/BNRxtkFbq13GjEo/4Q+9YhFGU4o6g=="], + + "@oxfmt/binding-freebsd-x64": ["@oxfmt/binding-freebsd-x64@0.79.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-lHVIp0g8ZOFKiqVscvttp+3HJkkRH6XkGgfAA0lVexIlE1mMFVp4V7RBdxz/P9p7T8pSNsYdapFWvdT21Mib9w=="], + + "@oxfmt/binding-linux-arm-gnueabihf": ["@oxfmt/binding-linux-arm-gnueabihf@0.79.0", "", { "os": "linux", "cpu": "arm" }, "sha512-Pt35GoxiMUfnr+23cuzk07XQVvISDFxxPcp/aFVB87+RQvJoQaBo/XN7Re9XxgElvbELdyxTLnV9XM2aTfJeUA=="], + + "@oxfmt/binding-linux-arm-musleabihf": ["@oxfmt/binding-linux-arm-musleabihf@0.79.0", "", { "os": "linux", "cpu": "arm" }, "sha512-zPi9Dni58VKp3r1QUcFvnbJNfBr49qyecq0vlM4SaX/MSjmguq77VngirghDua5tyhIDfqdUMTCK2KRlnZFp/g=="], + + "@oxfmt/binding-linux-arm64-gnu": ["@oxfmt/binding-linux-arm64-gnu@0.79.0", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-XhRehATEWjwX7VVEgDUD+7pfHYncQIJaEU0qsHvEKtu9XX0QYzcKvXhU9+URfiGX9WRh3wy2Ow+YCc3EeHtImg=="], + + "@oxfmt/binding-linux-arm64-musl": ["@oxfmt/binding-linux-arm64-musl@0.79.0", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-gbVjFZYug0MEyqvuTAzXGNxFJmBqBO32o1Fud1lG8bGs6oVz48ZtNQyEcAzqrOwaaG+Sxtv4gVzcsfht9aqmkg=="], + + "@oxfmt/binding-linux-ppc64-gnu": ["@oxfmt/binding-linux-ppc64-gnu@0.79.0", "", { "os": "linux", "cpu": "ppc64", "libc": "glibc" }, "sha512-0N0sD3vnllyuiNh1r6zKvNXWE/CakcPKJAespg7XE2+sfvxpz5Q1iFah8sF5aedsOmVvbZaOPZcSHVmMosT1fA=="], + + "@oxfmt/binding-linux-riscv64-gnu": ["@oxfmt/binding-linux-riscv64-gnu@0.79.0", "", { "os": "linux", "cpu": "none", "libc": "glibc" }, "sha512-YtjqUHolcX6cv0ZMZuKQCM4H0ae/okcowy0wGcPHJk4O+8zjy3TvNhzDQ1/KGCkMJO8Fwulm1JcPJsraVJ3p+w=="], + + "@oxfmt/binding-linux-riscv64-musl": ["@oxfmt/binding-linux-riscv64-musl@0.79.0", "", { "os": "linux", "cpu": "none", "libc": "musl" }, "sha512-H2gb9bEBr5tcdP5FU8JYTfgOavXDorWcAAlwci/zEKF2jzgh/oEr/SAw6aHB9n3FLEvnKvOh0A1fjku+vgYoUA=="], + + "@oxfmt/binding-linux-s390x-gnu": ["@oxfmt/binding-linux-s390x-gnu@0.79.0", "", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-aZUbyWW5dSOxT/u6suWc4S9GVDt7YPPNMKQon+z79M8dpXmosadcFHAb7jBhpU7Hdsd2GN6/y3nd0JFTsGddZw=="], + + "@oxfmt/binding-linux-x64-gnu": ["@oxfmt/binding-linux-x64-gnu@0.79.0", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-5pW/ZHYfjjQ71gQR+EKzDz8ZzWIDHlTUtWtxVFNgZbKxVZnRxiSXVrllbjpJtx1q8VtSPZ+Lyg9BLny3yw+PTA=="], + + "@oxfmt/binding-linux-x64-musl": ["@oxfmt/binding-linux-x64-musl@0.79.0", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-3IVUerTDB7Dvd90c1EurAzlVnlE9Azl7Wn8e33qX3wL/IqnslF+P7HvwkD+VeMbHxRtuw0EEBGSArZFXpUAZrQ=="], + + "@oxfmt/binding-openharmony-arm64": ["@oxfmt/binding-openharmony-arm64@0.79.0", "", { "os": "none", "cpu": "arm64" }, "sha512-C5QDgJBtu9+/2BQScoP7ynv54PLOqfoSqhRWwI0D0RPOwYD4tYj0TUdJbXMO1fNegL/5zJiSOxkq6II2xvttWg=="], + + "@oxfmt/binding-win32-arm64-msvc": ["@oxfmt/binding-win32-arm64-msvc@0.79.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-zlW1m8M49vNGgqQF/ze80KW8pZMicnW2XDZGBHuYtXTRYn4ewvgpqN9wwoqb6uLZZfb1R1zaQWKEB8cs7KYjwA=="], + + "@oxfmt/binding-win32-ia32-msvc": ["@oxfmt/binding-win32-ia32-msvc@0.79.0", "", { "os": "win32", "cpu": "ia32" }, "sha512-wbb7hFv2wK3SCTfu8dl1ydNsXM5dmH+PJMU3sojCkfKcG29VDpITL5/AtouCzXjkOc90QRkcAZcg36gP0KqoHA=="], + + "@oxfmt/binding-win32-x64-msvc": ["@oxfmt/binding-win32-x64-msvc@0.79.0", "", { "os": "win32", "cpu": "x64" }, "sha512-JLaeaQ+4LkQiVXY06JIV1dBFEDJzssvDieK/3Poi6CsY+c4UxghZVrrsfcKGJ5R/0F2Sw3C5Lf5Hu0sM5qJfPw=="], + + "@oxlint/binding-android-arm-eabi": ["@oxlint/binding-android-arm-eabi@1.94.0", "", { "os": "android", "cpu": "arm" }, "sha512-730FKSBsKg/NawYnpI3gXRroXptOVqY32iYBPLUZaSx0vgYzOeiNtwojZL4gJdzo9wDvHUlstShmGRHrWcbRYg=="], + + "@oxlint/binding-android-arm64": ["@oxlint/binding-android-arm64@1.94.0", "", { "os": "android", "cpu": "arm64" }, "sha512-8v8TICIiZpXLot1HSq5+vsG9NEKQ5czQBYlUqJR75OVfFDr3cGOmRU/CtHDWnS4tm8nW+Z4Y357qGToSfYqFvA=="], + + "@oxlint/binding-darwin-arm64": ["@oxlint/binding-darwin-arm64@1.94.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-NePcRMO/ltt1Pnytohl6pl0bd/QyRX8HbpptuDz9LK7FTsFD4lKxDMBt7di9k6IFLO0J05jO2nm7wGqIh6dRHA=="], + + "@oxlint/binding-darwin-x64": ["@oxlint/binding-darwin-x64@1.94.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-QV+m+OaEgLmYyillvP1wKXhMm6tDZEWx3vG7Wjmx9ybg15+6YMfqzvp6e+uPukC6zNywuule0vMn0fZgihZzZA=="], + + "@oxlint/binding-freebsd-x64": ["@oxlint/binding-freebsd-x64@1.94.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-KVZjca581nrV6P71kZ9M1otBib9LH0IMn9rr4mrnbRp18V0HiZhBHbU26gji/Ieq2G34qMacnMc3zrmKmvWqWA=="], + + "@oxlint/binding-linux-arm-gnueabihf": ["@oxlint/binding-linux-arm-gnueabihf@1.94.0", "", { "os": "linux", "cpu": "arm" }, "sha512-AMQtgQJk8DgdIV+qaQ5sFoHAko4iKa8zo+gYqELy2grtU8hXWB08DAGB3u90aQL1YSxbd3zqHjgcODBHDFyzBQ=="], + + "@oxlint/binding-linux-arm-musleabihf": ["@oxlint/binding-linux-arm-musleabihf@1.94.0", "", { "os": "linux", "cpu": "arm" }, "sha512-ZLzoGVGAmQkp9leeB5rNxAXLcvlmkmd/GY71LKd5uikk+28NEApY3S2FB3pq6MkfOCFFnFg6QgD9lJIjd07D0Q=="], + + "@oxlint/binding-linux-arm64-gnu": ["@oxlint/binding-linux-arm64-gnu@1.94.0", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-N1dW6o7cY90hLVkDsvz8nWIFOwbO+n272pvW7uLYB7u47HagJVnLChfK6QA9dWFdiPudud9zfksVUOciHc5PNA=="], + + "@oxlint/binding-linux-arm64-musl": ["@oxlint/binding-linux-arm64-musl@1.94.0", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-7tCF4OV/bGDQ2xxgb+sDI97SpmmDrUII4JxTG553voJVA9cnkbXSGSXzo78Ax73BuhEOPoQc2Qi6VrfT0cDG2A=="], + + "@oxlint/binding-linux-ppc64-gnu": ["@oxlint/binding-linux-ppc64-gnu@1.94.0", "", { "os": "linux", "cpu": "ppc64", "libc": "glibc" }, "sha512-B5vUHE4wNisVEuaYxwFUn6tY+vw7A+9APxxqGKI+UmP3yKLpkhnt0qsaCrzjpX55F8rCRHBaTvIDdYo32NE36g=="], + + "@oxlint/binding-linux-riscv64-gnu": ["@oxlint/binding-linux-riscv64-gnu@1.94.0", "", { "os": "linux", "cpu": "none", "libc": "glibc" }, "sha512-/U0b15+c4hTodo8YhEqDlQ6OjnGKvc8igjM/mh23ukqqCUBKiBCaxqUV8bcaofK9uZ+f8wCygkyXLS6LN25YSA=="], + + "@oxlint/binding-linux-riscv64-musl": ["@oxlint/binding-linux-riscv64-musl@1.94.0", "", { "os": "linux", "cpu": "none", "libc": "musl" }, "sha512-ba94Vwl0qOnwXIXNDR33AEbLXuX++ckM74t+9Te7CiPSPAHivhOYyeEkUAicrvOEei1pxXkWggLbFeBFFBTuHA=="], + + "@oxlint/binding-linux-s390x-gnu": ["@oxlint/binding-linux-s390x-gnu@1.94.0", "", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-GVwwwms3O8pdgbCiPavwq2vltyB4661GkDz6kJduZ0E5nsSJUDJ0svaP+ePYpuDVYi4+K1qhCKnWa/Ec8I4LUA=="], + + "@oxlint/binding-linux-x64-gnu": ["@oxlint/binding-linux-x64-gnu@1.94.0", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-iUfCFJN8ZIresSnpTfiIkhF3s8X+XA4I9KJ249QwR2QYTMwh0+pla1pj1xaFi+HtR9McjM4Jaemf70HzX7ilOQ=="], + + "@oxlint/binding-linux-x64-musl": ["@oxlint/binding-linux-x64-musl@1.94.0", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-RqWVeWpDACS4Oh0m21OBmy+CQ50CbbhuHFmNNPVS2P/4R3d188MjEuEuV7So82/tAM8UAT+UuMDtRDESd9NJ7g=="], + + "@oxlint/binding-openharmony-arm64": ["@oxlint/binding-openharmony-arm64@1.94.0", "", { "os": "none", "cpu": "arm64" }, "sha512-K/2DHOUoypwYVqzxJMRPdMuBKjAetZEAsGPP7rHimd+2+5J1TxM+17pG8kw+ayH4+rqBXiPd+H9wgPcU+fF77A=="], + + "@oxlint/binding-win32-arm64-msvc": ["@oxlint/binding-win32-arm64-msvc@1.94.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-hYOCaOJiB4ZCGswBWKl3JQrhqu6mnC5DCUw/1UMNzRXgsHIJ0V226J43LAVICVIDGlhFUZTYShFW+wHWpt6qCQ=="], + + "@oxlint/binding-win32-ia32-msvc": ["@oxlint/binding-win32-ia32-msvc@1.94.0", "", { "os": "win32", "cpu": "ia32" }, "sha512-1l1FDlzbPmAeDoZ8UGspOE2dOmz1ZL6SlDsvOmRCmWSQjCdTy5LzUepS8mO/SGpAoz4D6WAt/yNZAUyHqbkmkQ=="], + + "@oxlint/binding-win32-x64-msvc": ["@oxlint/binding-win32-x64-msvc@1.94.0", "", { "os": "win32", "cpu": "x64" }, "sha512-I3eZdd4bemIJQDNv9XDV/FEofDxIoN32tzCv98wIgLdW05EqxZb5hF4AwPrRzHD/dQhl0n7KgPy5AQPfM0HWrA=="], + + "oxfmt": ["oxfmt@0.79.0", "", { "dependencies": { "tinypool": "2.2.0" }, "optionalDependencies": { "@oxfmt/binding-android-arm-eabi": "0.79.0", "@oxfmt/binding-android-arm64": "0.79.0", "@oxfmt/binding-darwin-arm64": "0.79.0", "@oxfmt/binding-darwin-x64": "0.79.0", "@oxfmt/binding-freebsd-x64": "0.79.0", "@oxfmt/binding-linux-arm-gnueabihf": "0.79.0", "@oxfmt/binding-linux-arm-musleabihf": "0.79.0", "@oxfmt/binding-linux-arm64-gnu": "0.79.0", "@oxfmt/binding-linux-arm64-musl": "0.79.0", "@oxfmt/binding-linux-ppc64-gnu": "0.79.0", "@oxfmt/binding-linux-riscv64-gnu": "0.79.0", "@oxfmt/binding-linux-riscv64-musl": "0.79.0", "@oxfmt/binding-linux-s390x-gnu": "0.79.0", "@oxfmt/binding-linux-x64-gnu": "0.79.0", "@oxfmt/binding-linux-x64-musl": "0.79.0", "@oxfmt/binding-openharmony-arm64": "0.79.0", "@oxfmt/binding-win32-arm64-msvc": "0.79.0", "@oxfmt/binding-win32-ia32-msvc": "0.79.0", "@oxfmt/binding-win32-x64-msvc": "0.79.0" }, "peerDependencies": { "@astrojs/compiler-rs": "^0.5.0", "svelte": "^5.0.0", "vite-plus": "*" }, "optionalPeers": ["@astrojs/compiler-rs", "svelte", "vite-plus"], "bin": { "oxfmt": "bin/oxfmt" } }, "sha512-92iLHGxAgtYk6jLp/1ZBnEeABveNduHZgMDQj7tyqO9iafuJG3q+YHJq0R5Aa4YT+E6xswMQXdmPZYMwynS8ig=="], + + "oxlint": ["oxlint@1.94.0", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.94.0", "@oxlint/binding-android-arm64": "1.94.0", "@oxlint/binding-darwin-arm64": "1.94.0", "@oxlint/binding-darwin-x64": "1.94.0", "@oxlint/binding-freebsd-x64": "1.94.0", "@oxlint/binding-linux-arm-gnueabihf": "1.94.0", "@oxlint/binding-linux-arm-musleabihf": "1.94.0", "@oxlint/binding-linux-arm64-gnu": "1.94.0", "@oxlint/binding-linux-arm64-musl": "1.94.0", "@oxlint/binding-linux-ppc64-gnu": "1.94.0", "@oxlint/binding-linux-riscv64-gnu": "1.94.0", "@oxlint/binding-linux-riscv64-musl": "1.94.0", "@oxlint/binding-linux-s390x-gnu": "1.94.0", "@oxlint/binding-linux-x64-gnu": "1.94.0", "@oxlint/binding-linux-x64-musl": "1.94.0", "@oxlint/binding-openharmony-arm64": "1.94.0", "@oxlint/binding-win32-arm64-msvc": "1.94.0", "@oxlint/binding-win32-ia32-msvc": "1.94.0", "@oxlint/binding-win32-x64-msvc": "1.94.0" }, "peerDependencies": { "oxlint-tsgolint": ">=7.0.2007", "vite-plus": "*" }, "optionalPeers": ["oxlint-tsgolint", "vite-plus"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-Fnt+3wSKRhtLmvgRfxgRX0excSPCoyiXRol4eWKZLtXxWMQtwQ3KjKQUYXOw5loyinfnZfGzh4RCYf7opfL0vw=="], + + "tinypool": ["tinypool@2.2.0", "", {}, "sha512-jBrmx4lYmaC9k/mgPbylxs7kBUxHtD8256up+HjLaDFfXScKJQyil+SWXSvhAtT7XHo+yTVlpB81PGmHP8oLSQ=="], + } +} diff --git a/docs/wiki/concepts/Groups-and-URLs.md b/docs/wiki/concepts/Groups-and-URLs.md index 49aeca9..7898d25 100644 --- a/docs/wiki/concepts/Groups-and-URLs.md +++ b/docs/wiki/concepts/Groups-and-URLs.md @@ -47,7 +47,16 @@ foreach (var resource in HostKit.Groups.Data.Resources.Where(static r => r.IsEna } ``` -A group must be at least as accessible as the host kit, just like a resource kit. +Two placement rules apply, because the group is a second partial declaration the generator completes: + +- **A group must be declared at namespace scope** (SG0045). The generator emits the group, and its nested + options class, beside the host kit, so a group nested inside another class is emitted without the + containing types its `*Options` references still use. Move the class out of the container rather than + making the container `partial`. +- **A group must have the same accessibility as its host kit** (SG0046). A `public` group paired with an + `internal` host kit derives from a less accessible base (CS9338/CS0051), and an `internal` group paired + with a `public` host kit is exposed by the host kit's public `Groups` accessor (CS0053). Declare both + `public` or both `internal`; leaving the modifier off a group makes it `internal` at namespace scope. ### Enablement @@ -65,9 +74,9 @@ ExampleHostKit:Groups:Data:ShowInDashboard=false # data's kits move up to the p ### Parent and child kits in groups -A child kit with no `[InGroup]` inherits its ResourceKit parent's **primary** group when the host seals its -resources. A child with an explicit `[InGroup]` keeps it instead. The parent's group is registered by the -parent, so the child's registration order does not matter. +A child kit **may** declare `[InGroup]`. Without one it inherits its ResourceKit parent's **primary** group +when the host seals its resources; with one it keeps the groups it declares instead. The parent's group is +registered by the parent, so the child's registration order does not matter. Permission to build is the intersection of every gate: the child's own groups, the parent's groups, the host mode, and the parent/child hierarchy. A disabled parent disables descendants even when a child's own diff --git a/docs/wiki/project/Release-Flow.md b/docs/wiki/project/Release-Flow.md index 4a2fc70..1e31355 100644 --- a/docs/wiki/project/Release-Flow.md +++ b/docs/wiki/project/Release-Flow.md @@ -97,7 +97,7 @@ The GitHub release is created with automatically generated notes, grouped by the ## Analyzer release tracking -`src/src/SourceGeneration` ships public diagnostics (`SG0001`–`SG0020`), so it maintains the Roslyn +`src/src/SourceGeneration` ships public diagnostics (`SG0001`–`SG0046`), so it maintains the Roslyn release tracking files: - `AnalyzerReleases.Shipped.md` — rules that have shipped in a released version. @@ -109,6 +109,14 @@ with `TreatWarningsAsErrors`). Add new rules to the *unshipped* file while devel into the *shipped* file as part of a release. See [Contributing](Contributing.md) for the day-to-day workflow. +> [!IMPORTANT] +> Roslyn parses those tables with a fixed header shape, so the separator row under +> `Rule ID | Category | Severity | Notes` must stay dashes and pipes with **no spaces**: +> `--------|----------|----------|-------`. A Markdown formatter that aligns table cells rewrites it to +> `-------- | ---------- | ---------- | ------`, and the build then fails with `RS2007` and stops +> reading every table below the first row it cannot parse. `AnalyzerReleaseTrackingTests` guards the +> shape, so a reformat fails the test suite with the offending rows named. + ## Build-time dependencies Some centrally-managed packages are build/analysis-time only (consumed with `PrivateAssets`), for diff --git a/docs/wiki/reference/Attributes-Reference.md b/docs/wiki/reference/Attributes-Reference.md index 44de41b..c608cfb 100644 --- a/docs/wiki/reference/Attributes-Reference.md +++ b/docs/wiki/reference/Attributes-Reference.md @@ -38,6 +38,11 @@ sealed partial class PublishHostKit; See [Enablement](../concepts/Enablement.md) for the mode list and evaluation order. +A host kit's accessibility sets what its generated members can mention. The host kit's options class and +`Groups` accessor are nested inside it, so they take its accessibility; a `[ResourceGroup]` class is emitted +beside it, so it must be declared the same way — `public` under a `public` host kit, `internal` under an +`internal` one (SG0046). See [Groups and URLs](../concepts/Groups-and-URLs.md#resource-groups). + ## `ResourceDefinitionAttribute` (`[ResourceDefinition]`) Marks a resource kit class that participates in generation. diff --git a/docs/wiki/reference/Diagnostics.md b/docs/wiki/reference/Diagnostics.md index d145a17..7cfc3f6 100644 --- a/docs/wiki/reference/Diagnostics.md +++ b/docs/wiki/reference/Diagnostics.md @@ -57,10 +57,12 @@ exiting the constructor" warning does not apply. | SG0042 | Warning | `ProjectPath` and `ResourcePath` declare different paths; `ResourcePath` is used | | SG0043 | Warning | `ResourcePath` is set on a resource that is not added by path, so it is ignored | | SG0044 | Info | A `BuildResource` override only repeats the registration ResourceKit generates from the declared path; the code fix removes it, moving the path into the attribute first when needed | +| SG0045 | Error | A `[ResourceGroup]` class is nested in another type; it must be declared at namespace scope | +| SG0046 | Error | A `[ResourceGroup]` class and its host kit are declared with different accessibility | See [Attributes Reference](Attributes-Reference.md) for the rules tied to attribute styles, [Project Resources](../concepts/Project-Resources.md) for SG0018/SG0019/SG0041–SG0044 specifics, -[Groups and URLs](../concepts/Groups-and-URLs.md) for SG0021–SG0031, and +[Groups and URLs](../concepts/Groups-and-URLs.md) for SG0021–SG0031 and SG0045/SG0046, and [Parent and child resource kits](../concepts/Hierarchies.md) for SG0032–SG0040. A parent cycle is reported on one kit in the cycle and includes the full path, for example @@ -165,6 +167,9 @@ and the kit's own `IResourceBuilder` would not satisfy it. 6. If the kit declares `Parent = typeof(...)`, ensure that type is a resource kit in the same composition; a child in a different primary group than its parent gets SG0039, and a redundant `Parent.ResourceBuilder` gets SG0040. +7. Declare each `[ResourceGroup]` class at namespace scope (SG0045) and with the same accessibility as the + host kit (SG0046); a nested group, or a `public` group under an `internal` host kit, is reported there + instead of in generated code. ## Common fixes diff --git a/docs/wiki/reference/Source-Generator-Behaviors.md b/docs/wiki/reference/Source-Generator-Behaviors.md index ab6023a..c567968 100644 --- a/docs/wiki/reference/Source-Generator-Behaviors.md +++ b/docs/wiki/reference/Source-Generator-Behaviors.md @@ -41,7 +41,9 @@ the two never drift apart. - **Analyzer-owned rules** are reported only by the analyzer; the generator computes them for its `ShouldProcess` gating but does not re-report them (avoiding duplicate diagnostics). - **Generation-blocking rules** (Error severity, including the group and hierarchy rules SG0021–SG0038) - halt generation via the `GeneratorResult.ShouldProcess` gate. + halt generation via the `GeneratorResult.ShouldProcess` gate. SG0045 (a nested `[ResourceGroup]` class) + and SG0046 (a group whose accessibility differs from its host kit's) block the same way: neither can be + emitted correctly, because the group is a second partial declaration of a class the generator completes. - **Execution-only rules** (SG0017–SG0019, SG0024 and SG0028, warnings) never block generation, so a resource kit with incomplete `BuildResource`/`ConfigureResource` wiring is still generated and the host kit output is still emitted. diff --git a/package.json b/package.json index 4c82a84..17c5d0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aspire-resourcekit", - "version": "2.2.2", + "version": "2.2.3", "description": "Source-generator-powered framework for structuring .NET Aspire AppHost resource composition as strongly typed, test-friendly classes.", "keywords": [], "homepage": "https://purview.dev/projects/aspire-resourcekit/", @@ -15,5 +15,9 @@ "repository": { "type": "git", "url": "git+https://github.com/purview-dev/aspire-resourcekit.git" + }, + "devDependencies": { + "oxfmt": "^0.79.0", + "oxlint": "^1.94.0" } } \ No newline at end of file diff --git a/skills-lock.json b/skills-lock.json index eb2a287..77932f6 100644 --- a/skills-lock.json +++ b/skills-lock.json @@ -1,227 +1,264 @@ { - "version": 1, + "version": 2, "skills": { "add-catalogue-project": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/add-catalogue-project/SKILL.md", - "computedHash": "015f5c8a22346676710b774a1b4110e9172c2b6817e7de0113682004fafe9610" + "computedHash": "fd7539da585809ea8e522c6d00fe8ebfead3a4dd0944c5c96a1ca0d7ce5639cd" }, "add-project-intake": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/add-project-intake/SKILL.md", - "computedHash": "86a3326465defe4b1f15f228009137a99735e981c3de99eff52211975ce22368" + "computedHash": "407e6ede1873adf3e933dfb402a0536eb1bfd4c9bd587af68408ec49b1ae6604" }, "audit-catalogue-projects": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/audit-catalogue-projects/SKILL.md", - "computedHash": "a6e763e87018419d3688f00d72e84f062284dba8cc037a673d15e4ca308a82fb" + "computedHash": "9020e33be8d74bb6d4dac7012f1dc8d8c61fe0df903083eb3bb6dcff8192e67a" }, "docs-aggregation-rules": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/docs-aggregation-rules/SKILL.md", - "computedHash": "569fdb2ea736d5e5727cd8a1341495355511b317874f6e0c6c86f7f0780a44ad" + "computedHash": "ea22ef67e5fa14f6a26e2cede3e3d1da7758e6b8d5ac4b4e65f3c33bedfb6a3e" }, "github-repo-metadata": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/github-repo-metadata/SKILL.md", - "computedHash": "f9123757d3dba91141e5384fa28161d151f5121b3aa9846f30142a74804f4945" + "computedHash": "29b2c46599846f57a15dc63d440c808e4f90f84056f73c7d1d1be2fed71ec18d" }, "project-manifest-reference": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/project-manifest-reference/SKILL.md", - "computedHash": "f0b43eddb34866e6869047c1641fa90bc099475cfddab888cab3feba74d3dd0c" + "computedHash": "dfbde8cf9eb8824bfddce91180eb2471c6c44c6a9946acec8408e40a830ca3d3" }, "purview-build-adoption": { "source": "purview-dev/build", + "commit": "e3b3d9952f0a06065ac7b8fb1ec26d99081ea257", "sourceType": "github", "skillPath": "skills/purview-build-adoption/SKILL.md", - "computedHash": "dd1ec1adf03bcda71293ca957714192c58383c5aecadc1d8fe1c00b354f9bcaa" + "computedHash": "bae63fc04462cb227eac05c09d51ea3740ee606487c906f5df1ea9d673a25710" }, "purview-build-configuration": { "source": "purview-dev/build", + "commit": "e3b3d9952f0a06065ac7b8fb1ec26d99081ea257", "sourceType": "github", "skillPath": "skills/purview-build-configuration/SKILL.md", - "computedHash": "d1db91b6b53fe178639dba30e7f1a7363cbd12234bff809dd357d9e1f7d0a9e3" + "computedHash": "1c3278a5f0891a3bdac829511bfcdf8fa8dc672a49359f4b81f273e1f33f037d" }, "purview-build-pack-validation": { "source": "purview-dev/build", + "commit": "e3b3d9952f0a06065ac7b8fb1ec26d99081ea257", "sourceType": "github", "skillPath": "skills/purview-build-pack-validation/SKILL.md", - "computedHash": "aa6b3ca11f7d009723951fd325932aedc36b9421ea2aeb6cd40a1d3f62e0bce2" + "computedHash": "c95a582e6aed9ccbe9018325fc20a9d389c09e6498b8dca277053198de63e4e6" }, "purview-build-package-json": { "source": "purview-dev/build", + "commit": "e3b3d9952f0a06065ac7b8fb1ec26d99081ea257", "sourceType": "github", "skillPath": "skills/purview-build-package-json/SKILL.md", - "computedHash": "d162df5dff21ac3424c314d63d727f36713d80aa072446118de2111948f938d6" + "computedHash": "f403b09ac26b5bb3f4496175e893800ea9fdc0b3053797c557c7f0c7c5748cb7" }, "purview-build-pipeline": { "source": "purview-dev/build", + "commit": "e3b3d9952f0a06065ac7b8fb1ec26d99081ea257", "sourceType": "github", "skillPath": "skills/purview-build-pipeline/SKILL.md", - "computedHash": "275b2676b7ac8e158b4fef25bd3a5acbc4842c6c01a26ba5fb2973ae9afe9f3e" + "computedHash": "5b5ffbb8ff5d8b6ea188b7aa2219e1e022c7cb225fc216f8085aac61010b410f" }, "purview-build-release-eligibility": { "source": "purview-dev/build", + "commit": "e3b3d9952f0a06065ac7b8fb1ec26d99081ea257", "sourceType": "github", "skillPath": "skills/purview-build-release-eligibility/SKILL.md", - "computedHash": "717d06a3d9212484392fa9dc46e27cc16c524aa7374970d2fd5873122568c8f5" + "computedHash": "87b6dd650e3fe537aa041cfe3b23b3e6e3b9900dd13c957661f787dbc4cdbcb1" }, "purview-buildsdk-adoption": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-adoption/SKILL.md", - "computedHash": "41e63a4e8bc212e21224dac2628ab835d24784a31a4e70ad8a517e7f8801128e" + "computedHash": "5380ee60e34197a8af5ba8ec32e13ef84e541d014fe143ca0d815fff30a1b758" }, "purview-buildsdk-configuration": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-configuration/SKILL.md", - "computedHash": "2a44c84025cc6342f928b2e91b4157bbd340657a1f0b1de80b133f1f106e0e53" + "computedHash": "6eb2359d0c6acba80c5ea548c28e0e4df52ea5157435ba4372fde7e42981a577" }, "purview-buildsdk-docs-sync": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-docs-sync/SKILL.md", - "computedHash": "24d5e86ee5f3877b519c0f85be21c20ad47c051156debe72a42e6f025e3c345d" + "computedHash": "47b4d6dfa84623345239783f507190ee95c3500b7201fb0a9c916e488b4915a3" }, "purview-buildsdk-justfile": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-justfile/SKILL.md", - "computedHash": "fc0ae370f56320723ed3dd4fc0d3851cb876de250035583ac35ecbc4f2374e26" + "computedHash": "128ef10f07dab4a6c7d50800d700f39fe2ec15090174c4ca83bfc659789e4f31" }, "purview-buildsdk-msbuild-properties": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-msbuild-properties/SKILL.md", - "computedHash": "e1dde3293f2a003b4e8f6d2ea418405684add2f7cfa6ec2f53bb3415d8f326ed" + "computedHash": "76af7d5e1d12fd159acea43d3591bb6543b7ecb8375f3cfdc2f090f28729431f" }, "purview-buildsdk-project-detection": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-project-detection/SKILL.md", - "computedHash": "a98da28a4f42f5dfac4d3a02c38b07a42b5039b98b0b45a1073d620c00f60fc0" + "computedHash": "219f323ebd77536fa3424957798b88b89ae119cecef6d801d3101ab7981d6828" }, "purview-buildsdk-project-layout": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-project-layout/SKILL.md", - "computedHash": "392e9be03d076322090cabfa4062afa2755dd25ee9a98e3896d05773628ddb92" + "computedHash": "e2df530972d850894ea3129f30041b5f0a16a067b6a6b037188f920e81d488bb" }, "purview-buildsdk-repository-review": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-repository-review/SKILL.md", - "computedHash": "cc41baaf97b63639352894b726e3f92b6f2cd757862f8af008c81972aa989b2d" + "computedHash": "e09488299f61af4292be2a64c90622a826fd9a7df2640a73ddcc953216c07836" }, "purview-buildsdk-settings-docs-sync": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-settings-docs-sync/SKILL.md", - "computedHash": "76d5dd5b32a0937af024afe92132e221b8947f7cd11a29176bb606f772e2ed5a" + "computedHash": "a2a121d7b1fb97bf2e4c63ed58a20cc737f7d844a10cf30862c62bece930e3ff" }, "purview-buildsdk-skill-installation": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-skill-installation/SKILL.md", - "computedHash": "9b824ac73ed6e068dc1f4dfa714ff44129cb4c816e9dfa3b8f08ad0eed4d8179" + "computedHash": "e00f5a1b4c1ab728338c9ccbfaf59dd0c2d228be4a30149d16699b2dce86fe8e" }, "purview-buildsdk-skill-tests": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-skill-tests/SKILL.md", - "computedHash": "2f6c1a04975389723cc85093f9e15fc56248afa70f9c003b74bd53875cbb1f1f" + "computedHash": "bfa5798b756ab0fdc174fcba98184a516135f61f5b99453fc62b042a5c3551fa" }, "purview-buildsdk-skills-layout": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-skills-layout/SKILL.md", - "computedHash": "1046f7229df832897c6cf80b87c2f6745ea52e89e4e08083a92e6582bb86e742" + "computedHash": "1067c53b6011c601c6a4b702ba327c461372c4fa3f6b36af746c0d10171c717d" }, "purview-buildsdk-testing": { "source": "purview-dev/build-sdk", + "commit": "b035b675d205714f653981b76601aa9ca57dbc33", "sourceType": "github", "skillPath": "skills/purview-buildsdk-testing/SKILL.md", - "computedHash": "920a5d4e7ff8c429f4d883044574248f30f2e1df1af2a18d84530b40d1851ddb" + "computedHash": "5faaf12203c835f1af452137304feed6b99c5e94d7fb1e628ba0b304751914f9" }, "purview-site-assessment": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/purview-site-assessment/SKILL.md", - "computedHash": "5a119c0bbb680e2183f9bfa9dde0cdb35b14d38a8a1419ef21e4fe981366a11b" + "computedHash": "f5277c639e5beb6f781625307de26329eb91f548928cfe6aefdd37d9ddb73045" }, "purview-site-docs": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/purview-site-docs/SKILL.md", - "computedHash": "aad7582179f21d19780c1053069942b1285ae39f744ea1fae590840c6eb8a94e" + "computedHash": "9c1aa10adf8e6a3fe1de89f6509f88b3f76875b30574299454b9c0903c50db1a" }, "purview-site-integration": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/purview-site-integration/SKILL.md", - "computedHash": "5c9f6b7fb88efdddbc55d68d817199d227a3d5d01c99df94c3d462a1e7c5a2f8" + "computedHash": "4f79ec42946f295526a70742b1ee42be51f4a3dd3d955b2101cb87fa6a3a5bcb" }, "purview-sourcegenerator-attribute-data-models": { "source": "purview-dev/sourcegenerator-framework", + "commit": "7f501f0add05eb0dfb78fda33034b4cde3acd9b4", "sourceType": "github", "skillPath": "skills/purview-sourcegenerator-attribute-data-models/SKILL.md", - "computedHash": "84c309a0094a44a8ca76f0078c1fccee1f3c99b96b13a90b5b01260274c0cda6" + "computedHash": "475bf4ef2c6e5c29e02725383f97fb0aea60243c05a2d779b03533c392c6d395" }, "purview-sourcegenerator-codewriter": { "source": "purview-dev/sourcegenerator-framework", + "commit": "7f501f0add05eb0dfb78fda33034b4cde3acd9b4", "sourceType": "github", "skillPath": "skills/purview-sourcegenerator-codewriter/SKILL.md", - "computedHash": "7b8efd8fefee0dbd7ae630e4dcf49166b914132d7517d35b4c1d90597517205c" + "computedHash": "efc58013ff2122eb56981d482f8b66345977f235339473d5db63afca45bee198" }, "purview-sourcegenerator-diagnostics": { "source": "purview-dev/sourcegenerator-framework", + "commit": "7f501f0add05eb0dfb78fda33034b4cde3acd9b4", "sourceType": "github", "skillPath": "skills/purview-sourcegenerator-diagnostics/SKILL.md", - "computedHash": "28e30ecfc0ce5822bf2564baec17c224f796d169fdda2eeaa9ebaa85c35f0cd3" + "computedHash": "751a6feac6487bb70dba6ceb9b8bfb7201bae9e3733e1634df7dea443fe4f6a1" }, "purview-sourcegenerator-packaging": { "source": "purview-dev/sourcegenerator-framework", + "commit": "7f501f0add05eb0dfb78fda33034b4cde3acd9b4", "sourceType": "github", "skillPath": "skills/purview-sourcegenerator-packaging/SKILL.md", - "computedHash": "42557df2c8536ed0287535b69ffbd75b7c1048cdf0bcae780b4860efd898a109" + "computedHash": "6044272af5982bbf9750a198ca8094c17106579de36dc259712cedc166b7b2fb" }, "purview-sourcegenerator-pipeline": { "source": "purview-dev/sourcegenerator-framework", + "commit": "7f501f0add05eb0dfb78fda33034b4cde3acd9b4", "sourceType": "github", "skillPath": "skills/purview-sourcegenerator-pipeline/SKILL.md", - "computedHash": "7d48394d7e3890f288949c79f040646207f34af9ae85827a63d056bae1b1b985" + "computedHash": "62835d55eab1ccf233241796d34d17bfd7b2fbe4be03424bf9a3a40d8ad2e6a7" }, "purview-sourcegenerator-testing": { "source": "purview-dev/sourcegenerator-framework", + "commit": "7f501f0add05eb0dfb78fda33034b4cde3acd9b4", "sourceType": "github", "skillPath": "skills/purview-sourcegenerator-testing/SKILL.md", - "computedHash": "f49d29eecbfe3153b71cbf530d8c0d6a449ee7605ccd11afb4236c219e98a97d" + "computedHash": "027d6eb1b63783635b9000acd72ec4c3d06e129fed742e7b71a79fe7535040ed" }, "purview-sourcegenerator-tunit-tests": { "source": "purview-dev/sourcegenerator-framework", + "commit": "7f501f0add05eb0dfb78fda33034b4cde3acd9b4", "sourceType": "github", "skillPath": "skills/purview-sourcegenerator-tunit-tests/SKILL.md", - "computedHash": "5b801f9bf792f2ae0baeb2a3835680b9f95dbaed2e57ced43815449e64e19132" + "computedHash": "29f966d9331a556bc3a7d5aa8ad8fe7b1a9091557d629e9c23f65ebd14e3aee7" }, "site-validation-loop": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/site-validation-loop/SKILL.md", - "computedHash": "9d62878fcd457bad46f00d4dc55625ab379551ef1ea3103de90ddc911af8b223" + "computedHash": "cee0c49a7737b88f2367a4a3052c19584dbf12da639cf22f110942be8fa44284" }, "use-case-authoring": { - "source": "purview-dev/purview-dev", + "source": "purview-dev/purview-dev.github.io", + "commit": "d5781703015417762242417d0a17fa8799053aed", "sourceType": "github", "skillPath": "skills/use-case-authoring/SKILL.md", - "computedHash": "078f2b4df03c103b6bbae9edd94d1872483bc1dd0a6a46614d1764650607d80b" + "computedHash": "80be02ac4684ebe7bfe28aefcc87bb2682eda96f9fb5140722e6f7df16d05567" } } } diff --git a/skills/purview-resourcekit-authoring/SKILL.md b/skills/purview-resourcekit-authoring/SKILL.md index de73d72..b266293 100644 --- a/skills/purview-resourcekit-authoring/SKILL.md +++ b/skills/purview-resourcekit-authoring/SKILL.md @@ -163,9 +163,9 @@ sealed partial class PostgresDatabaseKit - A disabled parent disables every descendant, and a disabled ancestor never invokes a descendant's `IsResourceEnabled` hook. Siblings are independent. - Child options nest under the parent (`ShopHostKit:Postgres:Database:IsEnabled`). -- A child with no `[InGroup]` inherits its parent's **primary** group. Grouping never changes build order. - An explicit child group whose primary group differs from the parent's warns `SG0039`; the child renders in - its own group unless an Aspire visual parent places it under the parent. +- A child may declare `[InGroup]`; with none it inherits its parent's **primary** group. Grouping never + changes build order. An explicit child group whose primary group differs from the parent's warns `SG0039`; + the child renders in its own group unless an Aspire visual parent places it under the parent. - ResourceKit parentage is composition ownership, not a general dependency, and it does **not** create an Aspire visual parent relationship. Add `WithParentRelationship(Parent.ResourceBuilder)` yourself when you want that. @@ -346,7 +346,11 @@ sealed partial class ApiKit { /* ... */ } - A group class must be `partial`, non-generic and must have no base type: the generator derives it from `ResourceKitGroup` (`SG0025`, `SG0030`). A class is a kit or a group, never both (`SG0031`), and a - parent chain can never loop back (`SG0022`). It must be at least as accessible as the host kit. + parent chain can never loop back (`SG0022`). +- Declare a group at **namespace scope**, never nested inside another class, and give it the **same + accessibility as the host kit** (`SG0045`, `SG0046`). The generator emits the group beside the host kit as + a second partial declaration, so a nested group's `*Options` path no longer resolves, and an accessibility + mismatch surfaces as CS9338/CS0051 (`public` group, `internal` host kit) or CS0053 (the inverse). - In run mode, at the end of `Configure`, each group with a built kit is added as a `ResourceKitGroupResource` node, named after the group, or `-group` when a resource already has that name. The node is excluded from the manifest. A kit whose resource already has a parent (its own diff --git a/skills/purview-resourcekit-diagnostics/SKILL.md b/skills/purview-resourcekit-diagnostics/SKILL.md index 7a24acc..e8441ad 100644 --- a/skills/purview-resourcekit-diagnostics/SKILL.md +++ b/skills/purview-resourcekit-diagnostics/SKILL.md @@ -70,6 +70,8 @@ assigned. | `SG0042` | Warning | `ProjectPath` and `ResourcePath` declare different paths; `ResourcePath` is used, so one must be fixed or removed. | | `SG0043` | Warning | `ResourcePath` is set on a resource that is not added by path, so it is ignored. | | `SG0044` | Info | A `BuildResource` override only calls `AddDotnetProject`/`AddViteApp`/`AddNextJsApp` with `Name` and the path, which ResourceKit generates. The code fix removes it, first moving the path into `ProjectPath`/`ResourcePath` when the attribute has none. | +| `SG0045` | Error | A `[ResourceGroup]` class is nested in another type; it must be declared at namespace scope. | +| `SG0046` | Error | A `[ResourceGroup]` class and its host kit are declared with different accessibility. | `SG0018` applies only to a hand-written `BuildResource`. A `DotnetProjectResource`, `ViteAppResource` or `NextJsAppResource` kit that declares its path and writes no override gets the registration generated. @@ -99,6 +101,7 @@ Only the Error-severity rules block generation. 3. Are the generated property names unique? 4. Does each resource use one attribute style, with a matching base? 5. Is `Name` set where inference cannot determine it? +6. Is every `[ResourceGroup]` class at namespace scope, with the same accessibility as the host kit? ## Common fixes @@ -140,7 +143,7 @@ sealed partial class SqlServerKit } ``` -### `SG0021`–`SG0031` — groups and URLs +### `SG0021`–`SG0031`, `SG0045`–`SG0046` — groups and URLs - `SG0021`: the type in `[InGroup]`, or in `Parent = typeof(T)`, must be a `[ResourceGroup]` class declared in the same project. @@ -152,6 +155,12 @@ sealed partial class SqlServerKit `[EndpointUrl("https")]` also collide. - `SG0027` / `SG0028`: a group, or a kit for a resource without endpoints such as a `ParameterResource`, can only show an **absolute** URL. +- `SG0045` / `SG0046`: the group class is a second partial declaration of a class the generator completes, + emitted beside the host kit. Declare it at **namespace scope** (a nested group loses its containing types + and its `*Options` path stops resolving — CS0426) and with the **same accessibility as the host kit**: a + `public` group under an `internal` host kit derives from a less accessible base (CS9338/CS0051), and an + `internal` group under a `public` host kit is exposed by the host kit's public `Groups` accessor (CS0053). + Both are errors, and both block generation, so no generated code is emitted to fail in their place. ### `SG0032`–`SG0038` — parent/child hierarchies diff --git a/src/src/ResourceKit/Sdk/README.md b/src/src/ResourceKit/Sdk/README.md index d2925eb..59f5079 100644 --- a/src/src/ResourceKit/Sdk/README.md +++ b/src/src/ResourceKit/Sdk/README.md @@ -123,6 +123,13 @@ ownership, not a general dependency or an automatic Aspire visual parent relatio `:Groups:`, which applies to every kit in it. In run mode each group appears as a dashboard node with its kits nested underneath. +The group class must be declared **at namespace scope** and with the **same accessibility as the host +kit** (SG0045, SG0046). It is a second partial declaration the generator completes, emitted beside the +host kit: a nested group loses its containing types (CS0426), a `public` group under an `internal` host +kit derives from a less accessible base (CS9338), and an `internal` group under a `public` host kit is +exposed by the host kit's public `Groups` accessor (CS0053). Both rules are reported against the +declaration instead. + `[ResourceUrl(name, url)]` adds a named dashboard URL: absolute, or relative to an endpoint. `[EndpointUrl(endpoint)]` renames an endpoint's own URL. Each URL becomes a `ResourceKitUrl` option under `::Urls:`. diff --git a/src/src/SourceGeneration/AnalyzerReleases.Shipped.md b/src/src/SourceGeneration/AnalyzerReleases.Shipped.md index ae110e3..79e8e83 100644 --- a/src/src/SourceGeneration/AnalyzerReleases.Shipped.md +++ b/src/src/SourceGeneration/AnalyzerReleases.Shipped.md @@ -1,9 +1,19 @@ +## Release 2.2.3 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|------- +SG0044 | Purview.Aspire.ResourceKit.SourceGenerator | Info | BuildResource only adds the declared path +SG0045 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Resource group must be declared at namespace scope +SG0046 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Resource group accessibility differs from its host kit + ## Release 2.1.0 ### New Rules Rule ID | Category | Severity | Notes ---------|----------|----------|------ +--------|----------|----------|------- SG0041 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | ProjectPath requires a DotnetProjectResource SG0042 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | ProjectPath and ResourcePath conflict SG0043 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | ResourcePath requires a path-based resource @@ -13,7 +23,7 @@ SG0043 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | ResourcePath req ### New Rules Rule ID | Category | Severity | Notes ---------|----------|----------|------ +--------|----------|----------|------- SG0021 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Type is not a resource group SG0022 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Resource group parent cycle SG0023 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Duplicate resource group name @@ -41,22 +51,22 @@ SG0040 | Purview.Aspire.ResourceKit.SourceGenerator | Info | Resource kit is alr Rule ID | Category | Severity | Notes | --------|----------|----------|-------------------- - SG0001 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Class must be partial - SG0002 | Purview.Aspire.ResourceKit.SourceGenerator | Info | No host resources defined - SG0003 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | No host app info defined - SG0004 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Multiple host apps defined - SG0005 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Duplicate resource property name - SG0006 | Purview.Aspire.ResourceKit.SourceGenerator | Error | App resource must derive from generated base - SG0007 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Resource name could not be determined - SG0008 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Invalid property name - SG0009 | Purview.Aspire.ResourceKit.SourceGenerator | Error | IServiceCollection type missing - SG0010 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Configuration binder type missing - SG0011 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Options configuration extension method missing - SG0012 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Non-empty constructors are not supported - SG0013 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Mixed ResourceDefinition attribute usage is not supported - SG0014 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Non-generic ResourceDefinition requires explicit base - SG0015 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Generic ResourceDefinition cannot have explicit base - SG0016 | Purview.Aspire.ResourceKit.SourceGenerator | Error | No Aspire resource found + SG0001 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Class must be partial + SG0002 | Purview.Aspire.ResourceKit.SourceGenerator | Info | No host resources defined + SG0003 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | No host app info defined + SG0004 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Multiple host apps defined + SG0005 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Duplicate resource property name + SG0006 | Purview.Aspire.ResourceKit.SourceGenerator | Error | App resource must derive from generated base + SG0007 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Resource name could not be determined + SG0008 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Invalid property name + SG0009 | Purview.Aspire.ResourceKit.SourceGenerator | Error | IServiceCollection type missing + SG0010 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Configuration binder type missing + SG0011 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Options configuration extension method missing + SG0012 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Non-empty constructors are not supported + SG0013 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Mixed ResourceDefinition attribute usage is not supported + SG0014 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Non-generic ResourceDefinition requires explicit base + SG0015 | Purview.Aspire.ResourceKit.SourceGenerator | Error | Generic ResourceDefinition cannot have explicit base + SG0016 | Purview.Aspire.ResourceKit.SourceGenerator | Error | No Aspire resource found SG0017 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | Resource property is never set SG0018 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | Project resource definition mismatch SG0019 | Purview.Aspire.ResourceKit.SourceGenerator | Warning | Project resource kit base must use ProjectResource diff --git a/src/src/SourceGeneration/AnalyzerReleases.Unshipped.md b/src/src/SourceGeneration/AnalyzerReleases.Unshipped.md index 78bf96d..e69de29 100644 --- a/src/src/SourceGeneration/AnalyzerReleases.Unshipped.md +++ b/src/src/SourceGeneration/AnalyzerReleases.Unshipped.md @@ -1,5 +0,0 @@ -### New Rules - -Rule ID | Category | Severity | Notes ---------|----------|----------|------ -SG0044 | Purview.Aspire.ResourceKit.SourceGenerator | Info | BuildResource only adds the declared path diff --git a/src/src/SourceGeneration/Helpers/DiagnosticLibrary.cs b/src/src/SourceGeneration/Helpers/DiagnosticLibrary.cs index f632bbd..9d9a099 100644 --- a/src/src/SourceGeneration/Helpers/DiagnosticLibrary.cs +++ b/src/src/SourceGeneration/Helpers/DiagnosticLibrary.cs @@ -428,4 +428,24 @@ static class DiagnosticLibrary isEnabledByDefault: true, description: "A class is either a resource kit, which joins groups with [InGroup], or a resource group, which nests under a parent group. One class cannot be both, so a group can never contain itself as a member." ); + + public static readonly DiagnosticDescriptor ResourceGroupMustBeTopLevel = new( + id: "SG0045", + title: "Resource group must be declared at namespace scope", + messageFormat: "The resource group '{0}' is nested in '{1}'; declare the group at namespace scope", + category: Category, + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: "The generator emits the group class, and its nested options class, beside the host kit rather than inside the declaring type, so a group nested in another type is emitted without its containing types while its options are referenced through them. Move the group class to namespace scope." + ); + + public static readonly DiagnosticDescriptor ResourceGroupAccessibilityMismatch = new( + id: "SG0046", + title: "Resource group accessibility differs from its host kit", + messageFormat: "The resource group '{0}' is {1}, but the host kit '{2}' is {3}; declare the group with the same accessibility as its host kit", + category: Category, + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: "A group derives from ResourceKitGroup, and the host kit exposes it through public members of types nested in the host kit, so the two declarations must have the same accessibility: a public group paired with an internal host kit derives from a less accessible base, and an internal group paired with a public host kit is exposed by a more accessible member." + ); } diff --git a/src/src/SourceGeneration/Helpers/ResourceKitRules.cs b/src/src/SourceGeneration/Helpers/ResourceKitRules.cs index 7a7b17a..a468dd6 100644 --- a/src/src/SourceGeneration/Helpers/ResourceKitRules.cs +++ b/src/src/SourceGeneration/Helpers/ResourceKitRules.cs @@ -58,7 +58,9 @@ static class ResourceKitRules DiagnosticLibrary.ResourceKitParentCycle.Id, DiagnosticLibrary.ResourceKitParentNotResourceKit.Id, DiagnosticLibrary.ResourceKitParentUnavailable.Id, - DiagnosticLibrary.DuplicateResourceKitChildPropertyName.Id + DiagnosticLibrary.DuplicateResourceKitChildPropertyName.Id, + DiagnosticLibrary.ResourceGroupMustBeTopLevel.Id, + DiagnosticLibrary.ResourceGroupAccessibilityMismatch.Id ); /// @@ -738,6 +740,21 @@ CancellationToken cancellationToken ); } + // The group is emitted beside the host kit, so it cannot carry the containing types the declaring + // path implies. Report the placement rather than let the generated code fail with CS0426/CS9338. + // A group nested in a generic type is SG0030's case instead; one message per cause is enough. + if (symbol.ContainingType is { } containingType && !IsGenericOrInGenericType(symbol)) + { + diagnostics.Add( + new( + DiagnosticLibrary.ResourceGroupMustBeTopLevel, + IsBlocking: true, + GetGroupDeclarationLocation(symbol, cancellationToken) ?? declaration.Identifier.GetLocation(), + [symbol.Name, containingType.ToDisplayString()] + ) + ); + } + // A group is never a member of anything, itself included: groups nest through their parent only. if ( TypeHelpers.HasAttribute(symbol, TypeLibrary.Purview.Aspire.ResourceKit.ResourceDefinitionAttribute) @@ -1104,6 +1121,86 @@ public static string GroupPropertyName(INamedTypeSymbol symbol) => public static string GroupName(INamedTypeSymbol symbol) => ResourceGroupAttributeData.FromAttributeData(symbol.GetAttributes()).Name ?? GroupPropertyName(symbol); + /// + /// Gets the location of the [ResourceGroup] application on , so a + /// placement diagnostic points at the declaration the user wrote rather than at emitted code. + /// + public static Location? GetGroupDeclarationLocation(INamedTypeSymbol symbol, CancellationToken cancellationToken) => + symbol + .GetAttributes() + .Where(IsResourceGroupAttribute) + .Select(attribute => GetLocation(attribute, cancellationToken)) + .FirstOrDefault(static location => location is not null); + + /// + /// Compares the accessibility a resource group is emitted with against the accessibility of the host + /// kit it derives from, and returns the mismatch rule when the two differ. + /// + /// + /// The generated group derives from ResourceKitGroup<THostKit>, and the host kit exposes it + /// through members emitted on types nested in the host kit. Both relationships carry the accessibility + /// of the type they mention, so the declarations must match: a public group paired with an internal + /// host kit fails with CS9338/CS0051, and an internal group paired with a public host kit fails with + /// CS0053. The generated group copies the declared modifier because it is a second partial + /// declaration, so the generator cannot correct the pairing itself. + /// + public static RuleEvaluation? EvaluateGroupHostKitAccessibility( + TypeDeclarationAccessibility? groupAccessibility, + TypeDeclarationAccessibility? hostKitAccessibility, + string groupName, + string hostKitName, + Location? location + ) + { + // A declaration without a modifier is internal at namespace scope, which is what the generator emits. + var group = groupAccessibility ?? TypeDeclarationAccessibility.Internal; + var hostKit = hostKitAccessibility ?? TypeDeclarationAccessibility.Internal; + if (group == hostKit) + return null; + + return new( + DiagnosticLibrary.ResourceGroupAccessibilityMismatch, + IsBlocking: true, + location ?? Location.None, + [groupName, AccessibilityText(group), hostKitName, AccessibilityText(hostKit)] + ); + } + + /// + /// Compares a resource group with the host kit it belongs to, from their symbols. + /// + /// + /// A nested group is SG0045's case, and its effective accessibility comes from its containing types, so + /// it is left to that rule rather than reported twice. + /// + public static RuleEvaluation? EvaluateGroupHostKitAccessibility( + INamedTypeSymbol group, + INamedTypeSymbol hostKit, + CancellationToken cancellationToken + ) => + group.ContainingType is not null || IsGenericOrInGenericType(group) + ? null + : EvaluateGroupHostKitAccessibility( + group.DeclaredAccessibility.ToTypeDeclarationAccessibility(), + hostKit.DeclaredAccessibility.ToTypeDeclarationAccessibility(), + GroupName(group), + hostKit.Name, + GetGroupDeclarationLocation(group, cancellationToken) ?? GetLocation(group) + ); + + static string AccessibilityText(TypeDeclarationAccessibility accessibility) => + accessibility switch + { + TypeDeclarationAccessibility.Public => "public", + TypeDeclarationAccessibility.Internal => "internal", + TypeDeclarationAccessibility.Protected => "protected", + TypeDeclarationAccessibility.ProtectedInternal => "protected internal", + TypeDeclarationAccessibility.PrivateProtected => "private protected", + TypeDeclarationAccessibility.Private => "private", + TypeDeclarationAccessibility.File => "file", + _ => "internal", + }; + /// /// Determines whether a group's parent chain leads back to the group itself. /// diff --git a/src/src/SourceGeneration/Helpers/SourceGenLibrary.cs b/src/src/SourceGeneration/Helpers/SourceGenLibrary.cs index 8881e36..389dc97 100644 --- a/src/src/SourceGeneration/Helpers/SourceGenLibrary.cs +++ b/src/src/SourceGeneration/Helpers/SourceGenLibrary.cs @@ -79,7 +79,14 @@ .. groups ) .CombineWith( resourceGroups, - static (model, groups, _) => model with { ResourceGroups = groups }, + static (model, groups, _) => + model with + { + ResourceGroups = groups, + // Evaluated here because only the pair decides whether a group can be emitted, and only + // now are the host kit and its groups both known. + HierarchyDiagnostics = WithGroupAccessibilityDiagnostics(model, groups), + }, GeneratorTrackingNames.CollectResourceGroups ); @@ -157,6 +164,47 @@ ImmutableArray models return ReportableDiagnostic.Create(finding.Descriptor, isBlocking: true, location, [.. finding.MessageArgs]); } + /// + /// Appends the accessibility rules that compare each resource group with the host kit it is emitted + /// beside, keeping the hierarchy diagnostics already gathered. + /// + /// + /// A nested group is SG0045's case and has no single accessibility to compare, so it is skipped here. + /// + static EquatableArray WithGroupAccessibilityDiagnostics( + KitGenerationModel model, + EquatableArray> groups + ) + { + if (model.HostKit.IsEmpty || groups.IsEmpty) + return model.HierarchyDiagnostics; + + var hostKit = model.HostKit.Value; + List diagnostics = [.. model.HierarchyDiagnostics]; + foreach (var group in groups) + { + var groupModel = group.Value; + if ( + groupModel.GroupType.IsNested + || ResourceKitRules.EvaluateGroupHostKitAccessibility( + groupModel.Accessibility, + hostKit.Accessibility, + groupModel.Name, + hostKit.HostKitType.Name, + groupModel.Location.IsEmpty ? Location.None : groupModel.Location.ToLocation() + ) + is not { } rule + ) + { + continue; + } + + diagnostics.Add(rule.ToDiagnosticInfo()); + } + + return EquatableArray.Create([.. diagnostics]); + } + // A warning, not an error: an explicit child group is allowed, but it silently changes visual placement. // A child with no [InGroup] inherits the parent's primary group and never reaches this check. static ImmutableArray EvaluateChildGroupDiagnostics(ImmutableArray models) @@ -374,7 +422,10 @@ CancellationToken cancellationToken PropertyName: ResourceKitRules.GroupPropertyName(symbol), ShowInDashboard: data.ShowInDashboard, Mode: data.Mode, - Urls: GetUrlModels(symbol) + Urls: GetUrlModels(symbol), + Location: SourceLocationModel.From( + ResourceKitRules.GetGroupDeclarationLocation(symbol, cancellationToken) + ) ), diagnostics ); diff --git a/src/src/SourceGeneration/Models/KitGenerationModels.cs b/src/src/SourceGeneration/Models/KitGenerationModels.cs index 8ed5a27..33e1a7f 100644 --- a/src/src/SourceGeneration/Models/KitGenerationModels.cs +++ b/src/src/SourceGeneration/Models/KitGenerationModels.cs @@ -34,8 +34,10 @@ EquatableArray Diagnostics EquatableArray>.Empty; /// - /// Diagnostics raised by the ownership graph once every resource kit is known: self-parenting, cycles, - /// unknown parents, and duplicate child property names. + /// Diagnostics raised once the whole composition is known, which the per-symbol transforms cannot + /// decide alone: the ownership graph (self-parenting, cycles, unknown parents, duplicate child property + /// names), a child kit whose primary group differs from its parent's, and a group whose accessibility + /// does not match its host kit. /// public EquatableArray HierarchyDiagnostics { get; init; } = EquatableArray.Empty; @@ -205,7 +207,9 @@ readonly record struct ResourceGroupModel( string PropertyName, bool ShowInDashboard, string? Mode, - EquatableArray Urls + EquatableArray Urls, + // The [ResourceGroup] application, so a diagnostic discovered once the host kit is known points at it. + SourceLocationModel Location ) { public bool HasParent => ParentType != TypeIdentity.Empty; diff --git a/src/src/SourceGeneration/ResourceKitDiagnosticAnalyzer.cs b/src/src/SourceGeneration/ResourceKitDiagnosticAnalyzer.cs index 33399a9..8cd599d 100644 --- a/src/src/SourceGeneration/ResourceKitDiagnosticAnalyzer.cs +++ b/src/src/SourceGeneration/ResourceKitDiagnosticAnalyzer.cs @@ -51,6 +51,8 @@ public sealed class ResourceKitDiagnosticAnalyzer : DiagnosticAnalyzer DiagnosticLibrary.ResourceKitParentNotResourceKit, DiagnosticLibrary.ResourceKitParentUnavailable, DiagnosticLibrary.DuplicateResourceKitChildPropertyName, + DiagnosticLibrary.ResourceGroupMustBeTopLevel, + DiagnosticLibrary.ResourceGroupAccessibilityMismatch, ]; public override void Initialize(AnalysisContext context) @@ -123,7 +125,7 @@ public override void Initialize(AnalysisContext context) compilationStartContext.RegisterCompilationEndAction(compilationEndContext => { ReportCompilationRules(compilationEndContext, hostKits, resourceKits); - ReportGroupCompilationRules(compilationEndContext, resourceGroups); + ReportGroupCompilationRules(compilationEndContext, resourceGroups, hostKits); }); }); } @@ -249,10 +251,12 @@ static void ReportHierarchyRules(CompilationAnalysisContext context, INamedTypeS // name is a member of the generated Groups accessor, which C# compares ordinally. static void ReportGroupCompilationRules( CompilationAnalysisContext context, - ConcurrentBag resourceGroups + ConcurrentBag resourceGroups, + ConcurrentBag hostKits ) { var groups = resourceGroups.ToArray(); + ReportGroupAccessibilityRules(context, groups, hostKits); var duplicates = groups .GroupBy(ResourceKitRules.GroupName, StringComparer.OrdinalIgnoreCase) @@ -279,6 +283,31 @@ ConcurrentBag resourceGroups } } + // A group is emitted beside the host kit and copies its declared accessibility, so the pair must match: + // the generated class derives from ResourceKitGroup and is exposed by members the generator + // adds to types nested in the host kit. One host kit is required to know which accessibility to compare. + static void ReportGroupAccessibilityRules( + CompilationAnalysisContext context, + INamedTypeSymbol[] groups, + ConcurrentBag hostKits + ) + { + var hostKitArray = hostKits.ToArray(); + if (hostKitArray.Length != 1) + return; + + foreach (var group in groups) + { + if ( + ResourceKitRules.EvaluateGroupHostKitAccessibility(group, hostKitArray[0], context.CancellationToken) is + { } rule + ) + { + context.ReportDiagnostic(rule.ToDiagnostic()); + } + } + } + static Location? GetLocation(ISymbol symbol) => symbol.Locations.FirstOrDefault(static location => location.IsInSource); } diff --git a/src/tests/SourceGeneration.IntegrationTests/GeneratorCachingTests.cs b/src/tests/SourceGeneration.IntegrationTests/GeneratorCachingTests.cs index 127d627..0d2932c 100644 --- a/src/tests/SourceGeneration.IntegrationTests/GeneratorCachingTests.cs +++ b/src/tests/SourceGeneration.IntegrationTests/GeneratorCachingTests.cs @@ -58,16 +58,16 @@ CancellationToken cancellationToken [ .. TestHelper.GenerateSources(), """ - namespace Testing.Groups; + namespace Testing.Groups; - // TestHelper's host kit is public, and a group must be at least as accessible as its host kit. - [ResourceGroup] - [ResourceUrl("Runbook", "https://example.com/runbook")] - public partial class PlatformGroup; + // TestHelper's host kit is public, and a group must be at least as accessible as its host kit. + [ResourceGroup] + [ResourceUrl("Runbook", "https://example.com/runbook")] + public partial class PlatformGroup; - [ResourceGroup(Parent = typeof(PlatformGroup))] - public partial class DataGroup; - """, + [ResourceGroup(Parent = typeof(PlatformGroup))] + public partial class DataGroup; + """, ]; // Act & Assert diff --git a/src/tests/SourceGeneration.IntegrationTests/Golden/ResourceGroup.InternalTopLevelGroup.g.cs.txt b/src/tests/SourceGeneration.IntegrationTests/Golden/ResourceGroup.InternalTopLevelGroup.g.cs.txt new file mode 100644 index 0000000..1cb3e5d --- /dev/null +++ b/src/tests/SourceGeneration.IntegrationTests/Golden/ResourceGroup.InternalTopLevelGroup.g.cs.txt @@ -0,0 +1,62 @@ + internal sealed partial class DataGroup : global::Purview.Aspire.ResourceKit.ResourceKitGroup + { + /// + /// Initializes a new instance of the resource group. + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Runtime.CompilerServices.CompilerGenerated] + [global::System.CodeDom.Compiler.GeneratedCode("HostKitGenerator", "")] + public DataGroup( + global::Testing.DataGroup.DataGroupOptions options, + global::Purview.Aspire.ResourceKit.ResourceKitGroup? parent + ) + : base("data", parent) + { + Options = options ?? throw new global::System.ArgumentNullException(nameof(options)); + IsEnabled = options.IsEnabled; + Mode = options.Mode; + ShowInDashboard = options.ShowInDashboard; + } + + /// + /// Gets the resource group options. + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Runtime.CompilerServices.CompilerGenerated] + [global::System.CodeDom.Compiler.GeneratedCode("HostKitGenerator", "")] + public global::Testing.DataGroup.DataGroupOptions Options { get; } + + /// + /// Typed settings for . + /// Can be accessed by resolving . + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Runtime.CompilerServices.CompilerGenerated] + [global::System.CodeDom.Compiler.GeneratedCode("HostKitGenerator", "")] + public sealed partial class DataGroupOptions + { + /// + /// Gets or sets whether the group, and so every resource in it, is enabled. + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Runtime.CompilerServices.CompilerGenerated] + [global::System.CodeDom.Compiler.GeneratedCode("HostKitGenerator", "")] + public bool IsEnabled { get; set; } = true; + + /// + /// Gets or sets the execution mode in which the group, and so every resource in it, participates. + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Runtime.CompilerServices.CompilerGenerated] + [global::System.CodeDom.Compiler.GeneratedCode("HostKitGenerator", "")] + public global::Purview.Aspire.ResourceKit.ResourceKitMode Mode { get; set; } = global::Purview.Aspire.ResourceKit.ResourceKitMode.All; + + /// + /// Gets or sets whether the group is shown as a node in the dashboard. + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Runtime.CompilerServices.CompilerGenerated] + [global::System.CodeDom.Compiler.GeneratedCode("HostKitGenerator", "")] + public bool ShowInDashboard { get; set; } = false; + } + } \ No newline at end of file diff --git a/src/tests/SourceGeneration.IntegrationTests/RedundantBuildResourceAnalyzerTests.cs b/src/tests/SourceGeneration.IntegrationTests/RedundantBuildResourceAnalyzerTests.cs index 7ba73b9..7c27307 100644 --- a/src/tests/SourceGeneration.IntegrationTests/RedundantBuildResourceAnalyzerTests.cs +++ b/src/tests/SourceGeneration.IntegrationTests/RedundantBuildResourceAnalyzerTests.cs @@ -49,20 +49,19 @@ static ResourceKitSourceGeneratorTestOptions CreateOptions() }; } - static string DotnetKit(string attributeArguments, string body) => - $$""" - namespace Testing - { - [HostKit] - partial class TestingHostKit; + static string DotnetKit(string attributeArguments, string body) => $$""" + namespace Testing + { + [HostKit] + partial class TestingHostKit; - [ResourceDefinition<{{DotnetProject}}>({{attributeArguments}})] - sealed partial class ApiKit - { - {{body}} - } + [ResourceDefinition<{{DotnetProject}}>({{attributeArguments}})] + sealed partial class ApiKit + { + {{body}} } - """; + } + """; [Test] public async Task Analyze_GivenOverrideRepeatingProjectPath_ReportsRedundantBuildResource( diff --git a/src/tests/SourceGeneration.IntegrationTests/ResourceGroupPlacementTests.cs b/src/tests/SourceGeneration.IntegrationTests/ResourceGroupPlacementTests.cs new file mode 100644 index 0000000..d1afee3 --- /dev/null +++ b/src/tests/SourceGeneration.IntegrationTests/ResourceGroupPlacementTests.cs @@ -0,0 +1,300 @@ +using Microsoft.CodeAnalysis; +using Purview.Aspire.ResourceKit.SourceGeneration.Helpers; + +namespace Purview.Aspire.ResourceKit.SourceGeneration; + +/// +/// Verifies where a [ResourceGroup] class may be declared (SG0045) and how its accessibility must +/// pair with the host kit's (SG0046). The generated group copies the declared modifier as a second partial +/// declaration and is always emitted beside the host kit, so neither problem can be corrected in generated +/// code: each is reported against the declaration instead of surfacing as CS0426/CS9338/CS0053. +/// +public sealed class ResourceGroupPlacementTests : ResourceKitSourceGeneratorTestBase +{ + const string Kit = """ + protected override IResourceBuilder BuildResource(IDistributedApplicationBuilder builder) => + throw new global::System.NotImplementedException(); + """; + + [Test] + public async Task Generate_GivenGroupNestedInAContainer_ReportsResourceGroupMustBeTopLevel( + CancellationToken cancellationToken + ) + { + // Arrange + const string source = """ + namespace Testing; + + static class ResourceNames + { + public static class Groups + { + [ResourceGroup("Services")] + public sealed partial class Services; + } + } + + [HostKit] + sealed partial class TestingHostKit; + + [ResourceDefinition("api")] + [InGroup] + sealed partial class ApiKit; + """; + + // Act + using var result = await GenerateAsync( + source, + ResourceKitSourceGeneratorTestOptions.NoValidation, + cancellationToken + ); + + // Assert — one actionable diagnostic on the attribute, and nothing generated to fail in its place. + await Assert + .That((result.AnalyzerResult?.Diagnostics ?? []).Select(static d => d.Id)) + .IsEquivalentTo([DiagnosticLibrary.ResourceGroupMustBeTopLevel.Id]); + await Assert.That(result).HasDiagnostics(DiagnosticLibrary.ResourceGroupMustBeTopLevel, 1); + await Assert.That(result).DoesNotHaveDiagnostic(DiagnosticLibrary.ResourceGroupAccessibilityMismatch); + await Assert + .That(Reporting(result, DiagnosticLibrary.ResourceGroupMustBeTopLevel)) + .IsEquivalentTo(["ResourceGroup(\"Services\")"]); + await Assert.That(result.DriverResult.GeneratedTrees.Length).IsEqualTo(ExpectedGeneratedFileCount); + } + + [Test] + public async Task Generate_GivenGroupNestedInAnInternalContainer_ReportsOnlyThePlacementRule( + CancellationToken cancellationToken + ) + { + // Arrange — the group's effective accessibility is internal, so the host kit pairing is not a + // second problem; the placement is. + const string source = """ + namespace Testing; + + static class ResourceNames + { + [ResourceGroup] + internal sealed partial class Services; + } + + [HostKit] + sealed partial class TestingHostKit; + """; + + // Act + using var result = await GenerateAsync( + source, + ResourceKitSourceGeneratorTestOptions.NoValidation, + cancellationToken + ); + + // Assert + await Assert.That(result).HasDiagnostics(DiagnosticLibrary.ResourceGroupMustBeTopLevel, 1); + await Assert.That(result).DoesNotHaveDiagnostic(DiagnosticLibrary.ResourceGroupAccessibilityMismatch); + } + + [Test] + public async Task Generate_GivenPublicGroupWithAnInternalHostKit_ReportsAccessibilityMismatch( + CancellationToken cancellationToken + ) + { + // Arrange + const string source = """ + namespace Testing; + + [HostKit] + sealed partial class TestingHostKit; + + [ResourceGroup] + public sealed partial class DataGroup; + """; + + // Act + using var result = await GenerateAsync( + source, + ResourceKitSourceGeneratorTestOptions.NoValidation, + cancellationToken + ); + + // Assert + await Assert.That(result).HasDiagnostics(DiagnosticLibrary.ResourceGroupAccessibilityMismatch, 1); + await Assert + .That(Reporting(result, DiagnosticLibrary.ResourceGroupAccessibilityMismatch)) + .IsEquivalentTo(["ResourceGroup"]); + await Assert.That(result.DriverResult.GeneratedTrees.Length).IsEqualTo(ExpectedGeneratedFileCount); + } + + [Test] + public async Task Generate_GivenInternalGroupWithAPublicHostKit_ReportsAccessibilityMismatch( + CancellationToken cancellationToken + ) + { + // Arrange — the inverse pairing: the public host kit would expose an internal group through its + // public Groups accessor, which is also a compile error (CS0053). + const string source = """ + namespace Testing; + + [HostKit] + public sealed partial class TestingHostKit; + + [ResourceGroup] + sealed partial class DataGroup; + """; + + // Act + using var result = await GenerateAsync( + source, + ResourceKitSourceGeneratorTestOptions.NoValidation, + cancellationToken + ); + + // Assert + await Assert.That(result).HasDiagnostics(DiagnosticLibrary.ResourceGroupAccessibilityMismatch, 1); + await Assert.That(result.DriverResult.GeneratedTrees.Length).IsEqualTo(ExpectedGeneratedFileCount); + } + + [Test] + public async Task Generate_GivenChildKitWithNoGroup_RegistersItWithoutAGroup(CancellationToken cancellationToken) + { + // Arrange — a child with no [InGroup] is registered with no group and inherits the parent's primary + // group when the host seals its resources, so the generator must not warn (SG0039) about it. + var source = $$""" + namespace Testing; + + [HostKit] + partial class TestingHostKit; + + [ResourceGroup] + sealed partial class DataGroup; + + [ResourceDefinition("parent")] + [InGroup] + sealed partial class ParentKit + { + {{Kit}} + } + + [ResourceDefinition("child", Parent = typeof(ParentKit))] + sealed partial class ChildKit + { + {{Kit}} + } + """; + + // Act + using var result = await GenerateAsync(source, cancellationToken); + + // Assert + await Assert.That(result).HasNoErrorDiagnostics(); + await Assert.That(result).DoesNotHaveDiagnostic(DiagnosticLibrary.ResourceKitChildGroupDiffersFromParent); + + var generated = result.GetSource(); + await Assert.That(generated).Contains("AddResource(Parent, Groups.Data);"); + await Assert.That(generated).Contains("AddResource(Parent.Child);"); + } + + [Test] + public async Task Generate_GivenInternalGroupWithAnInternalHostKit_EmitsTheGroupUnchanged( + CancellationToken cancellationToken + ) + { + // Arrange — the shape every existing composition uses. The emitted group, and its options, are + // pinned so a change to the emission shows up as a diff rather than passing unnoticed. + const string source = """ + namespace Testing; + + [HostKit] + partial class TestingHostKit; + + [ResourceGroup("data", ShowInDashboard = false)] + sealed partial class DataGroup; + """; + + // Act + using var result = await GenerateAsync(source, cancellationToken); + + // Assert + await Assert.That(result).HasNoErrorDiagnostics(); + await Assert + .That(GeneratedGroup(result.GetSource(), "DataGroup")) + .IsEqualTo(await ReadGoldenAsync("ResourceGroup.InternalTopLevelGroup.g.cs.txt", cancellationToken)); + } + + // The source text each diagnostic points at, which for a group rule is the attribute or the declaration. + static string[] Reporting(DriverRunResult result, DiagnosticDescriptor descriptor) => + [ + .. (result.AnalyzerResult?.Diagnostics ?? []) + .Where(d => d.Id == descriptor.Id && d.Location.SourceTree is not null) + .Select(static d => d.Location.SourceTree!.GetText().ToString(d.Location.SourceSpan)) + .Order(StringComparer.Ordinal), + ]; + + // The emitted group declaration, from its first line to its matching closing brace, with the generator + // version stamp normalised so the golden text does not change with every commit. + static string GeneratedGroup(string generated, string groupName) + { + var normalized = NormalizeVersionStamp(generated); + var lines = normalized.Split('\n'); + var start = Array.FindIndex(lines, line => + line.Contains($" partial class {groupName} :", StringComparison.Ordinal) + ); + if (start < 0) + throw new InvalidOperationException($"The generated source does not declare '{groupName}'."); + + List declaration = []; + var depth = 0; + var opened = false; + foreach (var line in lines[start..]) + { + declaration.Add(line); + + foreach (var character in line) + { + if (character == '{') + { + depth++; + opened = true; + } + else if (character == '}') + { + depth--; + } + } + + if (opened && depth == 0) + return string.Join('\n', declaration); + } + + throw new InvalidOperationException($"The generated '{groupName}' declaration is not closed."); + } + + // The checked-in golden, read from the test output directory so a working-tree checkout with CRLF + // compares equal to the generated LF text. + static async Task ReadGoldenAsync(string fileName, CancellationToken cancellationToken) => + ( + await System.IO.File.ReadAllTextAsync( + System.IO.Path.Combine(AppContext.BaseDirectory, "Golden", fileName), + cancellationToken + ) + ).Replace("\r\n", "\n", StringComparison.Ordinal); + + // The emitted stamp is GeneratedCode("HostKitGenerator", "+"). + static string NormalizeVersionStamp(string generated) + { + const string stampStart = "\"HostKitGenerator\", \""; + const string stampEnd = "\")]"; + var index = generated.IndexOf(stampStart, StringComparison.Ordinal); + while (index >= 0) + { + var valueStart = index + stampStart.Length; + var valueEnd = generated.IndexOf(stampEnd, valueStart, StringComparison.Ordinal); + if (valueEnd < 0) + return generated; + + generated = generated[..valueStart] + "" + generated[valueEnd..]; + index = generated.IndexOf(stampStart, valueStart + "".Length, StringComparison.Ordinal); + } + + return generated; + } +} diff --git a/src/tests/SourceGeneration.IntegrationTests/SourceGeneration.IntegrationTests.csproj b/src/tests/SourceGeneration.IntegrationTests/SourceGeneration.IntegrationTests.csproj index cc1639d..85d9346 100644 --- a/src/tests/SourceGeneration.IntegrationTests/SourceGeneration.IntegrationTests.csproj +++ b/src/tests/SourceGeneration.IntegrationTests/SourceGeneration.IntegrationTests.csproj @@ -11,6 +11,11 @@ + + + + + diff --git a/src/tests/SourceGeneration.UnitTests/AnalyzerReleaseTrackingTests.cs b/src/tests/SourceGeneration.UnitTests/AnalyzerReleaseTrackingTests.cs index 5a3f238..9439514 100644 --- a/src/tests/SourceGeneration.UnitTests/AnalyzerReleaseTrackingTests.cs +++ b/src/tests/SourceGeneration.UnitTests/AnalyzerReleaseTrackingTests.cs @@ -18,6 +18,14 @@ public sealed partial class AnalyzerReleaseTrackingTests [GeneratedRegex(@"^\s*(?SG\d{4})\s*\|", RegexOptions.CultureInvariant)] private static partial Regex RuleIdPattern(); + /// + /// Roslyn's own pattern for the separator row of a new/removed rules table + /// (ReleaseTrackingHelper.TableHeaderNewOrRemovedRulesLine2RegexPattern). It allows no + /// spaces around the pipes, so a padded Markdown table does not match. + /// + [GeneratedRegex(@"^\|?-{3,}\|-{3,}\|-{3,}\|-{3,}\|?$", RegexOptions.CultureInvariant)] + private static partial Regex TableSeparatorRowPattern(); + [Test] public async Task ReleaseTrackingFiles_EveryDiagnosticDescriptor_IsTrackedExactlyOnce( CancellationToken cancellationToken @@ -37,6 +45,40 @@ CancellationToken cancellationToken await Assert.That(trackedInBoth).IsEmpty(); } + [Test] + public async Task ReleaseTrackingFiles_TableSeparatorRows_MatchTheFormatTheRoslynAnalyzerParses( + CancellationToken cancellationToken + ) + { + // Arrange + // Microsoft.CodeAnalysis.Analyzers parses a release tracking table only when the separator + // row matches its own pattern, which is dashes and pipes with no padding: + // '--------|----------|----------|-------'. A Markdown formatter that aligns table cells + // writes '-------- | ---------- | ---------- | ------' instead, and the build then fails + // with RS2007 and stops reading every table below the first row it cannot parse. + var shippedLines = await ReadLinesAsync("AnalyzerReleases.Shipped.md", cancellationToken); + var unshippedLines = await ReadLinesAsync("AnalyzerReleases.Unshipped.md", cancellationToken); + + // Act + var shippedSeparatorRows = shippedLines.Where(static line => IsTableSeparatorRow(line)).ToArray(); + var malformed = shippedLines + .Concat(unshippedLines) + .Where(static line => IsTableSeparatorRow(line)) + .Where(static line => !TableSeparatorRowPattern().IsMatch(line.Trim())) + .ToArray(); + + // Assert + await Assert.That(shippedSeparatorRows).IsNotEmpty(); + await Assert + .That(malformed) + .IsEmpty() + .Because("Roslyn rejects a padded separator row, so it must stay '--------|----------|----------|-------'"); + + static bool IsTableSeparatorRow(string line) => + line.Contains('|', StringComparison.Ordinal) + && line.Trim().All(static character => character is '-' or '|' or ' '); + } + [Test] public async Task ReleaseTrackingFiles_SG0017ToSG0020_AreShipped(CancellationToken cancellationToken) { @@ -61,8 +103,7 @@ .. typeof(DiagnosticLibrary) static async Task> ReadRuleIdsAsync(string fileName, CancellationToken cancellationToken) { - var path = Path.Combine(AppContext.BaseDirectory, ReleaseTrackingFolder, fileName); - var lines = await File.ReadAllLinesAsync(path, cancellationToken); + var lines = await ReadLinesAsync(fileName, cancellationToken); return [ @@ -72,4 +113,10 @@ .. lines .Select(static match => match.Groups["id"].Value), ]; } + + static async Task ReadLinesAsync(string fileName, CancellationToken cancellationToken) => + await File.ReadAllLinesAsync( + Path.Combine(AppContext.BaseDirectory, ReleaseTrackingFolder, fileName), + cancellationToken + ); } diff --git a/src/tests/SourceGeneration.UnitTests/Helpers/ResourceGroupOrderingTests.cs b/src/tests/SourceGeneration.UnitTests/Helpers/ResourceGroupOrderingTests.cs index fb5a408..c6dfa04 100644 --- a/src/tests/SourceGeneration.UnitTests/Helpers/ResourceGroupOrderingTests.cs +++ b/src/tests/SourceGeneration.UnitTests/Helpers/ResourceGroupOrderingTests.cs @@ -85,6 +85,7 @@ static ResourceGroupModel Group(string name, string? parent = null) => PropertyName: name, ShowInDashboard: true, Mode: null, - Urls: EquatableArray.Empty + Urls: EquatableArray.Empty, + Location: default ); }