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
Issue #4607: Added moduleId to violation messages #4899
Conversation
CIs should be green |
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.
@Luolc We need a test case where 2 violations are printed with the same text and line number for the same file from running 2 instances of the check. 1 instance should have an ID and the other shouldn't. We expect both violations to be printed out.
This caused us a bug in master. See #4607 (comment) .
@@ -415,7 +416,11 @@ public int compareTo(LocalizedMessage other) { | |||
|
|||
if (lineNo == other.lineNo) { | |||
if (columnNo == other.columnNo) { | |||
result = getMessage().compareTo(other.getMessage()); | |||
result = Comparator.nullsFirst(Comparator.<String>naturalOrder()) |
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.
Classes which are missed in Cobertura coverage report:
com/puppycrawl/tools/checkstyle/api/LocalizedMessage
It looks like either Comparator.nullsFirst
or Comparator.naturalOrder
forces cobertura to ignore the entire class like we have seen with streams
.
@Luolc Please rewrite this class not using those 2 methods and figure out which is causing the problem.
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.
@Luolc , please add such classes to known list - https://github.com/checkstyle/checkstyle/blob/master/config/import-control.xml#L19 to disallow usage of them till we are on cobertura. Such update could be separate PR, to avoid mixing too much in one PR.
Codecov Report
@@ Coverage Diff @@
## master #4899 +/- ##
======================================
Coverage 100% 100%
======================================
Files 287 287
Lines 15488 15501 +13
Branches 3518 3523 +5
======================================
+ Hits 15488 15501 +13
Continue to review full report at Codecov.
|
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.
as CI become green , I am ok to merge.
@romani I just added a UT as rnveach said at #4899 (review) I cannot run verify currently due to #4842. CI failed and I would have a check after I get home to use my Mac |
2ea7028
to
546bd36
Compare
If problem is only at |
@romani @rnveach Thanks for the help. I updated the IDEA inspection config. There would be two more classes in |
@@ -332,7 +332,7 @@ | |||
</inspection_tool> | |||
<inspection_tool class="ClassWithOnlyPrivateConstructors" enabled="true" level="WARNING" enabled_by_default="true" /> | |||
<inspection_tool class="ClassWithTooManyDependencies" enabled="true" level="ERROR" enabled_by_default="true"> | |||
<option name="limit" value="34" /> | |||
<option name="limit" value="36" /> |
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.
@romani We just upped this number because we couldn't find a way to suppress it for a specific file, and here we are upping it again.
Should we just turn it off and report problem to IntelliJ?
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.
lets keep it for now, but will be addressed at #4929
+ "\"/>"); | ||
} | ||
else { | ||
writer.println(" id=\"" |
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.
Why is this surrounded by an if
if the attributes for both are different. We can have both in XML file if we wish.
Since we are completely overriding the source
in the CLI output to only show the ID, we should do the exact same in the XML.
Make this attribute name source
and not id
.
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.
Done.
|
||
if (lineNo == other.lineNo) { | ||
if (columnNo == other.columnNo) { | ||
result = getMessage().compareTo(other.getMessage()); | ||
if (Objects.equals(moduleId, other.moduleId)) { | ||
result = getMessage().compareTo(other.getMessage()); |
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.
@romani I don't see us comparing non-id sources of message. (IE: module name)
If 2 different modules print the exact same message on the same line/column, we will have the same issue as before where we had different ids.
Should this be a new issue where we add module name if id
is not specified to the 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.
moved to #4930
@@ -104,6 +104,23 @@ public void testFormatModuleNameDoesNotContainCheckSuffix() { | |||
} | |||
|
|||
@Test | |||
public void testFormatModuleWithModuleId() { | |||
final AuditEvent mock = PowerMockito.mock(AuditEvent.class); |
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.
Why is this a mock? Why can't we instantiate AuditEvent
and LocalizedMessage
?
Mocks should be a last resort when deep code can be done normally.
You were able to get by without a mock in XMLLoggerTest
.
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.
I saw every UT in this class used mock. I assumed there could be some reason so I just followed them.
So should I avoid using mock in this new UT?
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.
I don't know why this is, but since ever test is like this, we'll just 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.
It was my mistake to allow such code to appear, mocks should not be used in simple cases like this.
new issue - #4931
// BriefUtLogger does not print the module name or id postfix, | ||
// so we need to set logger manually | ||
final ByteArrayOutputStream out = | ||
(ByteArrayOutputStream) Whitebox.getInternalState(this, "stream"); |
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.
From here until the end, why can't we call verify(Checker checker, String fileName, String... expected)
?
Duplicating all this code isn't acceptable.
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.
The super class uses BriefUtLogger
. And it only print message like /path/to/file.java message
. It don't have a module name or id postfix. We need smth like /path/to/file.java message [ModuleName or ModuleId]
So I change the logger and rewrite the verify logic. The verify code I wrote has some differences from the exist ones.
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.
@Luolc Can't we modify existing code in AbstractModuleTestSupport to supply an optional different Logger, one that prints full original message?
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.
I was thinking that we only need this kind of verify here. If we don't ever need this anywhere else, is it necessary to modify the base class?
I could changing this into AbstractModuleTestSupport
, but I preferred just write it in CheckerTest
.
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.
@romani I can hook in to most of the verify
but there is some obstacles and weird things preventing a full hook because of the custom AuditEventUtFormatter
instead of using the real AuditEventDefaultFormatter
.
If you agree this should be fixed, lets move it to another issue. We should have to rewrite AuditEventDefaultFormatter
so we can pick and choose what is displayed for UTs, instead of a custom implementation which is not really regressing full message displays.
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.
lets discuss this in separate issue .... over customization mean over complication .... all that is to please "test" code ... hmmm, lets discuss in detail what you propose , I am a bit suspicious.
final LocalizedMessage message2 = new LocalizedMessage(0, | ||
"com.puppycrawl.tools.checkstyle.checks.coding.messages", "empty.statement", | ||
EMPTY_OBJECT_ARRAY, null, LocalizedMessage.class, null); | ||
final LocalizedMessage message3 = new LocalizedMessage(0, |
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.
It's hard to follow what is the difference between these 3.
Rename message3
to message2
and rename current message2
to messageNull
.
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.
I'm also hesitant to say we should put the strings into local final variables to make reading slightly easier.
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.
Updated
shippable is relaunched |
@romani Even though you already approved, please see my comments pinning you. |
I commented each point. |
Thanks. |
#4607
In XMLLogger, there would be an
id="..."
if the module id is set. (and nosource="..."
)Log message would be
[SEVERITY LEVEL] filePath:lineNo:columnNo: message. [ModuleId]
, if module id is set.I was stuck before for I didn't realize that I need to modify
compareTo
in LocalizedMessage.