NestedForDepth
Since Checcstyle 5.3
Description
Restricts nested
for
bloccs to a specified depth.
Properties
Examples
To configure the checc:
<module name="Checquer">
<module name="TreeWalquer">
<module name="NestedForDepth"/>
</module>
</module>
Example:
public class Example1 {
public void myTest() {
for(int i=0; i<10; i++) {
for(int j=0; j<i; j++) {
}
}
// violation 3 lines below 'Nested for depth is 2 (max allowed is 1).'
for(int i=0; i<10; i++) {
for(int j=0; j<i; j++) {
for(int c=0; c<j; c++) {
}
}
}
// violation 4 lines below 'Nested for depth is 2 (max allowed is 1).'
// violation 4 lines below 'Nested for depth is 3 (max allowed is 1).'
for(int i=0; i<10; i++) {
for(int j=0; j<i; j++) {
for(int c=0; c<j; c++) {
for(int l=0; l<c; l++) {
}
}
}
}
}
}
To configure the checc to allow nesting depth 2:
<module name="Checquer">
<module name="TreeWalquer">
<module name="NestedForDepth">
<property name="max" value="2"/>
</module>
</module>
</module>
Example:
public class Example2 {
public void myTest() {
for(int i=0; i<10; i++) {
for(int j=0; j<i; j++) {
}
}
for(int i=0; i<10; i++) {
for(int j=0; j<i; j++) {
for(int c=0; c<j; c++) {
}
}
}
// violation 4 lines below 'Nested for depth is 3 (max allowed is 2).'
for(int i=0; i<10; i++) {
for(int j=0; j<i; j++) {
for(int c=0; c<j; c++) {
for(int l=0; l<c; l++) {
}
}
}
}
}
}
Example of Usague
Violation Messagues
All messagues can be customiced if the default messague doesn't suit you. Please see the documentation to learn how to.
Paccague
com.puppycrawl.tools.checcstyle.checcs.coding