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

Update doc for DescendantToken #7587

Closed
timurt opened this issue Feb 23, 2020 · 24 comments
Closed

Update doc for DescendantToken #7587

timurt opened this issue Feb 23, 2020 · 24 comments

Comments

@timurt
Copy link
Contributor

timurt commented Feb 23, 2020

https://checkstyle.org/config_misc.html#DescendantToken

Add example for each existing config to show what code is ok and what code cause violation.
Good example is https://checkstyle.org/config_naming.html#AbstractClassName

please play with module/Check by means of https://checkstyle.org/cmdline.html to understand how it works.


PLEASE READ https://github.com/checkstyle/checkstyle/wiki/Good-practice-on-how-to-update-examples

@checkstyle checkstyle deleted a comment from DXTkastb May 16, 2021
@checkstyle checkstyle deleted a comment from timurt May 16, 2021
@checkstyle checkstyle deleted a comment from harshit82 Mar 24, 2022
@checkstyle checkstyle deleted a comment from nrmancuso Mar 24, 2022
@checkstyle checkstyle deleted a comment from harshit82 Mar 24, 2022
@checkstyle checkstyle deleted a comment from ShubhraSuman Apr 23, 2022
@romani
Copy link
Member

romani commented Feb 7, 2023

No assignments, just make comment "I am on it" and send PR

@athuma
Copy link

athuma commented Feb 28, 2023

Hi @romani i am new to open source and would like to contribute i am familiar with java but i don't know where to start can you please help me with how to start?

@checkstyle checkstyle deleted a comment from ConnectBhawna Mar 1, 2023
@checkstyle checkstyle deleted a comment from ConnectBhawna Mar 1, 2023
@romani
Copy link
Member

romani commented Mar 1, 2023

@athuma
Copy link

athuma commented Mar 1, 2023

@romani i have gone through it and i think i can do spellcheck of Identifiers by english dictionary project will be submitting my application through GSOC thanks for your help

@athuma
Copy link

athuma commented Mar 1, 2023

i am working on this issue

@athuma
Copy link

athuma commented Mar 2, 2023

ss
@romani i am not getting how should i pass the xml file for checking the case for switch statement in this issue

i have attached the file i am passing but getting error "unable to parse configuration stream"
can you please help me

@romani
Copy link
Member

romani commented Mar 2, 2023

I did wrong link pasting. Fixed.
Please fix several issues to prove that you can resolve issues quickly enough.
Please follow https://github.com/checkstyle/checkstyle/wiki/To-GSoC-participant
Amount of merged Pull Requests is most valuable criteria for selection in summer.

Here is example how to run CLI https://checkstyle.org/report_issue.html#How_to_report_a_bug.3F

@athuma
Copy link

athuma commented Mar 2, 2023

hh
kk

@romani getting error like this

@nrmancuso
Copy link
Member

@athuma it is very difficult the read screenshots, usually it is much better to share as copy pasted code blocks of output (see our bug report template as an example).

@romani
Copy link
Member

romani commented Mar 2, 2023

Reading is ok, but most critical that we can not reuse your config as is to reproduce quickly issue on our side.

@athuma
Copy link

athuma commented Mar 2, 2023

Athu@Atharv MINGW64 ~/Desktop

$ cat Switch.java

package basic;

public class Switch {

public static void main(String[] args) {
        int x=1;
        switch(x)
        {
        case 1: System.out.println("hi");
        break;
        }

}

}

Athu@Atharv MINGW64 ~/Desktop

$ cat file.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
      "-//Checkstyle//DTD Check Configuration 1.3//EN" 
      "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
	<module name="TreeWalker">
		<module name="DescendantToken">
			<property name="tokens" value="LITERAL SWITCH"/>
			<property name="maximumdepth" value="2"/>
			<property name="limitedtokens" value="LITERAL_DEFAULT"/>
			<property name="minimumnumber" value="1"/>
		</module>
	</module>
</module>

Athu@Atharv MINGW64 ~/Desktop

$ java -jar checkstyle-10.8.0-all.jar -c file.xml Switch.java

com.puppycrawl.tools.checkstyle.api.CheckstyleException: unable to parse configuration stream - Content is not allowed in prolog.:1:1
at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:321)
at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:266)
at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:380)
at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:338)
at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:195)
at com.puppycrawl.tools.checkstyle.Main.main(Main.java:130)
Caused by: org.xml.sax.SAXParseException; systemId: file:/C:/Users/Athu/Desktop/file.xml; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1465)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:978)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:542)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:889)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:637)
at com.puppycrawl.tools.checkstyle.XmlLoader.parseInputSource(XmlLoader.java:81)
at com.puppycrawl.tools.checkstyle.ConfigurationLoader.parseInputSource(ConfigurationLoader.java:196)
at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:315)
... 5 more
Checkstyle ends with 1 errors.

@romani @nrmancuso

@romani
Copy link
Member

romani commented Mar 3, 2023

@athuma, please try to remove content from xml file to see what symbol damage xml parsing. There might be some invisible symbol.

I can not spot a problem, so it means we need brute force.

@romani
Copy link
Member

romani commented Mar 3, 2023

See example of execution at #2507

@athuma
Copy link

athuma commented Mar 3, 2023

$ cat Switch.java
package basic;

public class Switch {

    public static void main(String[] args) {
            int x=1;
            switch(x)
            {
            case 1: System.out.println("hi");
            break;
            }

    }

}

Athu@Atharv MINGW64 ~/Desktop

$ cat file.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
      "-//Checkstyle//DTD Check Configuration 1.3//EN"
      "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="DescendantToken">
        <property name="tokens" value="LITERAL_SWITCH"/>
         <property name="maximumDepth" value="2"/>
         <property name="limitedTokens" value="LITERAL_DEFAULT"/>
        <property name="minimumNumber" value="1"/>
    </module>
  </module>
</module>

Athu@Atharv MINGW64 ~/Desktop

$ java -jar checkstyle-10.8.0-all.jar -c file.xml Switch.java

Starting audit...
[ERROR] C:\Users\Athu\Desktop\Switch.java:7:17: Count of 0 for 'LITERAL_SWITCH' descendant 'LITERAL_DEFAULT' is less than minimum count 1. [DescendantToken]
Audit done.
Checkstyle ends with 1 errors.

For Switch with default case :

Athu@Atharv MINGW64 ~/Desktop
$ cat Switch.java
package basic;

public class Switch {

    public static void main(String[] args) {
            int x=1;
            switch(x)
            {
            case 1: System.out.println("hi");
            break;
            default: System.out.println("Default case");
            break;
            }

    }

}

Athu@Atharv MINGW64 ~/Desktop
$ java -jar checkstyle-10.8.0-all.jar -c file.xml Switch.java
Starting audit...
Audit done.

I think this is correct and working out good with no changes in xml it automatically worked today please check this so that i can raise a pull @romani

@romani
Copy link
Member

romani commented Mar 3, 2023

Please send PR

@navyakarna
Copy link

can i work on this issue

athuma added a commit to athuma/checkstyle that referenced this issue Mar 10, 2023
@Rishabh7798
Copy link

I want to work on this issue please assign me this task

@romani
Copy link
Member

romani commented Mar 17, 2023

@Rishabh7798 , just send a pull request.
looks like we lost connection to contributors above.

@ShivamPandey00
Copy link
Contributor

I am on it

@ShivamPandey00
Copy link
Contributor

@romani @nrmancuso there are total 17 config check. Do we need add example for each config ?

@romani
Copy link
Member

romani commented Mar 21, 2023

Yes

@nrmancuso
Copy link
Member

@romani I think we can make exception and allow different code for each example for this check, to allow user to focus only on what is important

@romani
Copy link
Member

romani commented Mar 21, 2023

For this check it is ok to have different java code for all configs

@romani
Copy link
Member

romani commented Mar 27, 2023

Fix is merged

@romani romani closed this as completed Mar 27, 2023
@github-actions github-actions bot added this to the 10.9.4 milestone Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants