ocaml.lang.best-practice.ifs.ocamllint-useless-else

profile photo of semgrepsemgrep
Author
4,866
Download Count*

Useless else. Just remove the else branch;

Run Locally

Run in CI

Defintion

rules:
  - id: ocamllint-useless-else
    pattern: if $E then $E1 else ()
    message: Useless else. Just remove the else branch;
    languages:
      - ocaml
    severity: WARNING
    metadata:
      category: best-practice
      technology:
        - ocaml
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

ifs.ml

let test a =
  (* ruleid:ocamllint-useless-else *)
  if a
  then print_string a
  else ()

let test2 a =
  (* ruleid:ocamllint-backwards-if *)
  if a
  then ()
  else print_string a