Skip to content

Commit

Permalink
Issue #14487: add support to ignore JSNI methods for LineLength check…
Browse files Browse the repository at this point in the history
… in google config
  • Loading branch information
Zopsss committed Feb 18, 2024
1 parent 9842608 commit f0cd779
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

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

}
Original file line number Diff line number Diff line change
@@ -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');
}-*/;
}
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
26 changes: 14 additions & 12 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 @@ -2310,10 +2302,12 @@
<a href="filters/suppresswithnearbycommentfilter.html#SuppressWithNearbyCommentFilter">
SuppressWithNearbyCommentFilter</a>,
<a href="filters/suppressioncommentfilter.html#SuppressionCommentFilter">
SuppressionCommentFilter</a>
and
SuppressionCommentFilter</a>,
<a href="filters/suppresswarningsfilter.html#SuppressWarningsFilter">
SuppressWarningsFilter</a>.
SuppressWarningsFilter</a>
and
<a href="filters/suppresswithplaintextcommentfilter.html#SuppressWithPlainTextCommentFilter">
SuppressWithPlainTextCommentFilter</a>.
</p>
<p>
Location of config file for
Expand Down Expand Up @@ -2351,6 +2345,12 @@
<i>name_of_the_check</i> is the actual name of check to be suppressed in lowercase
format.
</p>
<p>
To suppress a check using
<a href="filters/suppresswithplaintextcommentfilter.html#SuppressWithPlainTextCommentFilter">SuppressWithPlainTextCommentFilter</a>
add the offComment format you specified in the <code>offCommentFormat</code> property before the beginning of the code block and the onComment
format you specified in the <code>onCommentFormat</code> property after the end of the code block.
</p>
<p>
For more details please review exact configuration of Filters in google_checks.xml:
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionFilter">
Expand All @@ -2363,6 +2363,8 @@
SuppressionCommentFilter</a>,
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWarningsFilter">
SuppressWarningsFilter</a>,
<a href="filters/suppresswithplaintextcommentfilter.html#SuppressWithPlainTextCommentFilter">
SuppressWithPlainTextCommentFilter</a>.
</p>
</subsection>
</section>
Expand Down

0 comments on commit f0cd779

Please sign in to comment.