type/no-unnecessary-boolean-literal-compare
Disallow unnecessary comparisons against boolean literals.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
nuxt, opinionated |
No | Rule options |
Applies to: Type information in Vue SFC scripts and templates, for the constructs shown below.
This rule reads type information from your TypeScript project (tsconfig.json), so the configuration sets typeAware: true. typeAware does not turn on opt-in rules by itself.
Bad
flag is already boolean, so comparing it with true adds no check.
<script setup lang="ts">
function isFlag(flag: boolean): boolean {
return flag === true;
}
</script>
Good
Returning flag uses the boolean value directly.
<script setup lang="ts">
function isFlag(flag: boolean): boolean {
return flag;
}
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"type/no-unnecessary-boolean-literal-compare": "warn"
},
"typeAware": true
},
});
Then run vp run lint.