ocaml.lang.best-practice.ref.ocamllint-ref-decr

profile photo of semgrepsemgrep
Author
4,866
Download Count*

You should use decr

Run Locally

Run in CI

Defintion

rules:
  - id: ocamllint-ref-decr
    pattern: $X := ! $X - 1
    message: You should use `decr`
    languages:
      - ocaml
    severity: WARNING
    metadata:
      category: best-practice
      technology:
        - ocaml
      references:
        - https://v2.ocaml.org/api/Stdlib.html#VALdecr
        - https://v2.ocaml.org/api/Atomic.html#VALdecr
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

ref.ml

let test x =
  (* ruleid:ocamllint-ref-incr *)
  x := !x + 1;
  (* ruleid:ocamllint-ref-decr *)
  x := !x - 1;
  ()