xref: /OK3568_Linux_fs/kernel/scripts/coccinelle/misc/ifcol.cocci (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun// SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun/// Find confusingly indented code in or after an if.  An if branch should
3*4882a593Smuzhiyun/// be indented.  The code following an if should not be indented.
4*4882a593Smuzhiyun/// Sometimes, code after an if that is indented is actually intended to be
5*4882a593Smuzhiyun/// part of the if branch.
6*4882a593Smuzhiyun///
7*4882a593Smuzhiyun//# This has a high rate of false positives, because Coccinelle's column
8*4882a593Smuzhiyun//# calculation does not distinguish between spaces and tabs, so code that
9*4882a593Smuzhiyun//# is not visually aligned may be considered to be in the same column.
10*4882a593Smuzhiyun//
11*4882a593Smuzhiyun// Confidence: Low
12*4882a593Smuzhiyun// Copyright: (C) 2010 Nicolas Palix, DIKU.
13*4882a593Smuzhiyun// Copyright: (C) 2010 Julia Lawall, DIKU.
14*4882a593Smuzhiyun// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
15*4882a593Smuzhiyun// URL: http://coccinelle.lip6.fr/
16*4882a593Smuzhiyun// Comments:
17*4882a593Smuzhiyun// Options: --no-includes --include-headers
18*4882a593Smuzhiyun
19*4882a593Smuzhiyunvirtual org
20*4882a593Smuzhiyunvirtual report
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun@r disable braces4@
23*4882a593Smuzhiyunposition p1,p2;
24*4882a593Smuzhiyunstatement S1,S2;
25*4882a593Smuzhiyun@@
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun(
28*4882a593Smuzhiyunif (...) { ... }
29*4882a593Smuzhiyun|
30*4882a593Smuzhiyunif (...) S1@p1 S2@p2
31*4882a593Smuzhiyun)
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun@script:python depends on org@
34*4882a593Smuzhiyunp1 << r.p1;
35*4882a593Smuzhiyunp2 << r.p2;
36*4882a593Smuzhiyun@@
37*4882a593Smuzhiyun
38*4882a593Smuzhiyunif (p1[0].column == p2[0].column):
39*4882a593Smuzhiyun  cocci.print_main("branch",p1)
40*4882a593Smuzhiyun  cocci.print_secs("after",p2)
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun@script:python depends on report@
43*4882a593Smuzhiyunp1 << r.p1;
44*4882a593Smuzhiyunp2 << r.p2;
45*4882a593Smuzhiyun@@
46*4882a593Smuzhiyun
47*4882a593Smuzhiyunif (p1[0].column == p2[0].column):
48*4882a593Smuzhiyun  msg = "code aligned with following code on line %s" % (p2[0].line)
49*4882a593Smuzhiyun  coccilib.report.print_report(p1[0],msg)
50