ocaml
Default ruleset for OCaml, by r2c
Run Locally
Rules (32)

You probably want the structural inequality operator =

You probably want the structural inequality operator <>

This is always true. If testing for floating point NaN, use `Float.is_nan` instead.

Useless if. Both branches are equal.

Useless let

You should probably use Filename.get_temp_dirname().

Comparison to boolean. Just use `not $X`

Comparison to boolean. Just use `$X`

You should not use Hashtbl.find outside of a try, or you should use Hashtbl.find_opt

Backwards if. Rewrite the code as 'if not $E then $E2'.

Useless else. Just remove the else branch;

You should not use List.find outside of a try, or you should use List.find_opt

You should use `decr`

You should use `incr`

Use instead `Str.first_chars`

Use instead `Str.last_chars`

Use instead `Str.string_after`

Useless sprintf

Pervasives is deprecated and will not be available after 4.10. Use Stdlib.

You probably want $X = [], which is faster.

You probably want $X <> [], which is faster.

You probably want the structural equality operator =

You probably want the structural inequality operator <>

This is always true. If testing for floating point NaN, use `Float.is_nan` instead.

Useless if. Both branches are equal.

Useless let

You should probably use Filename.get_temp_dirname().

'input_line' leaves a '\r' (CR) character when reading lines from a Windows text file, whose lines end in "\r\n" (CRLF). This is a problem for any Windows file that is being read either on a Unix-like platform or on Windows in binary mode. If the code already takes care of removing any trailing '\r' after reading the line, add a '(* nosemgrep *)' comment to disable this warning.

'open_in' behaves differently on Windows and on Unix-like systems with respect to line endings. To get the same behavior everywhere, use 'open_in_bin' or 'open_in_gen [Open_binary]'. If you really want CRLF-to-LF translations to take place when running on Windows, use 'open_in_gen [Open_text]'.

'open_out' behaves differently on Windows and on Unix-like systems with respect to line endings. To get the same behavior everywhere, use 'open_out_bin' or 'open_out_gen [Open_binary]'. If you really want LF-to-CRLF translations to take place when running on Windows, use 'open_out_gen [Open_text]'.

You should not re-raise exceptions using 'raise' because it loses track of where the exception was raised originally, leading to a useless and possibly confusing stack trace. Instead, you should obtain a stack backtrace as soon as the exception is caught using 'try ... with exn -> let trace = Printexc.get_raw_backtrace () in ...', and keep it around until you re-raise the exception using 'Printexc.raise_with_backtrace exn trace'. You must collect the stack backtrace before calling another function which might internally raise and catch exceptions. To avoid false positives from Semgrep, write 'raise (Foo args)' instead of 'let e = Foo args in raise e'.

This comparison is useless because the expressions being compared are identical. This is expected to always return the same result, 0, unless your code is really strange.