Skip to content

Commit 016e011

Browse files
committed
feat(models): allow non-integer weights in refs
1 parent b79191e commit 016e011

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/models/docs/models-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ _Object containing the following properties:_
130130
| Property | Description | Type |
131131
| :---------------- | :----------------------------------------------------------------- | :---------------------------------------------------------------- |
132132
| **`slug`** (\*) | Slug of an audit or group (depending on `type`) | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) |
133-
| **`weight`** (\*) | Weight used to calculate score | `number` (_int, ≥0_) |
133+
| **`weight`** (\*) | Weight used to calculate score | `number` (_≥0_) |
134134
| **`type`** (\*) | Discriminant for reference kind, affects where `slug` is looked up | `'audit' \| 'group'` |
135135
| **`plugin`** (\*) | Plugin slug (plugin should contain referenced audit or group) | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) |
136136

@@ -207,7 +207,7 @@ _Object containing the following properties:_
207207
| Property | Description | Type |
208208
| :---------------- | :-------------------------------------------------------------- | :---------------------------------------------------------------- |
209209
| **`slug`** (\*) | Reference slug to a group within this plugin (e.g. 'max-lines') | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) |
210-
| **`weight`** (\*) | Weight used to calculate score | `number` (_int, ≥0_) |
210+
| **`weight`** (\*) | Weight used to calculate score | `number` (_≥0_) |
211211

212212
_(\*) Required._
213213

packages/models/src/lib/implementation/schemas.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export const positiveIntSchema = z.number().int().positive();
119119

120120
export const nonnegativeIntSchema = z.number().int().nonnegative();
121121

122+
export const nonnegativeNumberSchema = z.number().nonnegative();
123+
122124
export function packageVersionSchema<TRequired extends boolean>(options?: {
123125
versionDescription?: string;
124126
required?: TRequired;
@@ -140,7 +142,7 @@ export function packageVersionSchema<TRequired extends boolean>(options?: {
140142
}
141143

142144
/** Schema for a weight */
143-
export const weightSchema = nonnegativeIntSchema.describe(
145+
export const weightSchema = nonnegativeNumberSchema.describe(
144146
'Coefficient for the given score (use weight 0 if only for display)',
145147
);
146148

0 commit comments

Comments
 (0)