Skip to content

Commit

Permalink
Issue checkstyle#3902: Fixed formatting issue in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarshah94 committed Mar 13, 2017
1 parent 31bb4ea commit 5675a4b
Show file tree
Hide file tree
Showing 124 changed files with 68,176 additions and 277 deletions.
10 changes: 10 additions & 0 deletions .ci/travis/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ all-sevntu-checks)
diff -u web.txt file.txt
;;

no-error-test-sbe)
CS_POM_VERSION=$(mvn -q -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
echo version:$CS_POM_VERSION
mvn clean install -Pno-validations
git clone https://github.com/real-logic/simple-binary-encoding.git
cd simple-binary-encoding
sed -i'' "s/'com.puppycrawl.tools:checkstyle:.*'/'com.puppycrawl.tools:checkstyle:$CS_POM_VERSION'/" build.gradle
./gradlew build
;;

no-exception-test-checkstyle-sevntu-checkstyle)
git clone https://github.com/checkstyle/contribution
cd contribution/checkstyle-tester
Expand Down
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Mandatory to understand and do:
^(minor|config|infra|doc|spelling): .*$
b) It contains only one line of text
c) Must not end with a period, space, or tab
d) Commit message should be less than or equal to 200 characters

To avoid multiple iterations of fixes and CIs failures, please read http://checkstyle.sourceforge.net/contributing.html

Expand Down
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ matrix:
- DESC="sonarqube.com"
- CMD="./.ci/travis/travis.sh sonarqube"

# No error testing - simple-binary-encoding
- jdk: oraclejdk8
env:
- DESC="no error test on simple-binary-encoding"
- CMD="./.ci/travis/travis.sh no-error-test-sbe"

script:
- SKIP_FILES=".github|appveyor.yml|circle.yml|distelli-manifest.yml|fast-forward-merge.sh|LICENSE|LICENSE.apache20|README.md|release.sh|RIGHTS.antlr|shippable.yml|wercker.yml"
- SKIP_CI=$(if [[ $(git diff --name-only HEAD HEAD~1 | grep -vE "$SKIP_FILES" | cat | wc -c | sed 's/^ *//' ) > 0 ]]; then echo false; else echo true; fi;)
Expand Down
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,6 @@
<exclude>com/puppycrawl/tools/checkstyle/gui/ParseTreeTableModel*.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/TreeTableCellRenderer*.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/gui/TreeTableModelAdapter*.class</exclude>
<!-- GUI model classes without tests -->
<exclude>com/puppycrawl/tools/checkstyle/gui/MainFrameModel*.class</exclude>
<!-- deprecated classes -->
<exclude>com/puppycrawl/tools/checkstyle/checks/AbstractFormatCheck.class</exclude>
<exclude>com/puppycrawl/tools/checkstyle/checks/AbstractDeclarationCollector*.class</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public Object fooString()
String fakeUnicode = "asd\tsasd";
String fakeUnicode2 = "\\u23\\u123i\\u";
String content = "";
return "\ufeff" + content ; // byte order mark ok
/*byte order mark ok*/return "\ufeff" + content ;
}

public Object fooChar()
{
/*warn*/char unitAbbrev2 = '\u03bc';
char unitAbbrev3 = '\u03bc'; // Greek letter mu, "s" ok
String content = "";
return '\ufeff' + content; // byte order mark ok
/*byte order mark ok*/return '\ufeff' + content;
}

public void multiplyString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ public class AvoidEscapedUnicodeCharactersCheck
/** Regular expression for Unicode chars. */
private static final Pattern UNICODE_REGEXP = Pattern.compile("\\\\u[a-fA-F0-9]{4}");

/** Regular expression Unicode control characters. */
/**
* Regular expression Unicode control characters.
*
* @see <a href="https://en.wiktionary.org/wiki/Appendix:Control_characters">
* Appendix:Control characters</a>
*/
private static final Pattern UNICODE_CONTROL = Pattern.compile("\\\\(u|U)"
+ "(00[0-1][0-1A-Fa-f]|00[8-9][0-9A-Fa-f]|034(f|F)|070(f|F)"
+ "|180(e|E)|200[b-fB-F]|202[b-eB-E]|206[0-4a-fA-F]"
+ "(00[0-1][0-9A-Fa-f]|00[8-9][0-9A-Fa-f]|00(a|A)(d|D)|034(f|F)|070(f|F)"
+ "|180(e|E)|200[b-fB-F]|202[a-eA-E]|206[0-4a-fA-F]"
+ "|[fF]{3}[9a-bA-B]|[fF][eE][fF]{2})");

/** Regular expression for all escaped chars. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* {@link TokenTypes#RESOURCE_SPECIFICATION RESOURCE_SPECIFICATION},
* {@link TokenTypes#SUPER_CTOR_CALL SUPER_CTOR_CALL},
* {@link TokenTypes#QUESTION QUESTION},
* {@link TokenTypes#LAMBDA LAMBDA},
* </p>
* <p>
* An example of how to configure the check is:
Expand Down Expand Up @@ -131,7 +132,8 @@ public void visitToken(DetailAST ast) {
case TokenTypes.ENUM_CONSTANT_DEF:
case TokenTypes.LITERAL_NEW:
case TokenTypes.LITERAL_SYNCHRONIZED:
visitNewEnumConstDefAnnotationSync(ast);
case TokenTypes.LAMBDA:
visitTokenWithOptionalParentheses(ast);
break;
default:
processLeft(ast.findFirstToken(TokenTypes.LPAREN));
Expand All @@ -140,11 +142,13 @@ public void visitToken(DetailAST ast) {
}

/**
* Checks parens in {@link TokenTypes#ENUM_CONSTANT_DEF}, {@link TokenTypes#ANNOTATION}
* {@link TokenTypes#LITERAL_SYNCHRONIZED} and {@link TokenTypes#LITERAL_NEW}.
* Checks parens in token which may not contain parens, e.g.
* {@link TokenTypes#ENUM_CONSTANT_DEF}, {@link TokenTypes#ANNOTATION}
* {@link TokenTypes#LITERAL_SYNCHRONIZED}, {@link TokenTypes#LITERAL_NEW} and
* {@link TokenTypes#LAMBDA}.
* @param ast the token to check.
*/
private void visitNewEnumConstDefAnnotationSync(DetailAST ast) {
private void visitTokenWithOptionalParentheses(DetailAST ast) {
final DetailAST parenAst = ast.findFirstToken(TokenTypes.LPAREN);
if (parenAst != null) {
processLeft(parenAst);
Expand Down Expand Up @@ -229,6 +233,7 @@ private static int[] makeAcceptableTokens() {
TokenTypes.QUESTION,
TokenTypes.RESOURCE_SPECIFICATION,
TokenTypes.SUPER_CTOR_CALL,
TokenTypes.LAMBDA,
};
}

Expand Down
8 changes: 8 additions & 0 deletions src/site/resources/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ h2:hover .anchor {
.anchor {
display: none;
}

.source pre {
white-space: pre-wrap !important;
white-space: -moz-pre-wrap !important;
white-space: -pre-wrap !important;
white-space: -o-pre-wrap !important;
word-wrap: break-word !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.IntStream;

import org.junit.Test;

Expand All @@ -32,6 +34,115 @@
import com.puppycrawl.tools.checkstyle.api.TokenTypes;

public class AvoidEscapedUnicodeCharactersCheckTest extends BaseCheckTestSupport {

// C0 (ASCII and derivatives)
// https://en.wiktionary.org/wiki/Appendix:Control_characters#C0_.28ASCII_and_derivatives.29
private static final int[] C0_CONTROL_CHARACTER_INDICES = {
0x0000,
0x0001,
0x0002,
0x0003,
0x0004,
0x0005,
0x0006,
0x0007,
0x0008,
0x0009,
0x000a,
0x000b,
0x000c,
0x000d,
0x000e,
0x000f,
0x0010,
0x0011,
0x0012,
0x0013,
0x0014,
0x0015,
0x0016,
0x0017,
0x0018,
0x0019,
0x001a,
0x001b,
0x001c,
0x001d,
0x001e,
0x001f,
};

// C1 set
// https://en.wiktionary.org/wiki/Appendix:Control_characters#C1_set
private static final int[] C1_CONTROL_CHARACTER_INDICES = {
0x0080,
0x0081,
0x0082,
0x0083,
0x0084,
0x0085,
0x0086,
0x0087,
0x0088,
0x0089,
0x008a,
0x008b,
0x008c,
0x008d,
0x008e,
0x008f,
0x0090,
0x0091,
0x0092,
0x0093,
0x0094,
0x0095,
0x0096,
0x0097,
0x0098,
0x0099,
0x009a,
0x009b,
0x009c,
0x009d,
0x009e,
0x009f,
};

// Other control characters which do not occur in the C0 or C1 sets
// https://en.wiktionary.org/wiki/Appendix:Control_characters#Unicode_control_characters
private static final int[] OTHER_CONTROL_CHARACTER_INDICES = {
0x00ad,
0x034f,
0x070f,
0x180e,
0x200b,
0x200c,
0x200d,
0x200e,
0x200f,
0x202a,
0x202b,
0x202c,
0x202d,
0x202e,
0x2060,
0x2061,
0x2062,
0x2063,
0x2064,
0x206a,
0x206b,
0x206c,
0x206d,
0x206e,
0x206f,
0xfeff,
0xfff9,
0xfffa,
0xfffb,
};

@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator + filename);
Expand Down Expand Up @@ -224,4 +335,26 @@ public void testGetAcceptableTokens() {
final int[] expected = {TokenTypes.STRING_LITERAL, TokenTypes.CHAR_LITERAL };
assertArrayEquals(expected, actual);
}

@Test
public void testAllowEscapesForControlCharacterSetForAllCharacters() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidEscapedUnicodeCharactersCheck.class);
checkConfig.addAttribute("allowEscapesForControlCharacters", "true");

final int indexOfStartLineInInputFile = 6;
final String message = getCheckMessage(MSG_KEY);
final String[] expected = IntStream.rangeClosed(0, 0xffff)
.parallel()
.filter(val -> !isControlCharacter(val))
.mapToObj(msg -> indexOfStartLineInInputFile + msg + ": " + message)
.toArray(String[]::new);
verify(checkConfig, getPath("InputAllEscapedUnicodeCharacters.java"), expected);
}

private static boolean isControlCharacter(final int character) {
return Arrays.binarySearch(C0_CONTROL_CHARACTER_INDICES, character) >= 0
|| Arrays.binarySearch(C1_CONTROL_CHARACTER_INDICES, character) >= 0
|| Arrays.binarySearch(OTHER_CONTROL_CHARACTER_INDICES, character) >= 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public void setUp() {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
+ "whitespace" + File.separator
+ "operatorwrap" + File.separator
+ filename);
}

@Test
Expand All @@ -60,7 +62,7 @@ public void testDefault()
"48:30: " + getCheckMessage(MSG_LINE_NEW, "&"),
"61:30: " + getCheckMessage(MSG_LINE_NEW, "&"),
};
verify(checkConfig, getPath("InputOpWrap.java"), expected);
verify(checkConfig, getPath("InputOperatorWrap.java"), expected);
}

@Test
Expand All @@ -72,7 +74,7 @@ public void testOpWrapEol()
"24:13: " + getCheckMessage(MSG_LINE_PREVIOUS, "&&"),
"29:13: " + getCheckMessage(MSG_LINE_PREVIOUS, "&&"),
};
verify(checkConfig, getPath("InputOpWrap.java"), expected);
verify(checkConfig, getPath("InputOperatorWrap.java"), expected);
}

@Test
Expand All @@ -82,7 +84,7 @@ public void testNonDefOpsDefault()
final String[] expected = {
"33:33: " + getCheckMessage(MSG_LINE_NEW, "::"),
};
verify(checkConfig, getPath("InputOpWrap.java"), expected);
verify(checkConfig, getPath("InputOperatorWrap.java"), expected);
}

@Test
Expand All @@ -94,7 +96,7 @@ public void testNonDefOpsWrapEol()
"31:21: " + getCheckMessage(MSG_LINE_PREVIOUS, "::"),
"36:21: " + getCheckMessage(MSG_LINE_PREVIOUS, "::"),
};
verify(checkConfig, getPath("InputOpWrap.java"), expected);
verify(checkConfig, getPath("InputOperatorWrap.java"), expected);
}

@Test
Expand All @@ -105,7 +107,7 @@ public void testAssignEol()
final String[] expected = {
"42:13: " + getCheckMessage(MSG_LINE_PREVIOUS, "="),
};
verify(checkConfig, getPath("InputOpWrap.java"), expected);
verify(checkConfig, getPath("InputOperatorWrap.java"), expected);
}

@Test
Expand All @@ -115,7 +117,7 @@ public void testInvalidOption() throws Exception {
try {
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputOpWrap.java"), expected);
verify(checkConfig, getPath("InputOperatorWrap.java"), expected);
fail("exception expected");
}
catch (CheckstyleException ex) {
Expand Down
Loading

0 comments on commit 5675a4b

Please sign in to comment.