-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a710224
commit 0e7dd0f
Showing
7 changed files
with
68 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: "no-generic-types" | ||
--- | ||
|
||
```text title="Full name" | ||
@azure-tools/typespec-azure-core/no-generic-types | ||
``` | ||
|
||
Azure services should use types which specify the bit-width instead of generic types. | ||
|
||
#### ❌ Incorrect | ||
|
||
```tsp | ||
model Widget { | ||
id: integer; | ||
} | ||
``` | ||
|
||
#### ✅ Correct | ||
|
||
```tsp | ||
model Widget { | ||
id: int32; | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/typespec-azure-core/src/rules/no-generic-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Model, createRule, paramMessage } from "@typespec/compiler"; | ||
|
||
const disallowList = new Set(["integer", "numeric", "float", "decimal"]); | ||
const alternatives = new Map([ | ||
["integer", "int32"], | ||
["numeric", "int32"], | ||
["float", "float32"], | ||
["decimal", "float32"], | ||
]); | ||
|
||
export const noGenericTypesRule = createRule({ | ||
name: "no-generic-types", | ||
description: "Don't use generic types. Use more specific types instead.", | ||
severity: "warning", | ||
url: "https://azure.github.io/typespec-azure/docs/libraries/azure-core/rules/no-generic-types", | ||
messages: { | ||
default: paramMessage`Don't use generic type '${"name"}'. Use a more specific type that specifies the bit size, such as '${"alternative"}' instead.`, | ||
}, | ||
create(context) { | ||
return { | ||
model: (model: Model) => { | ||
for (const [_, prop] of model.properties) { | ||
if (prop.type.kind === "Scalar") { | ||
if (disallowList.has(prop.type.name)) { | ||
context.reportDiagnostic({ | ||
target: prop.type, | ||
format: { | ||
name: prop.type.name, | ||
alternative: alternatives.get(prop.type.name)!, | ||
}, | ||
}); | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
35 changes: 0 additions & 35 deletions
35
packages/typespec-azure-core/src/rules/use-standard-integer.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters