Skip to content
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

Merged
merged 1 commit into from Aug 10, 2017

Conversation

Luolc
Copy link
Contributor

@Luolc Luolc commented Aug 4, 2017

#4607

In XMLLogger, there would be an id="..." if the module id is set. (and no source="...")

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.

@romani
Copy link
Member

romani commented Aug 4, 2017

CIs should be green

Copy link
Member

@rnveach rnveach left a 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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romani

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.

Copy link
Member

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-io
Copy link

codecov-io commented Aug 7, 2017

Codecov Report

Merging #4899 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #4899   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         287     287           
  Lines       15488   15501   +13     
  Branches     3518    3523    +5     
======================================
+ Hits        15488   15501   +13
Impacted Files Coverage Δ
...l/tools/checkstyle/AuditEventDefaultFormatter.java 100% <100%> (ø) ⬆️
...pycrawl/tools/checkstyle/api/LocalizedMessage.java 100% <100%> (ø) ⬆️
...ava/com/puppycrawl/tools/checkstyle/XMLLogger.java 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14a22ed...0dc6ed7. Read the comment docs.

Copy link
Member

@romani romani left a 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.

@Luolc
Copy link
Contributor Author

Luolc commented Aug 7, 2017

@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

@Luolc Luolc force-pushed the issue4607 branch 2 times, most recently from 2ea7028 to 546bd36 Compare August 7, 2017 11:00
@romani
Copy link
Member

romani commented Aug 7, 2017

I cannot run verify currently due

If problem is only at MainTest.testCreateListenerWithLocationIllegalStateException, you can exclude it execution -Dtest='*,!MainTest' , it will fail on missed coverage, but you can recheck coverage manually.

@rnveach
Copy link
Member

rnveach commented Aug 7, 2017

I cannot run verify currently due to #4842.

@Luolc I get around this issue currently by running verify in pieces similar to like travis does. Look at travis.yml to see the commands separated out. Just remember to delete the file before running Checkstyle on itself.

@Luolc
Copy link
Contributor Author

Luolc commented Aug 7, 2017

@romani @rnveach Thanks for the help.

I updated the IDEA inspection config. There would be two more classes in CheckerTest.
UT for #4899 (review) is placed in CheckerTest. I am not very sure if this is the proper place.

@@ -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" />
Copy link
Member

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?

Copy link
Member

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=\""
Copy link
Member

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.

Copy link
Contributor Author

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());
Copy link
Member

@rnveach rnveach Aug 7, 2017

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?

Copy link
Member

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);
Copy link
Member

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.

Copy link
Contributor Author

@Luolc Luolc Aug 7, 2017

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?

Copy link
Member

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.

Copy link
Member

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");
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@rnveach rnveach Aug 8, 2017

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.

Copy link
Member

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,
Copy link
Member

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.

Copy link
Member

@rnveach rnveach Aug 7, 2017

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@romani
Copy link
Member

romani commented Aug 9, 2017

shippable is relaunched

@rnveach
Copy link
Member

rnveach commented Aug 9, 2017

@romani Even though you already approved, please see my comments pinning you.

@romani romani merged commit 78de3dc into checkstyle:master Aug 10, 2017
@romani
Copy link
Member

romani commented Aug 10, 2017

I commented each point.

@rnveach
Copy link
Member

rnveach commented Aug 10, 2017

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants