Skip to content

Commit

Permalink
Issue checkstyle#14487: add support to ignore JSNI methods for LineLe…
Browse files Browse the repository at this point in the history
…ngth check in google config
  • Loading branch information
Zopsss committed Mar 3, 2024
1 parent 6d5b91f commit 40934dd
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 12 deletions.
2 changes: 0 additions & 2 deletions config/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ GMetrics
gnupg
google
googleapis
googleblog
googlecloudplatform
googleecommon
googlegroups
Expand Down Expand Up @@ -1417,7 +1416,6 @@ webjar
Weblogic
Webp
website
webtoolkit
Wellformedness
wget
wherejavadocrequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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
*/;
}
8 changes: 8 additions & 0 deletions src/main/resources/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>

<!-- To ignore JSNI Methods for LineLength check -->
<!-- See https://google.github.io/styleguide/javaguide.html#s4.4-column-limit -->
<module name="SuppressWithPlainTextCommentFilter">
<property name="offCommentFormat" value="\/\*-\{"/>
<property name="onCommentFormat" value="\}-\*\/"/>
<property name="checkFormat" value="LineLength"/>
</module>

<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/xdocs/filters/suppresswithplaintextcommentfilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ public class Example9 {
</subsection>
<subsection name="Example of Usage" id="Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWithPlainTextCommentFilter">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig%20path%3A**%2Fcheckstyle-checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWithPlainTextCommentFilter">
Checkstyle Style</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
</subsection>
<subsection name="Example of Usage" id="Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWithPlainTextCommentFilter">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig%20path%3A**%2Fcheckstyle-checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWithPlainTextCommentFilter">
Checkstyle Style</a>
Expand Down
12 changes: 2 additions & 10 deletions src/xdocs/google_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -780,18 +780,10 @@
<td>
<span class="wrapper inline">
<img
src="images/ok_blue.png"
src="images/ok_green.png"
alt="" />
</span>
<a href="checks/sizes/linelength.html#LineLength">LineLength</a>
<br />
We can detect URL with protocol type as http://, https:// etc.
<br />
<a href="https://webtoolkit.googleblog.com/2008/07/getting-to-really-know-gwt-part-1-jsni.html">
JSNI</a>
could not be detected right now, but might be possible after
comments and javadoc support appear in Checkstyle.
<br />
</td>
<td>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+LineLength">
Expand Down Expand Up @@ -2362,7 +2354,7 @@
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionCommentFilter">
SuppressionCommentFilter</a>,
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWarningsFilter">
SuppressWarningsFilter</a>,
SuppressWarningsFilter</a>.
</p>
</subsection>
</section>
Expand Down

0 comments on commit 40934dd

Please sign in to comment.