From 40934dddede18b5f004f678f6704a84e32847cb2 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 --- config/jsoref-spellchecker/whitelist.words | 2 -- .../rule44columnlimit/LineLengthTest.java | 19 +++++++++++++++++++ .../InputLineLengthJsniMethods.java | 16 ++++++++++++++++ src/main/resources/google_checks.xml | 8 ++++++++ .../checkstyle/internal/XdocsPagesTest.java | 1 + .../suppresswithplaintextcommentfilter.xml | 4 ++++ ...esswithplaintextcommentfilter.xml.template | 4 ++++ src/xdocs/google_style.xml | 12 ++---------- 8 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputLineLengthJsniMethods.java diff --git a/config/jsoref-spellchecker/whitelist.words b/config/jsoref-spellchecker/whitelist.words index 264b665312f..e6f403946a4 100644 --- a/config/jsoref-spellchecker/whitelist.words +++ b/config/jsoref-spellchecker/whitelist.words @@ -495,7 +495,6 @@ GMetrics gnupg google googleapis -googleblog googlecloudplatform googleecommon googlegroups @@ -1417,7 +1416,6 @@ webjar Weblogic Webp website -webtoolkit Wellformedness wget wherejavadocrequired 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..4f2bf924ef3 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 @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test; import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import com.puppycrawl.tools.checkstyle.api.Configuration; import com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck; @@ -46,4 +47,22 @@ public void testLineLength() throws Exception { verify(checkConfig, filePath, expected, warnList); } + @Test + public void testLineLengthJsniMethods() throws Exception { + final String[] expected = { + "14: " + getCheckMessage(LineLengthCheck.class, "maxLineLen", 100, 165), + }; + + final Configuration lineLengthConfig = getModuleConfig("LineLength"); + final DefaultConfiguration rootConfig = createRootConfig(lineLengthConfig); + + final Configuration filterConfig = getModuleConfig("SuppressWithPlainTextCommentFilter"); + rootConfig.addChild(filterConfig); + + final String filePath = getPath("InputLineLengthJsniMethods.java"); + + final Integer[] warnList = getLinesWithWarn(filePath); + verify(rootConfig, filePath, expected, warnList); + } + } 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..40ac288cb3c --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputLineLengthJsniMethods.java @@ -0,0 +1,16 @@ +package com.google.checkstyle.test.chapter4formatting.rule44columnlimit; + +public class InputLineLengthJsniMethods { + + // JSNI method + public static native void alertMessage(String msg) /*-{ + $wnd.alert(msg); + console.log('my very long message ....................................................................................................................'); + }-*/; + + // just a comment, no JSNI delimiters + public static native void alertMessage2(String msg) /* + $wnd.alert(msg); + console.log('my very long message ....................................................................................................................'); // warn + */; +} 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/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java index 2a25f2d114c..61b48a9775f 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java @@ -1665,6 +1665,7 @@ public void testAllStyleRules() throws Exception { styleChecks.remove("SuppressionCommentFilter"); styleChecks.remove("SuppressWarningsFilter"); styleChecks.remove("SuppressWarningsHolder"); + styleChecks.remove("SuppressWithPlainTextCommentFilter"); assertWithMessage( fileName + " requires the following check(s) to appear: " + styleChecks) diff --git a/src/xdocs/filters/suppresswithplaintextcommentfilter.xml b/src/xdocs/filters/suppresswithplaintextcommentfilter.xml index 7f459018fde..7d2dd05466c 100644 --- a/src/xdocs/filters/suppresswithplaintextcommentfilter.xml +++ b/src/xdocs/filters/suppresswithplaintextcommentfilter.xml @@ -347,6 +347,10 @@ public class Example9 {
    +
  • + + Google Style +
  • Checkstyle Style diff --git a/src/xdocs/filters/suppresswithplaintextcommentfilter.xml.template b/src/xdocs/filters/suppresswithplaintextcommentfilter.xml.template index 351a07e29c8..611cf76e920 100644 --- a/src/xdocs/filters/suppresswithplaintextcommentfilter.xml.template +++ b/src/xdocs/filters/suppresswithplaintextcommentfilter.xml.template @@ -206,6 +206,10 @@