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

profile photo of semgrepsemgrep
Author
4,866
Download Count*

You should use incr

Run Locally

Run in CI

Defintion

rules:
  - id: ocamllint-ref-incr
    pattern: $X := ! $X + 1
    message: You should use `incr`
    languages:
      - ocaml
    severity: WARNING
    metadata:
      category: best-practice
      technology:
        - ocaml
      references:
        - https://v2.ocaml.org/api/Stdlib.html#VALincr
        - https://v2.ocaml.org/api/Atomic.html#VALincr
      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;
  ()