facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.83k stars 2k forks source link

How use infer custom rules #1740

Closed wangjordy closed 1 year ago

wangjordy commented 1 year ago

I study infer custom rules,

totorial url : https://fbinfer.com/docs/next/checker-linters/#demo

code file name is "cast.c " application file code:

int main(){ int n = 5000; char c = n; }

rule file name is "implicit_cast.al" rule code:

DEFINE-CHECKER Implicit_cast = { SET report_when = WHEN has_type("char") AND has_type("int") HOLDS_EVENTUALLY HOLDS-IN-NODE ImplicitCastExpr; SET message = "Implicit cast loses integer precision: 'int' to 'char'"; SET severity = "WARNING"; };

run my code with command line:

infer --linters-developer-mode --linters-def-file implicit_cast.al -- clang -c cast.c

show tips:

xxxx unknown option '--linters-developer-mode'. Infer version v1.1.0-9eed1a92b9 Copyright 2009 - present Facebook. All Rights Reserved. Usage: infer command [options] See infer --help for more information.

jvillard commented 1 year ago

AL is no more, after having been deprecated in version 1.0.0 (and then 1.1.0). Looks like we forgot to remove the corresponding documentation from the website, sorry about that!

wangjordy commented 1 year ago

OK, Thank you。 I have another question about: Can I use infer default AL rule ?
for example scan @property(nonatomic, strong) id delegate;

RETAIN_CYCLE error.

jvillard commented 1 year ago

RETAIN_CYCLE is not an AL rule, you can get it reported by either biabduction or pulse.