diff --git a/.chronus/changes/almend-Rule-2024-8-17-16-58-23.md b/.chronus/changes/almend-Rule-2024-8-17-16-58-23.md index bf727064b..1cca1233b 100644 --- a/.chronus/changes/almend-Rule-2024-8-17-16-58-23.md +++ b/.chronus/changes/almend-Rule-2024-8-17-16-58-23.md @@ -4,4 +4,4 @@ packages: - "@azure-tools/typespec-azure-resource-manager" --- -Add `arm-no-empty-model` rule +Add `no-empty-model` rule diff --git a/.chronus/changes/almend-Rule-2024-8-18-10-2-28.md b/.chronus/changes/almend-Rule-2024-8-18-10-2-28.md index f59e75b58..d2c308430 100644 --- a/.chronus/changes/almend-Rule-2024-8-18-10-2-28.md +++ b/.chronus/changes/almend-Rule-2024-8-18-10-2-28.md @@ -4,4 +4,4 @@ packages: - "@azure-tools/typespec-azure-rulesets" --- -Add `arm-no-empty-model` rule to ruleset +Add `no-empty-model` rule to ruleset diff --git a/docs/libraries/azure-resource-manager/reference/linter.md b/docs/libraries/azure-resource-manager/reference/linter.md index 133d322bc..8b4584a85 100644 --- a/docs/libraries/azure-resource-manager/reference/linter.md +++ b/docs/libraries/azure-resource-manager/reference/linter.md @@ -31,7 +31,6 @@ Available ruleSets: | [`@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes`](/libraries/azure-resource-manager/rules/delete-operation-response-codes.md) | Ensure delete operations have the appropriate status codes. | | [`@azure-tools/typespec-azure-resource-manager/arm-put-operation-response-codes`](/libraries/azure-resource-manager/rules/put-operation-response-codes.md) | Ensure put operations have the appropriate status codes. | | [`@azure-tools/typespec-azure-resource-manager/arm-post-operation-response-codes`](/libraries/azure-resource-manager/rules/post-operation-response-codes.md) | Ensure post operations have the appropriate status codes. | -| `@azure-tools/typespec-azure-resource-manager/arm-no-empty-model` | ARM Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-action-no-segment` | `@armResourceAction` should not be used with `@segment`. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-duplicate-property` | Warn about duplicate properties in resources. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property` | Check for invalid resource envelope properties. | @@ -57,3 +56,4 @@ Available ruleSets: | `@azure-tools/typespec-azure-resource-manager/resource-name` | Check the resource name. | | `@azure-tools/typespec-azure-resource-manager/retry-after` | Check if retry-after header appears in response body. | | [`@azure-tools/typespec-azure-resource-manager/unsupported-type`](/libraries/azure-resource-manager/rules/unsupported-type.md) | Check for unsupported ARM types. | +| [`@azure-tools/typespec-azure-resource-manager/no-empty-model`](/libraries/azure-resource-manager/rules/no-empty-model.md) | ARM Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience. | diff --git a/docs/libraries/azure-resource-manager/rules/arm-no-empty-model.md b/docs/libraries/azure-resource-manager/rules/no-empty-model.md similarity index 87% rename from docs/libraries/azure-resource-manager/rules/arm-no-empty-model.md rename to docs/libraries/azure-resource-manager/rules/no-empty-model.md index 22f4a7e96..c2b30eda0 100644 --- a/docs/libraries/azure-resource-manager/rules/arm-no-empty-model.md +++ b/docs/libraries/azure-resource-manager/rules/no-empty-model.md @@ -1,9 +1,9 @@ --- -title: arm-no-empty-model +title: no-empty-model --- ```text title=- Full name- -@azure-tools/typespec-azure-resource-manager/arm-no-empty-model +@azure-tools/typespec-azure-resource-manager/no-empty-model ``` ARM Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience. diff --git a/packages/typespec-azure-resource-manager/README.md b/packages/typespec-azure-resource-manager/README.md index b3ab589da..0fefb6468 100644 --- a/packages/typespec-azure-resource-manager/README.md +++ b/packages/typespec-azure-resource-manager/README.md @@ -35,7 +35,6 @@ Available ruleSets: | [`@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/delete-operation-response-codes) | Ensure delete operations have the appropriate status codes. | | [`@azure-tools/typespec-azure-resource-manager/arm-put-operation-response-codes`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/put-operation-response-codes) | Ensure put operations have the appropriate status codes. | | [`@azure-tools/typespec-azure-resource-manager/arm-post-operation-response-codes`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/post-operation-response-codes) | Ensure post operations have the appropriate status codes. | -| `@azure-tools/typespec-azure-resource-manager/arm-no-empty-model` | ARM Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-action-no-segment` | `@armResourceAction` should not be used with `@segment`. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-duplicate-property` | Warn about duplicate properties in resources. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property` | Check for invalid resource envelope properties. | @@ -61,6 +60,7 @@ Available ruleSets: | `@azure-tools/typespec-azure-resource-manager/resource-name` | Check the resource name. | | `@azure-tools/typespec-azure-resource-manager/retry-after` | Check if retry-after header appears in response body. | | [`@azure-tools/typespec-azure-resource-manager/unsupported-type`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/unsupported-type) | Check for unsupported ARM types. | +| [`@azure-tools/typespec-azure-resource-manager/no-empty-model`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/no-empty-model) | ARM Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience. | ## Decorators diff --git a/packages/typespec-azure-resource-manager/src/linter.ts b/packages/typespec-azure-resource-manager/src/linter.ts index 2162b6b95..c0d86c4b1 100644 --- a/packages/typespec-azure-resource-manager/src/linter.ts +++ b/packages/typespec-azure-resource-manager/src/linter.ts @@ -1,7 +1,6 @@ import { defineLinter } from "@typespec/compiler"; import { armCommonTypesVersionRule } from "./rules/arm-common-types-version.js"; import { armDeleteResponseCodesRule } from "./rules/arm-delete-response-codes.js"; -import { armNoEmptyModel } from "./rules/arm-no-empty-model.js"; import { armNoRecordRule } from "./rules/arm-no-record.js"; import { armPostResponseCodesRule } from "./rules/arm-post-response-codes.js"; import { armPutResponseCodesRule } from "./rules/arm-put-response-codes.js"; @@ -24,6 +23,7 @@ import { envelopePropertiesRules } from "./rules/envelope-properties.js"; import { listBySubscriptionRule } from "./rules/list-operation.js"; import { lroLocationHeaderRule } from "./rules/lro-location-header.js"; import { missingXmsIdentifiersRule } from "./rules/missing-x-ms-identifiers.js"; +import { noEmptyModel } from "./rules/no-empty-model.js"; import { noResponseBodyRule } from "./rules/no-response-body.js"; import { operationsInterfaceMissingRule } from "./rules/operations-interface-missing.js"; import { patchEnvelopePropertiesRules } from "./rules/patch-envelope-properties.js"; @@ -37,7 +37,6 @@ const rules = [ armDeleteResponseCodesRule, armPutResponseCodesRule, armPostResponseCodesRule, - armNoEmptyModel, armResourceActionNoSegmentRule, armResourceDuplicatePropertiesRule, armResourceEnvelopeProperties, @@ -63,6 +62,7 @@ const rules = [ resourceNameRule, retryAfterRule, unsupportedTypeRule, + noEmptyModel, ]; export const $linter = defineLinter({ diff --git a/packages/typespec-azure-resource-manager/src/rules/arm-no-empty-model.ts b/packages/typespec-azure-resource-manager/src/rules/no-empty-model.ts similarity index 84% rename from packages/typespec-azure-resource-manager/src/rules/arm-no-empty-model.ts rename to packages/typespec-azure-resource-manager/src/rules/no-empty-model.ts index 8ef8d96a6..73b5eef45 100644 --- a/packages/typespec-azure-resource-manager/src/rules/arm-no-empty-model.ts +++ b/packages/typespec-azure-resource-manager/src/rules/no-empty-model.ts @@ -1,11 +1,11 @@ import { createRule, Model } from "@typespec/compiler"; -export const armNoEmptyModel = createRule({ - name: "arm-no-empty-model", +export const noEmptyModel = createRule({ + name: "no-empty-model", severity: "warning", description: "ARM Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience.", - url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-no-empty-model", + url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/no-empty-model", messages: { default: "Properties with type:object must have definition of a reference model.", extends: @@ -16,7 +16,7 @@ export const armNoEmptyModel = createRule({ model: (model: Model) => { if (model.properties.size === 0) { context.reportDiagnostic({ - code: "arm-no-empty-model", + code: "no-empty-model", target: model, }); } diff --git a/packages/typespec-azure-resource-manager/test/rules/arm-no-empty-model.test.ts b/packages/typespec-azure-resource-manager/test/rules/no-empty-model.test.ts similarity index 89% rename from packages/typespec-azure-resource-manager/test/rules/arm-no-empty-model.test.ts rename to packages/typespec-azure-resource-manager/test/rules/no-empty-model.test.ts index ea1f5eb18..30a27aaa3 100644 --- a/packages/typespec-azure-resource-manager/test/rules/arm-no-empty-model.test.ts +++ b/packages/typespec-azure-resource-manager/test/rules/no-empty-model.test.ts @@ -4,7 +4,7 @@ import { createLinterRuleTester, } from "@typespec/compiler/testing"; import { beforeEach, describe, it } from "vitest"; -import { armNoEmptyModel } from "../../src/rules/arm-no-empty-model.js"; +import { noEmptyModel } from "../../src/rules/no-empty-model.js"; import { createAzureResourceManagerTestRunner } from "../test-host.js"; const armDef = ` @@ -21,7 +21,7 @@ describe("typespec-azure-resource-manager: arm properties type-object no definit runner = await createAzureResourceManagerTestRunner(); tester = createLinterRuleTester( runner, - armNoEmptyModel, + noEmptyModel, "@azure-tools/typespec-azure-resource-manager", ); }); @@ -37,7 +37,7 @@ describe("typespec-azure-resource-manager: arm properties type-object no definit `, ) .toEmitDiagnostics({ - code: "@azure-tools/typespec-azure-resource-manager/arm-no-empty-model", + code: "@azure-tools/typespec-azure-resource-manager/no-empty-model", message: "Properties with type:object must have definition of a reference model.", }); }); @@ -51,7 +51,7 @@ describe("typespec-azure-resource-manager: arm properties type-object no definit `, ) .toEmitDiagnostics({ - code: "@azure-tools/typespec-azure-resource-manager/arm-no-empty-model", + code: "@azure-tools/typespec-azure-resource-manager/no-empty-model", message: "Properties with type:object must have definition of a reference model.", }); }); diff --git a/packages/typespec-azure-rulesets/src/rulesets/resource-manager.ts b/packages/typespec-azure-rulesets/src/rulesets/resource-manager.ts index 5dfd93c11..e7494f7c6 100644 --- a/packages/typespec-azure-rulesets/src/rulesets/resource-manager.ts +++ b/packages/typespec-azure-rulesets/src/rulesets/resource-manager.ts @@ -50,7 +50,7 @@ export default { // Azure resource manager "@azure-tools/typespec-azure-resource-manager/arm-no-record": true, - "@azure-tools/typespec-azure-resource-manager/arm-no-empty-model": true, + "@azure-tools/typespec-azure-resource-manager/no-empty-model": true, "@azure-tools/typespec-azure-resource-manager/arm-common-types-version": true, "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes": true, "@azure-tools/typespec-azure-resource-manager/arm-put-operation-response-codes": true,