ocaml.lang.best-practice.string.ocamllint-str-first-chars

Author
4,866
Download Count*
License
Use instead Str.first_chars
Run Locally
Run in CI
Defintion
rules:
- id: ocamllint-str-first-chars
pattern: String.sub $S 0 $N
message: Use instead `Str.first_chars`
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
()
Short Link: https://sg.run/x16y