ocaml.lang.best-practice.bool.ocamllint-bool-false

profile photo of semgrepsemgrep
Author
4,866
Download Count*

Comparison to boolean. Just use not $X

Run Locally

Run in CI

Defintion

rules:
  - id: ocamllint-bool-false
    pattern-either:
      - pattern: $X = false
      - pattern: $X == false
      - pattern: $X <> true
    message: Comparison to boolean. Just use `not $X`
    languages:
      - ocaml
    severity: WARNING
    metadata:
      category: best-practice
      technology:
        - ocaml
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

bool.ml

let test a =
  (* ruleid:ocamllint-bool-true *)
  let x = a = true in
  (* ruleid:ocamllint-bool-true *)
  let x = a == true in
  (* ruleid:ocamllint-bool-false *)
  let x = a = false in
  (* ruleid:ocamllint-bool-false *)
  let x = a == false in
  (* ruleid:ocamllint-bool-true *)
  let x = a != false in
  (* ruleid:ocamllint-bool-false *)
  let x = a <> true in
  ()