Skip to content

Commit

Permalink
- Stricter number type check
Browse files Browse the repository at this point in the history
  • Loading branch information
Xterionix committed Oct 18, 2024
1 parent 578c6f9 commit e9de8ea
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Lib/Diagnostics/BehaviorPack/Entity/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ function diagnose_entity_float_property_definition(property: EntityFloatProperty
}
}

if (typeof def === "number" || typeof def === "string") return;
if ((typeof def === "number" && !Number.isInteger(def)) || typeof def === "string") return;

diagnoser.add(
`properties/${name}/${def}`,
`Default value is not a boolean: ${def}`,
`Default value is not a float: ${def}`,
DiagnosticSeverity.error,
"behaviorpack.entity.property.float.default"
);
Expand All @@ -101,11 +101,11 @@ function diagnose_entity_int_property_definition(property: EntityIntProperty, di
}
}

if (typeof def === "number" || typeof def === "string") return;
if ((typeof def === "number" && Number.isInteger(def)) || typeof def === "string") return;

diagnoser.add(
`properties/${name}/${def}`,
`Default value is not a boolean: ${def}`,
`Default value is not an integer: ${def}`,
DiagnosticSeverity.error,
"behaviorpack.entity.property.int.default"
);
Expand Down Expand Up @@ -207,12 +207,22 @@ function check_entity_property_usage(
break;

case "int":
if ((typeof value === "number" && Number.isInteger(value)) || typeof value === "string") return;

diagnoser.add(
`${parent}/${name}/${value}`,
`Property value is not a integer: ${value}`,
DiagnosticSeverity.error,
`behaviorpack.entity.property.${definition.type}.value`
);
break;

case "float":
if (typeof value === "number" || typeof value === "string") return;
if ((typeof value === "number" && !Number.isInteger(value)) || typeof value === "string") return;

diagnoser.add(
`${parent}/${name}/${value}`,
`Property value is not a number: ${value}`,
`Property value is not a float: ${value}`,
DiagnosticSeverity.error,
`behaviorpack.entity.property.${definition.type}.value`
);
Expand Down

0 comments on commit e9de8ea

Please sign in to comment.