-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
Milestone
Description
We have a sample of CSV input that we used for documenting REST APIs via OpenAPI, using the shiny new Java 17 multi-line strings
(instead of the ugly multi-line manual strings we had before)
static final String LOCATION_CSV_SAMPLE =
"""
locationId,label,regionId,regionLabel,vendorId,vendorLabel,address,address2,city,stateProvinceCode,zipCode,countryCode,latitude,longitude
ST001,Station 001,ZONE1,Zone 1,CP1,Competitor 1,123 Street,Unit 2,Houston,TX,77033,US,29.761496813335178,-95.53049214204984
ST002,Station 002,ZONE2,,CP2,,668 Street,Unit 23,San Jose,CA,95191,US,37.35102477242508,-121.9209934020318
""";
the LineLength check gets triggerd on this and blocks us from using the benefits of multi-line strings like this.
I think this check should be more flexible and recognize that multi-line strings like this could be used for documentation, etc. and not get triggered.
Otherwise it may nullify one of the greatest benefits of the new multi-line Java 17 strings.
public class LineLength {
/** somejavadoc. */
public static void main(String[] args) {
// SHOULD NOT VIOLATE, THIS IS TEXT-BLOCK
String textBlock = """
This STRing will exceed the column limit of 100 but checktyle will not show many error because it is allowed
Random String
google config allows text block to exceed limit of 100 line length. it improves readability and stuff.
same is true for this line also. same is true for this line as well. same is true for this line too.
one more Random String.
""";
// OK to give violation as this is normal string
String normalString = "a very long string is heavy to parse and takes so much processing power. it is not ideal to make long strings";
}
}
$ java -jar checkstyle-10.25.0-all.jar -c /google_checks.xml LineLength.java
Starting audit...
[WARN] /mnt/5D92528E6B945467/test/testing/LineLength.java:1:1: Missing a Javadoc comment. [MissingJavadocType]
[WARN] /mnt/5D92528E6B945467/test/testing/LineLength.java:7: Line is longer than 100 characters (found 115). [LineLength]
[WARN] /mnt/5D92528E6B945467/test/testing/LineLength.java:9: Line is longer than 100 characters (found 108). [LineLength]
[WARN] /mnt/5D92528E6B945467/test/testing/LineLength.java:10: Line is longer than 100 characters (found 107). [LineLength]
[WARN] /mnt/5D92528E6B945467/test/testing/LineLength.java:14: Line is longer than 100 characters (found 138). [LineLength]
Audit done.
Google style is updated to mention this
#11867 (comment)
dmatej and jtrimmer-nydig