ocaml.lang.best-practice.string.ocamllint-str-string-after

profile photo of semgrepsemgrep
Author
4,866
Download Count*

Use instead Str.string_after

Run Locally

Run in CI

Defintion

rules:
  - id: ocamllint-str-string-after
    pattern: String.sub $S $N (String.length $S - $N)
    message: Use instead `Str.string_after`
    languages:
      - ocaml
    severity: WARNING
    metadata:
      category: best-practice
      technology:
        - ocaml
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

string.ml

let test s =
  (* ruleid:ocamllint-str-first-chars *)
  String.sub s 0 20

let test2 s =
  (* ruleid:ocamllint-str-string-after *)
  String.sub s 20 (String.length s - 20)

let test3 s =
  (* ruleid:ocamllint-str-last-chars *)
  String.sub s (String.length s - 20) 20


let test 4 s =
  (* ruleid:ocamllint-useless-sprintf *)
  let s1 = Printf.sprintf "this is useless" in
  (* ruleid:ocamllint-useless-sprintf *)
  let s2 = Printf.sprintf "%s" "this is also useless" in
  let s3 = Printf.sprintf "this is an %d int" 2 in
  ()