Vize

type/strict-boolean-expressions

Require safe boolean expressions in script and template conditions

Bad · Good

Default severity: warning
Presets: none
Automatic fix: None; review the suggested change
Applies to: Type information in Vue SFC scripts and templates, for the constructs shown below
Options: See typed options and defaults.

Enable typeAware and this rule explicitly. The default disallows nullable numbers, while non-null numbers are allowed.

Type-aware checks use the native Corsa runtime and the TypeScript project. typeAware alone does not enable an opt-in rule.

Configuration (Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({
  lint: {
    vize: {
      "preset": "incremental",
      "rules": {
        "type/strict-boolean-expressions": "warn"
      },
      "typeAware": true
    },
  },
});
vp run lint

Bad

if (count) relies on the truthiness of a nullable numeric binding instead of an explicit boolean test; it also conflates zero with absence.

<script setup lang="ts">
const count: number | undefined = undefined;
if (count) console.log(count);
</script>

Good

count !== undefined && count > 0 separately tests presence and positivity, producing an explicit boolean condition after narrowing the optional value.

<script setup lang="ts">
const count: number | undefined = undefined;
if (count !== undefined && count > 0) console.log(count);
</script>

Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.

Implementation · All rules