From f0cd779e2ad6ec66bf1d1b2df8fac39ecefe67df Mon Sep 17 00:00:00 2001 From: Mauryan Kansara Date: Sun, 18 Feb 2024 12:35:48 +0530 Subject: [PATCH] Issue #14487: add support to ignore JSNI methods for LineLength check in google config --- .../rule44columnlimit/LineLengthTest.java | 17 ++++++++++++ .../InputLineLengthJsniMethods.java | 8 ++++++ src/main/resources/google_checks.xml | 8 ++++++ src/xdocs/google_style.xml | 26 ++++++++++--------- 4 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputLineLengthJsniMethods.java diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/LineLengthTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/LineLengthTest.java index fa64460c463..f8a60dbe08a 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/LineLengthTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/LineLengthTest.java @@ -19,11 +19,13 @@ package com.google.checkstyle.test.chapter4formatting.rule44columnlimit; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import org.junit.jupiter.api.Test; import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport; import com.puppycrawl.tools.checkstyle.api.Configuration; import com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck; +import com.puppycrawl.tools.checkstyle.utils.CommonUtil; public class LineLengthTest extends AbstractGoogleModuleTestSupport { @@ -46,4 +48,19 @@ public void testLineLength() throws Exception { verify(checkConfig, filePath, expected, warnList); } + @Test + public void testLineLengthJsniMethods() throws Exception { + final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; + + final Configuration lineLengthConfig = createModuleConfig(LineLengthCheck.class); + final DefaultConfiguration rootConfig = createRootConfig(lineLengthConfig); + + final Configuration filterConfig = getModuleConfig("SuppressWithPlainTextCommentFilter"); + rootConfig.addChild(filterConfig); + + final String filePath = getPath("InputLineLengthJsniMethods.java"); + + verify(rootConfig, filePath, expected); + } + } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputLineLengthJsniMethods.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputLineLengthJsniMethods.java new file mode 100644 index 00000000000..9678d860cea --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputLineLengthJsniMethods.java @@ -0,0 +1,8 @@ +package com.google.checkstyle.test.chapter4formatting.rule44columnlimit; + +public class InputLineLengthJsniMethods { + public static native void alertMessage(String msggggggggggggggggggggggggggggggggggggggggggggggggggg) /*-{ + $wnd.alert(msg); + console.log('a really long message here blah blah blah blah blah bruh bruh bruhhhhhhhhhhhhhhhhhhhhhhhhhhhh'); + }-*/; +} diff --git a/src/main/resources/google_checks.xml b/src/main/resources/google_checks.xml index bc47e7e7767..83439302802 100644 --- a/src/main/resources/google_checks.xml +++ b/src/main/resources/google_checks.xml @@ -48,6 +48,14 @@ + + + + + + + + diff --git a/src/xdocs/google_style.xml b/src/xdocs/google_style.xml index 11686aeb1d9..b8992b6e2ea 100644 --- a/src/xdocs/google_style.xml +++ b/src/xdocs/google_style.xml @@ -780,18 +780,10 @@ LineLength -
- We can detect URL with protocol type as http://, https:// etc. -
- - JSNI - could not be detected right now, but might be possible after - comments and javadoc support appear in Checkstyle. -
@@ -2310,10 +2302,12 @@ SuppressWithNearbyCommentFilter, - SuppressionCommentFilter - and + SuppressionCommentFilter, - SuppressWarningsFilter. + SuppressWarningsFilter + and + + SuppressWithPlainTextCommentFilter.

Location of config file for @@ -2351,6 +2345,12 @@ name_of_the_check is the actual name of check to be suppressed in lowercase format.

+

+ To suppress a check using + SuppressWithPlainTextCommentFilter + add the offComment format you specified in the offCommentFormat property before the beginning of the code block and the onComment + format you specified in the onCommentFormat property after the end of the code block. +

For more details please review exact configuration of Filters in google_checks.xml: @@ -2363,6 +2363,8 @@ SuppressionCommentFilter, SuppressWarningsFilter, + + SuppressWithPlainTextCommentFilter.