0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// Find confusingly indented code in or after an if. An if branch should
0003 /// be indented. The code following an if should not be indented.
0004 /// Sometimes, code after an if that is indented is actually intended to be
0005 /// part of the if branch.
0006 ///
0007 //# This has a high rate of false positives, because Coccinelle's column
0008 //# calculation does not distinguish between spaces and tabs, so code that
0009 //# is not visually aligned may be considered to be in the same column.
0010 //
0011 // Confidence: Low
0012 // Copyright: (C) 2010 Nicolas Palix, DIKU.
0013 // Copyright: (C) 2010 Julia Lawall, DIKU.
0014 // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
0015 // URL: https://coccinelle.gitlabpages.inria.fr/website
0016 // Comments:
0017 // Options: --no-includes --include-headers
0018
0019 virtual org
0020 virtual report
0021
0022 @r disable braces4@
0023 position p1,p2;
0024 statement S1,S2;
0025 @@
0026
0027 (
0028 if (...) { ... }
0029 |
0030 if (...) S1@p1 S2@p2
0031 )
0032
0033 @script:python depends on org@
0034 p1 << r.p1;
0035 p2 << r.p2;
0036 @@
0037
0038 if (p1[0].column == p2[0].column):
0039 cocci.print_main("branch",p1)
0040 cocci.print_secs("after",p2)
0041
0042 @script:python depends on report@
0043 p1 << r.p1;
0044 p2 << r.p2;
0045 @@
0046
0047 if (p1[0].column == p2[0].column):
0048 msg = "code aligned with following code on line %s" % (p2[0].line)
0049 coccilib.report.print_report(p1[0],msg)