-
Notifications
You must be signed in to change notification settings - Fork 112
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
1. Fixed a bug when adding extra spaces after the parameter name. 2. Fixed a bug when using comment-like text in string literals. #1301
Conversation
The error no longer appears for string literals similar to comments.
@yegor256 @pnatashap ping |
@PeJetuz can you please merge master into your branch, since there are merge conflicts now? |
@yegor256 done. |
@yegor256 Hi!, the branch has been updated. |
@volodya-lombrozo can you please help and review this pull request? It's pretty large and I'm afraid of merging it without a proper review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz I have left just a few small suggestions. Also, it would be nice to have a short description of the changes made in this PR description; otherwise, it's hard to trace the original problem you're trying to pinpoint. Anyway, thanks so much for your contribution!
* @param patt Pattern for checking the contents of a tag in a string. | ||
* @param rep Reference to a method for writing a message to the log. | ||
*/ | ||
RequiredJavaDocTag(final String name, final Pattern patt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz NIT: What do you think about placing all the parameters either on one line, or each parameter in a separate line for the sake of consistency?
RequiredJavaDocTag(final String name, final Pattern patt, final Reporter rep) {
or
RequiredJavaDocTag(
final String name,
final Pattern patt,
final Reporter rep
) {
The same is relevant for all the rest methods in this class.
I understand, that the format you used comes from the old classes from this repository, so it's not really important and you can leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! Done.
|
||
@Test | ||
void success() { | ||
final String[] lines = {" *", " * @since 0.3", " *"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz NIT: Many redundant variables are used in this test. Fore example, you can remove lines
variables entirely.
There is the explanation why it's bad: https://www.yegor256.com/2015/09/01/redundant-variables-are-evil.html
Also, there is a study that emphasises significant negative impact of a hight number of identifiers in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! Done.
|
||
/** | ||
* Valid multi line literal. | ||
* @checkstyle ArrayTrailingCommaCheck (6 lines) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz Why do you need to add ArrayTrailingCommaCheck
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! I added a description in the comments to the methods. Is this ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz Maybe we can just remove this ArrayTrailingCommaCheck
and add one more comma to the last element?
public static final String[] MULTILINE_LITERAL = {
" /**", " * @since 0.3.4.4.", " **/",
" /**",
" * @since 0.3.4.4.",
" **/",
};
In this case you don't need to suppress this violation and to add explanation to it.
@@ -0,0 +1,5 @@ | |||
6:This kind of comment is not allowed. | |||
9:First sentence in a comment should start with a capital letter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz Could you help me here, please? I don't clearly understand why we have exactly this line numbers 6
,9
,9
,15
,19
.
Line 6
- /* C-style comment */
- OK
Line 9
- /** first sentence in a comment should start with a capital letter */
- OK
Line 9
- Why did you duplicate it?
Line 15
- The end of the incorrect java doc, but not the line itself (why not the 14
line?)
Line 19
- Why not the 18
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! Duplication occurs because we have this check triggered twice, once in the class com.qulice.checkstyle.MultiLineCommentCheck and the second time in the class com.qulice.checkstyle.SingleLineCommentCheck.
Unfortunately, I don't know where it would be better to place the description of this case.
} | ||
} | ||
|
||
public void setFormat(final String fmt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz I understand why you need to add setters, but in general it is a bad practice.
I suggest to add at least some javadocs that would explain why we need them and why we can't remove them from the code base. It will preserve them from the future removal. The same is relevant for SingleLineCommentCheck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! I added a description in the comments to the methods.
@Override | ||
public void visitToken(final DetailAST ast) { | ||
if (ast.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) { | ||
this.line = new StringBuilder(ast.getText()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz Why do you need to initialise this.line
field exactly here? Maybe we can initialise it directly in the constructor or in the field declaration?
private final StringBuilder line = new StringBuilder();
By doing this you will be able just to append
text to it. First of all, this should simplify the code, and what is the most important, you will make this.line
field immutable. How Immutability Helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! I described why we reinitialize the variable in the comment when declaring it. Unfortunately, I didn't find a place where it is done correctly. Is this ok?
} | ||
|
||
@Test | ||
void successWithSpaces() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! Done.
@volodya-lombrozo Thank you! I'll read the articles and fix. |
7259ac0
to
4844907
Compare
@volodya-lombrozo Thank you very much! I changed the commit message to describe the issues fixed. Is this okay? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz Thank you for the clarification. It's almost finished. I've just left several small comments.
|
||
/** | ||
* Valid multi line literal. | ||
* @checkstyle ArrayTrailingCommaCheck (6 lines) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz Maybe we can just remove this ArrayTrailingCommaCheck
and add one more comma to the last element?
public static final String[] MULTILINE_LITERAL = {
" /**", " * @since 0.3.4.4.", " **/",
" /**",
" * @since 0.3.4.4.",
" **/",
};
In this case you don't need to suppress this violation and to add explanation to it.
<module name="com.qulice.checkstyle.MultiLineCommentCheck"> | ||
<property name="format" value=" */\*\* +[^A-Z\{ ][\W\s\S]*"/> | ||
<property name="message" value="First sentence in a comment should start with a capital letter."/> | ||
<property name="id" value="FirstLetterInCommentShouldBeCapital3"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz I have some doubts about id
properties here. Can we just omit them? Or at least to give them more meaningful names. FirstLetterInCommentShouldBeCapital2
-> FirstLetterInMultiLineCommenWithAsterisk
. Or something like this. FirstLetterInCommentShouldBeCapital2
and FirstLetterInCommentShouldBeCapital3
look strange to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks for your help with ArrayTrailingCommaCheck!
I renamed id
and changed the message for this check. Thanks for pointing this out, I think the message should be more friendly now.
* during the class under test and the field is reinitialized with a new object. | ||
*/ | ||
@SuppressWarnings("PMD.AvoidStringBufferField") | ||
private StringBuilder line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz It seems, that the line
is not an appropriate name of variable here. Since it's a "MultilineComment", I would give it lines
or text
name. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Absolutely agree. Fixed.
</module> | ||
<module name="com.qulice.checkstyle.MultiLineCommentCheck"> | ||
<property name="format" value=" */\*\*\W+\* +[^A-Z\{ ][\W\s\S]*"/> | ||
<property name="message" value="First sentence in a comment should start with a capital letter."/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeJetuz I would highly recommend you to change this error message:
First sentence in a comment should start with a capital letter.
->
First sentence in a multiline comment should start with a capital letter.
It will greatly help to distinct these two cases. The same you can do in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Thanks! I've changed the messages so they should be more friendly now.
* @param line Line position. * @param column Column position. 2. Fixed a bug when using comment-like text in string literals: final String comment = "/* some text */"; Fixes for issue yegor256#1079
4844907
to
dfc2c62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rultor merge |
@pnatashap @yegor256
Please review, this should resolve the issue 1079.