Skip to content

Commit

Permalink
Issue checkstyle#10837: WhitespaceAround misrecognizes white spaces a…
Browse files Browse the repository at this point in the history
…fter emojis
  • Loading branch information
nrmancuso authored and rnveach committed Oct 9, 2021
1 parent 09e65bf commit 84e45f7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions .ci/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ elif
elist
Ellipsize
emacs
Emoji
emptyblock
emptycatchblock
emptyforinitializerpad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,17 +690,18 @@ public void visitToken(DetailAST ast) {
final String line = getLine(ast.getLineNo() - 1);
final int before = ast.getColumnNo() - 1;
final int after = ast.getColumnNo() + ast.getText().length();
final int[] codePoints = line.codePoints().toArray();

if (before >= 0) {
final char prevChar = line.charAt(before);
final char prevChar = Character.toChars(codePoints[before])[0];
if (shouldCheckSeparationFromPreviousToken(ast)
&& !Character.isWhitespace(prevChar)) {
log(ast, MSG_WS_NOT_PRECEDED, ast.getText());
}
}

if (after < line.length()) {
final char nextChar = line.charAt(after);
if (after < codePoints.length) {
final char nextChar = Character.toChars(codePoints[after])[0];
if (shouldCheckSeparationFromNextToken(ast, nextChar)
&& !Character.isWhitespace(nextChar)) {
log(ast, MSG_WS_NOT_FOLLOWED, ast.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,27 @@ public void testWhitespaceAroundAllTokens() throws Exception {
getPath("InputWhitespaceAroundAllTokens.java"), expected);
}

@Test
public void testWhitespaceAroundAfterEmoji() throws Exception {
final String[] expected = {
"25:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
"26:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"27:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"27:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
"29:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"29:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
"29:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"29:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
"29:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"29:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
"29:32: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"29:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
"29:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"29:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
"29:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
"29:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
};
verifyWithInlineConfigParser(
getPath("InputWhitespaceAroundAfterEmoji.java"), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
WhitespaceAround
allowEmptyConstructors = (default)false
allowEmptyMethods = (default)false
allowEmptyTypes = true
allowEmptyLoops = (default)false
allowEmptyLambdas = (default)false
allowEmptyCatches = true
ignoreEnhancedForColon = (default)true
tokens = ASSIGN, ARRAY_INIT, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, \
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND, LCURLY, \
LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, \
LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, \
LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, \
PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, \
STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND, WILDCARD_TYPE, GENERIC_START, \
GENERIC_END, ELLIPSIS
*/
package com.puppycrawl.tools.checkstyle.checks.whitespace.whitespacearound;

public class InputWhitespaceAroundAfterEmoji {
String a = "🎄❤️😂" + "🎅🔥😊🎁"; // ok
String b = "🎄❤️😂"+ "🎅🔥😊🎁"; // violation
String c = "🎄❤️😂" +"🎅🔥😊🎁"; // violation
String d = "🎄❤️😂"+"🎅🔥😊🎁"; // 2 violations
String e = "🎄" + "❤" + "️😂" + "🎅" + "🔥" + "😊" + "🎁"; // ok
String f = "🎄"+"❤"+"️😂"+"🎅"+"🔥"+"😊"+"🎁"; // 12 violations
}

0 comments on commit 84e45f7

Please sign in to comment.