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 #3573: Resolve design problem of FileContentsHolder (step 1) #4468

Closed
wants to merge 1 commit into from

Conversation

timurt
Copy link
Contributor

@timurt timurt commented Jun 19, 2017

@MEZk
Copy link
Contributor

MEZk commented Jun 19, 2017

@timurt
CIs must be green.

  1. Coverage threshold is not satisfied. Please, run mvn clean cobertura:check and mvn clean cobertura:cobertura.
  2. IDEA's inspections violations should be resolved:
src/main/java/com/puppycrawl/tools/checkstyle/api
 FileProcessingResult.java (2)
43: FileProcessingResult() Assignment to Collection field this.text from parameter 'text'
44: FileProcessingResult() Assignment to Collection field this.messages from parameter 'messages'

Please, read http://checkstyle.sourceforge.net/idea.html#Inspections and run the inspections locally.

  1. Had problem with Checker class
    [checkstyle] [ERROR] /home/travis/build/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java:67:1: Class Fan-Out Complexity is 26 (max allowed is 25). [ClassFanOutComplexity]

@romani @rnveach
I think that this is a task for separate issue. Despite the fact that we increased class complexity by one, Checker has already been over-complicated.

import java.util.SortedSet;

/**
* Represents the file results.
Copy link
Contributor

Choose a reason for hiding this comment

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

file processing results

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

@@ -41,7 +39,7 @@
/**
* Notify all listeners about the errors in a file.
* @param fileName the audited file
* @param errors the audit errors from the file
* @param fileProcessingResult the audit errors from the file
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, change javadoc

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

@@ -308,12 +309,14 @@ private void processFiles(List<File> files) throws CheckstyleException {
* @throws CheckstyleException if error condition within Checkstyle occurs.
* @noinspection ProhibitedExceptionThrown
*/
private SortedSet<LocalizedMessage> processFile(File file) throws CheckstyleException {
private FileProcessingResult processFile(File file) throws CheckstyleException {
Copy link
Contributor

Choose a reason for hiding this comment

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

method javadoc should be corrected

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

@@ -374,13 +377,13 @@ public void fireFileStarted(String fileName) {
* Notify all listeners about the errors in a file.
*
* @param fileName the audited file
* @param errors the audit errors from the file
* @param fileProcessingResult the audit errors from the file
Copy link
Contributor

Choose a reason for hiding this comment

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

javadoc is not correct. Should be fixed.

* Returns the contents of the file.
* @return an object containing the full text of the file
*/
public FileText getText() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of the method is cryptic. What does 'text' mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to fileText

@timurt timurt force-pushed the 3573 branch 2 times, most recently from cb726f6 to bc0c0c3 Compare June 20, 2017 05:39
@codecov-io
Copy link

codecov-io commented Jun 20, 2017

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #4468   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         287     288    +1     
  Lines       15395   15410   +15     
  Branches     3502    3503    +1     
======================================
+ Hits        15395   15410   +15
Impacted Files Coverage Δ
...awl/tools/checkstyle/api/FileProcessingResult.java 100% <100%> (ø)
.../java/com/puppycrawl/tools/checkstyle/Checker.java 100% <100%> (ø) ⬆️
...awl/tools/checkstyle/api/AbstractFileSetCheck.java 100% <100%> (ø) ⬆️
...rawl/tools/checkstyle/checks/TranslationCheck.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 3694f89...26d984a. Read the comment docs.

@timurt
Copy link
Contributor Author

timurt commented Jun 20, 2017

@MEZk
I am getting TravisCI errors

Connecting to www.oracle.com (www.oracle.com)|23.49.182.138|:80... connected.
HTTP request sent, awaiting response... 503 Service Unavailable
2017-06-20 05:40:47 ERROR 503: Service Unavailable.

@@ -350,7 +350,7 @@
DetailsAST, CheckstyleException, UnsupportedEncodingException, BuildException, ConversionException, FileNotFoundException, TestException"/>
</module>
<module name="ClassFanOutComplexity">
<property name="max" value="25"/>
<property name="max" value="26"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

No, it is not allowed to change the config. There should be good reasons to change the config for all project. Please, revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but otherwise my PR won't pass CI

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, got error

Copy link
Contributor

Choose a reason for hiding this comment

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

@timurt
Please, create an issue. Explain, what your problem is there. Make a suppression, put a link to the issue into suppression file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MEZk
Done

@Test
public void testNonNullFileText() throws IOException {
final String charsetName = "ISO-8859-1";
final FileText fileText = new FileText(new File("src/test/resources/com/puppycrawl/tools/"
Copy link
Contributor

Choose a reason for hiding this comment

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

The test should have its own input file.

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

final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
boolean hasNonFilteredViolations = false;
for (final LocalizedMessage element : errors) {
for (final LocalizedMessage element : fileProcessingResult.getMessages()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, extract fileProcessingResult.getMessages() to the local variable

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

@rnveach
Copy link
Member

rnveach commented Jun 20, 2017

No, it is not allowed to change the config.
but otherwise my PR won't pass CI
done, got error

@timurt CI should be green for us to merge. You must suppress this error for the class.
See https://github.com/rnveach/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java#L290 on how to suppress errors.

@timurt
Copy link
Contributor Author

timurt commented Jun 21, 2017

@rnveach
Done

Copy link
Contributor

@MEZk MEZk left a comment

Choose a reason for hiding this comment

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

  1. Please, fix new points.
  2. Rename commit message to Issue #3573: resolve design problem of FileContentsHolder (step 1) to clearly indicate that this commit and PR are only the first step.

final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
boolean hasNonFilteredViolations = false;
for (final LocalizedMessage element : errors) {
final SortedSet<LocalizedMessage> messages = fileProcessingResult.getMessages();
for (final LocalizedMessage element : messages) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. remove final modifier
  2. rename element to something more appropriate

Copy link
Contributor Author

@timurt timurt Jun 21, 2017

Choose a reason for hiding this comment

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

'auditErrors' name is ok?

Copy link
Contributor Author

@timurt timurt Jun 21, 2017

Choose a reason for hiding this comment

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

remove final modifier

is it about final SortedSet<LocalizedMessage> messages = fileProcessingResult.getMessages(); ?
when I remove it, verification fails with Variable 'messages' should be declared final

Copy link
Member

Choose a reason for hiding this comment

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

@timurt
This line: for (final LocalizedMessage element : messages) {

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

public void testNonNullFileText() throws IOException {
final String charsetName = "ISO-8859-1";
final FileText fileText = new FileText(new File("src/test/resources/com/puppycrawl/tools/"
+ "checkstyle/api/InputFileProcessingResult.java"), charsetName);
Copy link
Contributor

Choose a reason for hiding this comment

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

You do not assert the content of the file directly in the test. Do we really need a separate file? Can we use temp folder and create the empty file there it it satisfied coverage threshold?

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

@@ -174,6 +174,6 @@ protected final void fireErrors(String fileName) {
final SortedSet<LocalizedMessage> errors = messageCollector
.getMessages();
messageCollector.reset();
getMessageDispatcher().fireErrors(fileName, errors);
getMessageDispatcher().fireErrors(fileName, new FileProcessingResult(null, errors));
Copy link
Contributor

Choose a reason for hiding this comment

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

as we need to pass null as the constructor parameter it means that this is a problem in the design. Please, create one more constructor which receives one parameter and sets fileText to null. The constructor can be reused in the FileProcessingResult itself.

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

@MEZk MEZk changed the title Issue #3573: resovle design problem of FileContentsHolder Issue #3573: Resolve design problem of FileContentsHolder (step 1) Jun 21, 2017
@MEZk
Copy link
Contributor

MEZk commented Jun 21, 2017

@rnveach

CI should be green for us to merge.

Localized UTs are failing. Other jobs successfully finished.

@timurt
Ignore Travis CI failures for now.
See #4316 for details.

@MEZk
Copy link
Contributor

MEZk commented Jun 22, 2017

@timurt
Ping

*
* @param messages the sorted set of messages
*/
public FileProcessingResult(SortedSet<LocalizedMessage> messages) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Reuse this constructor in the previous one

Copy link
Contributor Author

@timurt timurt Jun 22, 2017

Choose a reason for hiding this comment

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

Not previous constructor in this one?

Like this or not?

 public FileProcessingResult(SortedSet<LocalizedMessage> messages) {
        this(null, messages);
 }

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

final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
boolean hasNonFilteredViolations = false;
for (final LocalizedMessage element : errors) {
final SortedSet<LocalizedMessage> auditErrors = fileProcessingResult.getMessages();
for (LocalizedMessage element : auditErrors) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename element to errorMessage, errors to errorMessages. We loop over messages, not audit events

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


public class FileProcessingResultTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
Copy link
Contributor

@MEZk MEZk Jun 22, 2017

Choose a reason for hiding this comment

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

Why is it public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

http://junit.org/junit4/javadoc/4.12/org/junit/Rule.html

Annotates fields that reference rules or methods that return a rule. A field must be public, not static, and a subtype of TestRule (preferred) or MethodRule. A method must be public, not static, and must return a subtype of TestRule (preferred) or MethodRule.

Copy link
Contributor

Choose a reason for hiding this comment

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

The filed should have been final. Now, I'm OK with the change.

@@ -0,0 +1,5 @@
package com.puppycrawl.tools.checkstyle.api;
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need this file anymore, please remove

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

@MEZk
Copy link
Contributor

MEZk commented Jun 22, 2017

@timurt
Please fix TeamCity violations

@timurt
Copy link
Contributor Author

timurt commented Jun 22, 2017

@MEZk done

@MEZk
Copy link
Contributor

MEZk commented Jun 22, 2017

@rnveach
I'm OK with the changes. Please, do final review.
Localized tests are still failing.

@MEZk MEZk requested a review from rnveach June 22, 2017 15:09
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.

@MEZk Please see my comments directed to you.
Only 1 real item for @timurt .

public FileText getFileText() {
FileText result = null;
if (fileText != null) {
result = new FileText(fileText);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a new instance? FileText is almost immutable except for lineBreaks, which is just populated on demand.
Can't we return the field as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rnveach
Cobertura fails when I just return value, as the example I took FileContents#getText method

Copy link
Member

@rnveach rnveach Jun 22, 2017

Choose a reason for hiding this comment

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

@timurt Please explain how cobertura is failing with just return fileText;.
There are no branches or such, and we know the method is already being executed.
Is coverage failing in another class?

Copy link
Contributor

Choose a reason for hiding this comment

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

@timurt
This point is not addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MEZk
done

final AuditEvent event = new AuditEvent(this, stripped, element);
final SortedSet<LocalizedMessage> errorMessages = fileProcessingResult.getMessages();
for (LocalizedMessage errorMessage : errorMessages) {
final AuditEvent event = new AuditEvent(this, stripped, errorMessage);
Copy link
Member

Choose a reason for hiding this comment

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

Step 2
6. Add FileContents to audit event to make it available for filters. We will add AST root to FileContents later

@MEZk Shouldn't the event eventually accept FileProcessingResult?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rnveach
Maybe, but this should not be done in this PR. I'll think about it.

Copy link
Contributor

@MEZk MEZk Jun 22, 2017

Choose a reason for hiding this comment

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

@rnveach
You are right. AuditEvent should receive FileProcessingResult. Changed the plan.
#3573 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

ok.

*
* @param messages the sorted set of messages
*/
public FileProcessingResult(SortedSet<LocalizedMessage> messages) {
Copy link
Member

Choose a reason for hiding this comment

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

@MEZk I think we should eventually remove this constructor as it doesn't contain the file contents. We are always working with a file, so I can't see why it shouldn't be populated (aside from any exception on file).

Copy link
Contributor

@MEZk MEZk Jun 22, 2017

Choose a reason for hiding this comment

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

@rnveach
Yes, you are right. We always can instantiate FileText based on the file name and pass error messages and FileText to the constructor with two parameters. I did not see this fact. Hovewer, it will require to catch IOException from FileText constructor.

@timurt
Please, remove the constructor with one parameter. You always have the file path (file name) to instantiate FileText object and pass it to the constructor. So, both FileText object and the sorted set of localized messages can be instantiated.

Copy link
Member

Choose a reason for hiding this comment

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

it will require to catch IOException from FileText constructor.

@MEZk I'm not sure where you think IOException is coming from. Both constructors don't have an IOException being thrown right now and I am not talking about creating FileText in the constructor.
FileText is already created in TreeWalker https://github.com/checkstyle/checkstyle/pull/4468/files#diff-503cc093d3169abd5697cc8189f27f32R319 and passed around. We should be using that FileText everywhere somehow.

Copy link
Contributor

@MEZk MEZk Jun 22, 2017

Choose a reason for hiding this comment

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

Both constructors don't have an IOException being thrown right now

FileText constructor throws IOException.

We will need to create FileText here. The constructor of FileText which receives the File object throws IOException.

Copy link
Member

Choose a reason for hiding this comment

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

@MEZk We pass FileText to all FileSets at https://github.com/checkstyle/checkstyle/pull/4468/files/8da878eaf14710f1d578ecadfa1caafe94512dc3#diff-503cc093d3169abd5697cc8189f27f32R321 . So TreeWalker should be able to hand it over to AbstractCheck without having to create a new one.
Since the class is still List<String> outside Checker, it depends on #3034 being done first.

Copy link
Contributor

@MEZk MEZk Jun 24, 2017

Choose a reason for hiding this comment

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

@rnveach
DO we need 'file' as the first parameter of the process method? We already have the reference to the file in FileText.

Copy link
Member

@rnveach rnveach Jun 25, 2017

Choose a reason for hiding this comment

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

@MEZk No we don't need it, but to accomplish this we would have to send the direct class FileText to all parties as they only receive List<String> as described in #3034.
It also seems slightly weird we would go to FileText for the file's name. we will soon also have FileProcessingResult with a lot of file related stuff.

Should we create a single class like CheckstyleFile. It will contain the file name, FileProcessingResult, FileText, and everything else related to the input and output of the process method? We could move the unnecessary fields from FileText into CheckstyleFile.
If so, let's create another issue on this.

Copy link
Contributor

@MEZk MEZk Jun 26, 2017

Choose a reason for hiding this comment

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

The new issue was created #4527.

related to the input and output of the process method

Why do we need to include the output of the process method into CheckstyleFile? Can you explain in the issue ?
FileProcessingResult represents results (localized messages and information about the processed file). It can include CheckstyleFile which can be an argument of the process method.

*/
@Override
public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
public void fireErrors(String fileName, FileProcessingResult fileProcessingResult) {
Copy link
Member

Choose a reason for hiding this comment

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

@MEZk Should fileName be in FileProcessingResult?
It seems like they are fully conntected. FileText can also retrieve the File object, which can get it's name too.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rnveach
Yes, we can get the name of the file from FileText which will become part of FileProcessingResult. Thus, we do not need the first parameter of fireErrors at all.

@timurt
Please, change the signature of fireErrors to

void fireErrors(FileProcessingResult fileProcessingResult) 

Copy link
Contributor Author

@timurt timurt Jun 23, 2017

Choose a reason for hiding this comment

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

@MEZk @rnveach
I'm stuck with one thing. Inside Checker#processFile, there is try-catch for IOException in a case specified file does not exist, it means message will be logged, but fileText will be null. If FileText object is null then we will not be able to extract fileName, absolutePath and etc. from it, for example inside Checker#fireErrors it will throw NPE.
Problem is fileName is used in various places even if the file does not exist
I can suggest to add additional filePath field to FileProcessingResult or left PRed implementation?

Copy link
Member

@rnveach rnveach Jun 23, 2017

Choose a reason for hiding this comment

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

If FileText object is null then we will not be able to extract fileName, absolutePath and etc.

fileName will be a separate field inside FileProcessingResult, imo. Then we won't have to worry when FileText is null.

@MEZk
Copy link
Contributor

MEZk commented Jun 24, 2017

@timurt
Timur, please start working on #3034 as it blocks this PR.

@timurt
Copy link
Contributor Author

timurt commented Jul 9, 2017

@MEZk
Rebased, fixed conflicts and points

@timurt
Copy link
Contributor Author

timurt commented Jul 9, 2017

@MEZk
TeamCity violation
80: CheckerTest Class 'CheckerTest' has too many dependencies (34 > 33)
How can I fix it?

@Vladlis
Copy link
Contributor

Vladlis commented Jul 9, 2017

@timurt
you should suppress this inspection, here are examples of other suppressions: https://github.com/checkstyle/checkstyle/search?utf8=%E2%9C%93&q=noinspection&type=

Copy link
Contributor

@MEZk MEZk left a comment

Choose a reason for hiding this comment

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

@timurt
Please, suppress the TC violation. CheckerTest is a test class, it should be allowed to have many dependencies in the class.

new Object[] {"arg"}, null, getClass(), null));
final FileProcessingResult processingResult = new FileProcessingResult(
file.getAbsolutePath(), fileText, messages);
assertEquals(charsetName, processingResult.getFileText().getCharset().name());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use just assertNotNull(processingResult.getFileText()) ?

Copy link
Contributor Author

@timurt timurt Jul 9, 2017

Choose a reason for hiding this comment

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

I inserted this assert before assertEquals(charsetName, processingResult.getFileText().getCharset().name());
I see no reason to delete previous assert

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need

assertEquals(charsetName, processingResult.getFileText().getCharset().name());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no actual reason, just to assert charset didn't change
I can remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

@timurt
Please, remove. It is unnecessary. Judging by the name of the test the main idea is to check that FileText is not null when it is passed to FileProcessingResult.

@MEZk MEZk requested review from romani and rnveach and removed request for romani and rnveach July 9, 2017 17:48
@timurt
Copy link
Contributor Author

timurt commented Jul 9, 2017

@MEZk
Did I inspection suppression in wrong way?

/**
 * @noinspection ClassWithTooManyDependencies
 */
public class CheckerTest extends BaseCheckTestSupport {

@timurt timurt force-pushed the 3573 branch 2 times, most recently from e6a0c57 to b082e33 Compare July 10, 2017 09:38
@romani
Copy link
Member

romani commented Jul 11, 2017

Did I inspection suppression in wrong way?

please reference name of inspection at https://github.com/checkstyle/checkstyle/blob/master/config/intellij-idea-inspections.xml#L1996

@timurt timurt force-pushed the 3573 branch 6 times, most recently from 799cf44 to d8b5b75 Compare July 11, 2017 16:34
@@ -1997,6 +1997,29 @@
<inspection_tool class="SuperClassHasFrequentlyUsedInheritors" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SuperTearDownInFinally" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="SuppressionAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<scope name="Tests" level="ERROR" enabled="true">
Copy link
Contributor

@MEZk MEZk Jul 11, 2017

Choose a reason for hiding this comment

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

Why was the scope changed?

Copy link
Contributor Author

@timurt timurt Jul 11, 2017

Choose a reason for hiding this comment

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

@MEZk
my previous tries were not successful so I tried to create another scope
I am just out of ideas

this is my previous configuration

<inspection_tool class="SuppressionAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
        <option name="myAllowedSuppressions">
            <list>
                <option value="deprecation" />
                <option value="unchecked" />
                <option value="rawtypes" />
                <!-- There is no other way to deliver filename that was under processing.
                     See https://github.com/checkstyle/checkstyle/issues/2285-->
                <option value="ProhibitedExceptionThrown" />
                <option value="MismatchedQueryAndUpdateOfCollection" />
                <!-- Till https://github.com/checkstyle/checkstyle/issues/3066 -->
                <option value="ProhibitedExceptionCaught" />
                <!-- No way to split apart huge if/else branches in test. -->
                <option value="IfStatementWithTooManyBranches" />
                <!-- we have to catch Exception in Checker and rethrow it -->
                <option value="ProhibitedExceptionThrown" />
                <!-- we have to use it when pass null argument in test purporses -->
                <option value="NullArgumentToVariableArgMethod" />
 <!-- we have to use it because number of dependencies of CheckerTest exceeds 33. -->
                    <option value="ClassWithTooManyDependencies" />
            </list>
        </option>
    </inspection_tool>

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use scope for the certain option to make less changes to the config.
See https://github.com/timurt/checkstyle/blob/d8b5b759e859f66c8c5e932bce7eb5906e626912/config/intellij-idea-inspections.xml#L967

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MEZk
Is it correct?

 <inspection_tool class="ClassWithTooManyDependencies" enabled="true" level="ERROR" enabled_by_default="true">
        <scope name="Tests" level="ERROR" enabled="true">
            <!-- we have to use it because number of dependencies of CheckerTest exceeds 33. -->
            <option name="limit" value="40" />
        </scope>
        <option name="limit" value="33" />
    </inspection_tool>
@SuppressWarnings("ClassWithTooManyDependencies")
public class CheckerTest extends BaseCheckTestSupport {

Copy link
Contributor Author

@timurt timurt Jul 12, 2017

Choose a reason for hiding this comment

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

scope Production means src/main?
scope Tests means src/test ?

@timurt timurt force-pushed the 3573 branch 2 times, most recently from 562cedd to 9f264b9 Compare July 11, 2017 18:09
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.

Sorry, that I did not find time to review your intentions far before.

Sorry, I am against this update:

<scope name="Tests" level="ERROR" enabled="true">
<!-- we have to use it because number of dependencies of CheckerTest exceeds 33. -->
<option name="limit" value="40" />
</scope>
Copy link
Member

Choose a reason for hiding this comment

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

if there is problem in one file for whole rule, we do not change a rule, we do suppression in certain class.
please use javadoc tag suppression for CheckerTest.

*/
@Override
public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
public void fireErrors(FileProcessingResult fileProcessingResult) {
Copy link
Member

Choose a reason for hiding this comment

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

fileProcessingResult.getFileText is not used it is already sign smth is wrong in design.

please see my comment at #3573 (comment)

@MEZk
Copy link
Contributor

MEZk commented Jul 13, 2017

@timurt @rnveach
Unfortunately, after discussion with @romani we came to the conclusion that this PR and changes in step 1 do not make sense at all. FileProcessingResult looks strange. It breaks the idea of TreeWalker, AST and all AST-related stuff in future should not be available for Checker. Please, see #4714 for more details.

@romani
If you are ok, please close this PR.

@romani
Copy link
Member

romani commented Jul 14, 2017

it is better to close this PR

@romani romani closed this Jul 14, 2017
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

6 participants