New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All checks that use AbstractCheck#getLine()
should check code points instead of characters for spacing
#10924
Comments
Another option to consider is to have |
Why not add a |
In |
Can I work on this? |
@MUzairS15 sure, please be aware that we will need to generate check regression reports for all checks listed in the issue description. |
Thank you for your response. |
@nmancus1 Need help. |
@MUzairS15 circling back on this issue, I see that you edited your comment.
Yes, please do. |
…oints for spaces
I have created a draft PR, pls check when you find time, |
@MUzairS15 a good strategy for this update might be:
This process may help to give you a better feel for the reason why we are doing this update, and provide some insight that will be helpful when you return to Here is an article(and additional links) from StackOverflow that helped me to better understand code points: https://stackoverflow.com/questions/23979676/java-what-are-characters-code-points-and-surrogates-what-difference-is-there/23980020 ; perhaps this can also aid you in your work on this issue. |
…oints for spaces
…oints for spaces
We have missed a bunch of instances where we use ➜ checks git:(master) grep -R 'getLines(' | grep -v "indentCheck\|\.getLine(\|int"
AvoidEscapedUnicodeCharactersCheck.java: final String line = getLines()[lineNo - 1];
indentation/ArrayInitHandler.java: final String line = getIndentCheck().getLines()[lineNo - 1];
indentation/CommentsIndentationCheck.java: final String[] lines = getLines();
indentation/CommentsIndentationCheck.java: final char[] line = getLines()[lineNo - 1].toCharArray();
indentation/AnnotationArrayInitHandler.java: final String line = getIndentCheck().getLines()[lineNo - 1];
TrailingCommentCheck.java: final String line = getLines()[lineNo - 1];
TrailingCommentCheck.java: String line = getLines()[lineNo - 1];
TrailingCommentCheck.java: final String lineBefore = getLines()[lineNo - 1].substring(0, ast.getColumnNo());
blocks/EmptyBlockCheck.java: final String[] lines = getLines();
imports/CustomImportOrderCheck.java: final String[] lines = getLines();
coding/FallThroughCheck.java: final String[] lines = getLines();
whitespace/MethodParamPadCheck.java: final String line = getLines()[parenAST.getLineNo() - 1];
whitespace/EmptyForIteratorPadCheck.java: final String line = getLines()[semi.getLineNo() - 1];
whitespace/EmptyLineSeparatorCheck.java: final String prePreviousLine = getLines()[lineNo - number];
whitespace/EmptyLineSeparatorCheck.java: final String lineBefore = getLines()[lineNo - 2];
whitespace/EmptyLineSeparatorCheck.java: final String lineWithComment = getLines()[comment.getLineNo() - 1].trim();
whitespace/SeparatorWrapCheck.java: final String currentLine = getLines()[lineNo - 1];
whitespace/AbstractParenPadCheck.java: final String line = getLines()[ast.getLineNo() - 1];
whitespace/AbstractParenPadCheck.java: final String line = getLines()[ast.getLineNo() - 1];
whitespace/EmptyForInitializerPadCheck.java: final String line = getLines()[semiLineIdx];
These checks will also need to be updated. |
Yes, I was going to ask but wanted to fix those first😅 |
@pbludov @strkkk @romani @rnveach since scope of this issue has grown, and needs of codepoint compatible methods/ operations is increasing (trimming, checking whitespace, finding first character of type, etc.), should we consider creating our own We could call it |
I think such way will only bring more mess and confusion. Some custom StringUtil class with all utility methods (I do not think there will be a lot of them) seems a better approach to me. |
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java Line 252 in 3fec584
|
Yes, we do not need exact position of a character in this case. |
Working on this, but require more time because, since last week I am busy with college activities exams, and other stuff because of sem-end this month. |
…oints for spaces
…oints for spaces
…oints for spaces
…oints for spaces
…oints for spaces
…oints for spaces
@nick-mancuso Should I send PR to replace usage of
|
@MUzairS15 let's create a checklist from comment at #10924 (comment)
Ideally, we want to replace all with |
|
TODO: move Will send PR when all checks have been updated. |
@MUzairS15 what do we have left to do here? Let's update checklist with checks from #10924 (comment) and send PR for #10924 (comment) |
@MUzairS15 ping |
Affected checks:
https://checkstyle.sourceforge.io/config_misc.html#CommentsIndentation
https://checkstyle.sourceforge.io/config_blocks.html#RightCurly
https://checkstyle.sourceforge.io/config_blocks.html#LeftCurly
https://checkstyle.sourceforge.io/config_whitespace.html#GenericWhitespace
https://checkstyle.sourceforge.io/config_whitespace.html#NoWhitespaceBefore
https://checkstyle.sourceforge.io/config_whitespace.html#SingleSpaceSeparator
https://checkstyle.sourceforge.io/config_whitespace.html#NoWhitespaceAfter
Noticed in #10837 and #10920, any check where we use
AbstractCheck#getLine()
(extracting a line of code from a source file) should be converted to using code points instead of characters. Now that Checkstyle supports Unicode in variable names and counts Unicode surrogate pairs correctly, we should make sure that all affected checks use code points instead of character arrays to ensure that we are indexing the correct character.The text was updated successfully, but these errors were encountered: