diff --git a/.chronus/changes/core-IntegerTypesRule-2024-3-5-18-54-1.md b/.chronus/changes/core-IntegerTypesRule-2024-3-5-18-54-1.md index 45f114a8c4..f86905e812 100644 --- a/.chronus/changes/core-IntegerTypesRule-2024-3-5-18-54-1.md +++ b/.chronus/changes/core-IntegerTypesRule-2024-3-5-18-54-1.md @@ -3,7 +3,6 @@ changeKind: feature packages: - "@azure-tools/typespec-autorest" - - "@azure-tools/typespec-azure-core" --- -Add `use-standard-integer` rule to disable LintDiff `IntegerTypeMustHaveFormat`. +Add `no-generic-types` rule to disable LintDiff `IntegerTypeMustHaveFormat`. diff --git a/docs/libraries/azure-core/reference/linter.md b/docs/libraries/azure-core/reference/linter.md index e7a79ffac2..698b3b7b25 100644 --- a/docs/libraries/azure-core/reference/linter.md +++ b/docs/libraries/azure-core/reference/linter.md @@ -42,6 +42,7 @@ Available ruleSets: | `@azure-tools/typespec-azure-core/no-explicit-routes-resource-ops` | The @route decorator should not be used on standard resource operation signatures. | | `@azure-tools/typespec-azure-core/no-fixed-enum-discriminator` | Discriminator shouldn't be a fixed enum. | | [`@azure-tools/typespec-azure-core/non-breaking-versioning`](/libraries/azure-core/rules/non-breaking-versioning.md) | Check that only backward compatible versioning change are done to a service. | +| [`@azure-tools/typespec-azure-core/no-generic-types`](/libraries/azure-core/rules/no-generic-types.md) | Don't use generic types. Use more specific types instead. | | `@azure-tools/typespec-azure-core/no-nullable` | Use `?` for optional properties. | | `@azure-tools/typespec-azure-core/no-offsetdatetime` | Prefer using `utcDateTime` when representing a datetime unless an offset is necessary. | | `@azure-tools/typespec-azure-core/no-response-body` | Ensure that the body is set correctly for the response type. | @@ -59,6 +60,5 @@ Available ruleSets: | `@azure-tools/typespec-azure-core/response-schema-problem` | Warn about operations having multiple non-error response schemas. | | `@azure-tools/typespec-azure-core/rpc-operation-request-body` | Warning for RPC body problems. | | `@azure-tools/typespec-azure-core/spread-discriminated-model` | Check a model with a discriminator has not been used in composition. | -| `@azure-tools/typespec-azure-core/use-standard-integer` | Use only types that map to int32 or int64. | | `@azure-tools/typespec-azure-core/use-standard-names` | Use recommended names for operations. | | `@azure-tools/typespec-azure-core/use-standard-operations` | Operations should be defined using a signature from the Azure.Core namespace. | diff --git a/packages/typespec-azure-core/README.md b/packages/typespec-azure-core/README.md index 116561509c..6b6ac53ef7 100644 --- a/packages/typespec-azure-core/README.md +++ b/packages/typespec-azure-core/README.md @@ -46,6 +46,7 @@ Available ruleSets: | `@azure-tools/typespec-azure-core/no-explicit-routes-resource-ops` | The @route decorator should not be used on standard resource operation signatures. | | `@azure-tools/typespec-azure-core/no-fixed-enum-discriminator` | Discriminator shouldn't be a fixed enum. | | [`@azure-tools/typespec-azure-core/non-breaking-versioning`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/non-breaking-versioning) | Check that only backward compatible versioning change are done to a service. | +| [`@azure-tools/typespec-azure-core/no-generic-types`](https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-generic-types) | Don't use generic types. Use more specific types instead. | | `@azure-tools/typespec-azure-core/no-nullable` | Use `?` for optional properties. | | `@azure-tools/typespec-azure-core/no-offsetdatetime` | Prefer using `utcDateTime` when representing a datetime unless an offset is necessary. | | `@azure-tools/typespec-azure-core/no-response-body` | Ensure that the body is set correctly for the response type. | @@ -63,7 +64,6 @@ Available ruleSets: | `@azure-tools/typespec-azure-core/response-schema-problem` | Warn about operations having multiple non-error response schemas. | | `@azure-tools/typespec-azure-core/rpc-operation-request-body` | Warning for RPC body problems. | | `@azure-tools/typespec-azure-core/spread-discriminated-model` | Check a model with a discriminator has not been used in composition. | -| `@azure-tools/typespec-azure-core/use-standard-integer` | Use only types that map to int32 or int64. | | `@azure-tools/typespec-azure-core/use-standard-names` | Use recommended names for operations. | | `@azure-tools/typespec-azure-core/use-standard-operations` | Operations should be defined using a signature from the Azure.Core namespace. | diff --git a/packages/typespec-azure-core/test/rules/no-generic-types.test.ts b/packages/typespec-azure-core/test/rules/no-generic-types.test.ts index 5e3213f0fa..69cdbcc271 100644 --- a/packages/typespec-azure-core/test/rules/no-generic-types.test.ts +++ b/packages/typespec-azure-core/test/rules/no-generic-types.test.ts @@ -15,59 +15,32 @@ beforeEach(async () => { tester = createLinterRuleTester(runner, noGenericTypesRule, "@azure-tools/typespec-azure-core"); }); -it("emits a warning diagnostic for non-standard integer types", async () => { +it("emits a warning diagnostic for generic types", async () => { await tester .expect( ` namespace Azure.Widget; model Widget { - prop1: uint16; - prop2: int8; - prop3: uint32; + prop1: integer; + prop2: numeric; + prop3: float; + prop4: decimal; } ` ) .toEmitDiagnostics([ { - code: "@azure-tools/typespec-azure-core/use-standard-integer", + code: "@azure-tools/typespec-azure-core/no-generic-types", }, { - code: "@azure-tools/typespec-azure-core/use-standard-integer", + code: "@azure-tools/typespec-azure-core/no-generic-types", }, { - code: "@azure-tools/typespec-azure-core/use-standard-integer", + code: "@azure-tools/typespec-azure-core/no-generic-types", + }, + { + code: "@azure-tools/typespec-azure-core/no-generic-types", }, ]); }); - -it("does not emit a warning diagnostic for standard integer types", async () => { - await tester - .expect( - ` - namespace Azure.Widget; - - model Widget { - prop1: int32; - prop2: int64; - prop3: safeint; - } - ` - ) - .toBeValid(); -}); - -it("does not emit a warning diagnostic for non-standard integer types that map to supported integers in Autorest", async () => { - await tester - .expect( - ` - namespace Azure.Widget; - - model Widget { - prop1: numeric; - prop2: integer - } - ` - ) - .toBeValid(); -});