Skip to content

Commit

Permalink
Refactor test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Apr 10, 2024
1 parent cc75b2e commit 90e9d24
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .chronus/changes/core-IntegerTypesRule-2024-3-5-18-54-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion docs/libraries/azure-core/reference/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -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. |
2 changes: 1 addition & 1 deletion packages/typespec-azure-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -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. |

Expand Down
49 changes: 11 additions & 38 deletions packages/typespec-azure-core/test/rules/no-generic-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 90e9d24

Please sign in to comment.