codenarc-user Mailing List for CodeNarc (Page 2)
Brought to you by:
chrismair
This list is closed, nobody may subscribe to it.
2010 |
Jan
|
Feb
|
Mar
|
Apr
(14) |
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
(3) |
Oct
(11) |
Nov
(29) |
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(27) |
Feb
(8) |
Mar
(26) |
Apr
(9) |
May
(27) |
Jun
(8) |
Jul
(24) |
Aug
(27) |
Sep
|
Oct
(4) |
Nov
(7) |
Dec
(19) |
2012 |
Jan
|
Feb
(7) |
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
(3) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(4) |
2013 |
Jan
(2) |
Feb
(3) |
Mar
|
Apr
(3) |
May
(1) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2014 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
|
2015 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(10) |
Oct
(1) |
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(10) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2018 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Hamlet D'A. <ham...@gm...> - 2016-09-15 11:55:50
|
Sounds like you're looking for AstUtils.classNodeImplementsType :) /** * This method tells you if a ClassNode implements or extends a certain class. * @param node * the node * @param target * the class * @return * true if the class node 'is a' target */ On Thu, Sep 15, 2016 at 12:14 AM, <AGo...@cf...> wrote: > Thanks to the advice here I have made some good progress. I have a rule > that is doing pretty much what I want, but I would like to add one more > thing that is giving me trouble. > > I have the TryCatchStatement, and from there I can get the CatchStatement > list. For each CatchStatement I can get the ClassNode for the exception > type and from there I can check the ClassNode name to see if what is being > caught is an Exception. > > I would like to go the extra step and confirm that the CatchStatement is > catching a java.lang.Exception and not just a Throwable someone decided to > name Exception. Is that possible? > > I could add another rule that makes sure none of the compiled code names a > class "Exception", but it seems like I should be able to check the package > of the class being caught. If someone writes their own java.lang.Exception > class then I think we have gone beyond my scope, but there are definitely > names that get reused across packages and this appears to be an important > capability. > > Thanks! > > -Andrew Goodspeed > > > > From: Andy Goodspeed/IS/CFG > To: cod...@li... > Date: 09/06/2016 06:32 PM > Subject: Re: [Codenarc-user] Writing CodeNarc rules > ------------------------------ > > > Thanks Hamlet! That should be very helpful. Thanks also to Chris Mair who > had some helpful suggestions. > > I will hope to get a chance to try them both out; still digging out after > a week off. Once I get back to this I will report back. > > Thanks again! > > -Andrew Goodspeed > > > > > From: "Hamlet D'Arcy" <ham...@gm...> > To: AGo...@cf... > Cc: cod...@li... > Date: 09/01/2016 09:24 AM > Subject: Re: [Codenarc-user] Writing CodeNarc rules > ------------------------------ > > > > Not sure if you ever got an answer to this... > > Here is the latest Javadoc for MethodNode: > *http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html* > <http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html> > > A MethodNode only ever has one Statement! so if your Method has only a > TryCatchStatement then you know nothing follows it. > If your method has-a BlockStatement then your method will be several > statements long. > > The best way to explore is to write more unit tests and just look and see > what is in the AST! > > On Thu, Aug 18, 2016 at 9:18 PM, <*AGo...@cf...* > <AGo...@cf...>> wrote: > Hello all. > > I am trying to write a CodeNarc rule and am struggling with just how to > use the AST code visitor support (or anything else) to get were I want to > go. Does anyone know of a resource that might be helpful and/or give me > some firsthand assistance? I have looked at all of the obvious ones from > the CodeNarc site as well as the distributed rules, google searches, etc. > > I am trying to write a rule that checks to make sure the body of > particular methods consists entirely of a try/catch block where Exception > is caught. I have gotten as far as verifying the first statement in the > method is a try/catch statement using an AbstractMethodVisitor but am > struggling a bit in figuring out how to make sure there is no statement > following it in the method. > > This is where I am on my astVisitorClass. > > *class*MyTestAstVisitor *extends*AbstractMethodVisitor { > @Override > *void*visitMethod(MethodNode methodNode) { > *if*(Modifier.*isPublic*(methodNode.modifiers)) { > *if*(AstUtil.*isEmptyBlock*(methodNode.code)) { > addViolation(methodNode, "Action ${methodNode.name} in ${ > currentClassName} is empty") > } *else*{ > *def*tryCatchStatement = methodNode.firstStatement > *if*(!(tryCatchStatement *instanceof*TryCatchStatement)) { > addViolation(methodNode, "First statement of action > ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. > name}") > } *else*{ > // try/catch statement, but nothing more? > } > } > } > } > } > > I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. > > Thanks for any insight. > > -Andrew Goodspeed > NOTICE: This message and all attachments transmitted with it may contain > sensitive and/or confidential information intended solely for the use of > the addressee. If the reader of this message is not the intended recipient, > you are hereby notified that any reading, dissemination, distribution, > copying, or other use of this message or its attachments is strictly > prohibited. If you have received this message in error, please notify the > sender immediately and delete this message and all copies and backups > thereof. If you choose to communicate with us by email, you should be aware > that the security of incoming Internet email is not secure. We strongly > encourage you to use encrypted email when sending sensitive and/or > confidential information. By sending sensitive or confidential email > messages that are not encrypted, you accept the risks of such lack of > security and possible lack of confidentiality. If you elect to communicate > from your workplace computer, you also should be aware that your employer > and its agents have access to email communications between you and us. > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > Codenarc-user mailing list > *Cod...@li...* > <Cod...@li...> > *https://lists.sourceforge.net/lists/listinfo/codenarc-user* > <https://lists.sourceforge.net/lists/listinfo/codenarc-user> > > > > > -- > Hamlet D'Arcy > *ham...@gm...* <ham...@gm...>----------- > ------------------------------------------------------------------- > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > > NOTICE: This message and all attachments transmitted with it may contain > sensitive and/or confidential information intended solely for the use of > the addressee. If the reader of this message is not the intended recipient, > you are hereby notified that any reading, dissemination, distribution, > copying, or other use of this message or its attachments is strictly > prohibited. If you have received this message in error, please notify the > sender immediately and delete this message and all copies and backups > thereof. If you choose to communicate with us by email, you should be aware > that the security of incoming Internet email is not secure. We strongly > encourage you to use encrypted email when sending sensitive and/or > confidential information. By sending sensitive or confidential email > messages that are not encrypted, you accept the risks of such lack of > security and possible lack of confidentiality. If you elect to communicate > from your workplace computer, you also should be aware that your employer > and its agents have access to email communications between you and us. > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > -- Hamlet D'Arcy ham...@gm... |
From: <AGo...@cf...> - 2016-09-14 22:13:36
|
Thanks to the advice here I have made some good progress. I have a rule that is doing pretty much what I want, but I would like to add one more thing that is giving me trouble. I have the TryCatchStatement, and from there I can get the CatchStatement list. For each CatchStatement I can get the ClassNode for the exception type and from there I can check the ClassNode name to see if what is being caught is an Exception. I would like to go the extra step and confirm that the CatchStatement is catching a java.lang.Exception and not just a Throwable someone decided to name Exception. Is that possible? I could add another rule that makes sure none of the compiled code names a class "Exception", but it seems like I should be able to check the package of the class being caught. If someone writes their own java.lang.Exception class then I think we have gone beyond my scope, but there are definitely names that get reused across packages and this appears to be an important capability. Thanks! -Andrew Goodspeed From: Andy Goodspeed/IS/CFG To: cod...@li... Date: 09/06/2016 06:32 PM Subject: Re: [Codenarc-user] Writing CodeNarc rules Thanks Hamlet! That should be very helpful. Thanks also to Chris Mair who had some helpful suggestions. I will hope to get a chance to try them both out; still digging out after a week off. Once I get back to this I will report back. Thanks again! -Andrew Goodspeed From: "Hamlet D'Arcy" <ham...@gm...> To: AGo...@cf... Cc: cod...@li... Date: 09/01/2016 09:24 AM Subject: Re: [Codenarc-user] Writing CodeNarc rules Not sure if you ever got an answer to this... Here is the latest Javadoc for MethodNode: http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html A MethodNode only ever has one Statement! so if your Method has only a TryCatchStatement then you know nothing follows it. If your method has-a BlockStatement then your method will be several statements long. The best way to explore is to write more unit tests and just look and see what is in the AST! On Thu, Aug 18, 2016 at 9:18 PM, <AGo...@cf...> wrote: Hello all. I am trying to write a CodeNarc rule and am struggling with just how to use the AST code visitor support (or anything else) to get were I want to go. Does anyone know of a resource that might be helpful and/or give me some firsthand assistance? I have looked at all of the obvious ones from the CodeNarc site as well as the distributed rules, google searches, etc. I am trying to write a rule that checks to make sure the body of particular methods consists entirely of a try/catch block where Exception is caught. I have gotten as far as verifying the first statement in the method is a try/catch statement using an AbstractMethodVisitor but am struggling a bit in figuring out how to make sure there is no statement following it in the method. This is where I am on my astVisitorClass. classMyTestAstVisitor extendsAbstractMethodVisitor { @Override voidvisitMethod(MethodNode methodNode) { if(Modifier.isPublic(methodNode.modifiers)) { if(AstUtil.isEmptyBlock(methodNode.code)) { addViolation(methodNode, "Action ${methodNode.name} in ${ currentClassName} is empty") } else{ deftryCatchStatement = methodNode.firstStatement if(!(tryCatchStatement instanceofTryCatchStatement)) { addViolation(methodNode, "First statement of action ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. name}") } else{ // try/catch statement, but nothing more? } } } } } I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. Thanks for any insight. -Andrew Goodspeed NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user -- Hamlet D'Arcy ham...@gm... ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. |
From: <AGo...@cf...> - 2016-09-08 20:56:41
|
Yes, I did see the screencast, and it is nice as far as it goes. I was trying to get the rule written as a Groovy script to work for me as it seemed easier to play around with things that way. I used the MyStaticFieldRule example as the basis to get that working. The piece that was missing in the documentation to make that easy was how to reference the script as a rule. After a while googling I ended up with something that worked and my ruleSet.groovy file looked like this. ruleset { description ''' A Sample Groovy RuleSet containing all CodeNarc Rules You can use this as a template for your own custom RuleSet. Just delete the rules that you don't want to include. ''' rule('file:scripts/codenarc/play/MyStaticFieldRule.groovy') } The file path is relative to my Grails project root so that running "grails codenarc" finds it. I then got stuck on the AST paradigm but hopefully I have enough to move forward with now. Thanks for the help! From: "Hamlet D'Arcy" <ham...@gm...> To: AGo...@cf... Cc: cod...@li... Date: 09/07/2016 10:30 AM Subject: Re: [Codenarc-user] Writing CodeNarc rules Did you see the screencast? :) https://www.youtube.com/watch?v=ZPu8FaZZwRw On Wed, Sep 7, 2016 at 12:32 AM, <AGo...@cf...> wrote: Thanks Hamlet! That should be very helpful. Thanks also to Chris Mair who had some helpful suggestions. I will hope to get a chance to try them both out; still digging out after a week off. Once I get back to this I will report back. Thanks again! -Andrew Goodspeed From: "Hamlet D'Arcy" <ham...@gm...> To: AGo...@cf... Cc: cod...@li... Date: 09/01/2016 09:24 AM Subject: Re: [Codenarc-user] Writing CodeNarc rules Not sure if you ever got an answer to this... Here is the latest Javadoc for MethodNode: http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html A MethodNode only ever has one Statement! so if your Method has only a TryCatchStatement then you know nothing follows it. If your method has-a BlockStatement then your method will be several statements long. The best way to explore is to write more unit tests and just look and see what is in the AST! On Thu, Aug 18, 2016 at 9:18 PM, <AGo...@cf...> wrote: Hello all. I am trying to write a CodeNarc rule and am struggling with just how to use the AST code visitor support (or anything else) to get were I want to go. Does anyone know of a resource that might be helpful and/or give me some firsthand assistance? I have looked at all of the obvious ones from the CodeNarc site as well as the distributed rules, google searches, etc. I am trying to write a rule that checks to make sure the body of particular methods consists entirely of a try/catch block where Exception is caught. I have gotten as far as verifying the first statement in the method is a try/catch statement using an AbstractMethodVisitor but am struggling a bit in figuring out how to make sure there is no statement following it in the method. This is where I am on my astVisitorClass. classMyTestAstVisitor extendsAbstractMethodVisitor { @Override voidvisitMethod(MethodNode methodNode) { if(Modifier.isPublic(methodNode.modifiers)) { if(AstUtil.isEmptyBlock(methodNode.code)) { addViolation(methodNode, "Action ${methodNode.name} in ${ currentClassName} is empty") } else{ deftryCatchStatement = methodNode.firstStatement if(!(tryCatchStatement instanceofTryCatchStatement)) { addViolation(methodNode, "First statement of action ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. name}") } else{ // try/catch statement, but nothing more? } } } } } I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. Thanks for any insight. -Andrew Goodspeed NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user -- Hamlet D'Arcy ham...@gm... ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user -- Hamlet D'Arcy ham...@gm... ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. |
From: Hamlet D'A. <ham...@gm...> - 2016-09-07 14:29:33
|
Did you see the screencast? :) https://www.youtube.com/watch?v=ZPu8FaZZwRw On Wed, Sep 7, 2016 at 12:32 AM, <AGo...@cf...> wrote: > Thanks Hamlet! That should be very helpful. Thanks also to Chris Mair who > had some helpful suggestions. > > I will hope to get a chance to try them both out; still digging out after > a week off. Once I get back to this I will report back. > > Thanks again! > > -Andrew Goodspeed > > > > From: "Hamlet D'Arcy" <ham...@gm...> > To: AGo...@cf... > Cc: cod...@li... > Date: 09/01/2016 09:24 AM > Subject: Re: [Codenarc-user] Writing CodeNarc rules > ------------------------------ > > > > Not sure if you ever got an answer to this... > > Here is the latest Javadoc for MethodNode: > *http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html* > <http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html> > > A MethodNode only ever has one Statement! so if your Method has only a > TryCatchStatement then you know nothing follows it. > If your method has-a BlockStatement then your method will be several > statements long. > > The best way to explore is to write more unit tests and just look and see > what is in the AST! > > On Thu, Aug 18, 2016 at 9:18 PM, <*AGo...@cf...* > <AGo...@cf...>> wrote: > Hello all. > > I am trying to write a CodeNarc rule and am struggling with just how to > use the AST code visitor support (or anything else) to get were I want to > go. Does anyone know of a resource that might be helpful and/or give me > some firsthand assistance? I have looked at all of the obvious ones from > the CodeNarc site as well as the distributed rules, google searches, etc. > > I am trying to write a rule that checks to make sure the body of > particular methods consists entirely of a try/catch block where Exception > is caught. I have gotten as far as verifying the first statement in the > method is a try/catch statement using an AbstractMethodVisitor but am > struggling a bit in figuring out how to make sure there is no statement > following it in the method. > > This is where I am on my astVisitorClass. > > *class*MyTestAstVisitor *extends*AbstractMethodVisitor { > @Override > *void*visitMethod(MethodNode methodNode) { > *if*(Modifier.*isPublic*(methodNode.modifiers)) { > *if*(AstUtil.*isEmptyBlock*(methodNode.code)) { > addViolation(methodNode, "Action ${methodNode.name} in ${ > currentClassName} is empty") > } *else*{ > *def*tryCatchStatement = methodNode.firstStatement > *if*(!(tryCatchStatement *instanceof*TryCatchStatement)) { > addViolation(methodNode, "First statement of action > ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. > name}") > } *else*{ > // try/catch statement, but nothing more? > } > } > } > } > } > > I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. > > Thanks for any insight. > > -Andrew Goodspeed > NOTICE: This message and all attachments transmitted with it may contain > sensitive and/or confidential information intended solely for the use of > the addressee. If the reader of this message is not the intended recipient, > you are hereby notified that any reading, dissemination, distribution, > copying, or other use of this message or its attachments is strictly > prohibited. If you have received this message in error, please notify the > sender immediately and delete this message and all copies and backups > thereof. If you choose to communicate with us by email, you should be aware > that the security of incoming Internet email is not secure. We strongly > encourage you to use encrypted email when sending sensitive and/or > confidential information. By sending sensitive or confidential email > messages that are not encrypted, you accept the risks of such lack of > security and possible lack of confidentiality. If you elect to communicate > from your workplace computer, you also should be aware that your employer > and its agents have access to email communications between you and us. > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > Codenarc-user mailing list > *Cod...@li...* > <Cod...@li...> > *https://lists.sourceforge.net/lists/listinfo/codenarc-user* > <https://lists.sourceforge.net/lists/listinfo/codenarc-user> > > > > > -- > Hamlet D'Arcy > *ham...@gm...* <ham...@gm...>----------- > ------------------------------------------------------------------- > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > > NOTICE: This message and all attachments transmitted with it may contain > sensitive and/or confidential information intended solely for the use of > the addressee. If the reader of this message is not the intended recipient, > you are hereby notified that any reading, dissemination, distribution, > copying, or other use of this message or its attachments is strictly > prohibited. If you have received this message in error, please notify the > sender immediately and delete this message and all copies and backups > thereof. If you choose to communicate with us by email, you should be aware > that the security of incoming Internet email is not secure. We strongly > encourage you to use encrypted email when sending sensitive and/or > confidential information. By sending sensitive or confidential email > messages that are not encrypted, you accept the risks of such lack of > security and possible lack of confidentiality. If you elect to communicate > from your workplace computer, you also should be aware that your employer > and its agents have access to email communications between you and us. > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > -- Hamlet D'Arcy ham...@gm... |
From: <AGo...@cf...> - 2016-09-06 22:31:55
|
Thanks Hamlet! That should be very helpful. Thanks also to Chris Mair who had some helpful suggestions. I will hope to get a chance to try them both out; still digging out after a week off. Once I get back to this I will report back. Thanks again! -Andrew Goodspeed From: "Hamlet D'Arcy" <ham...@gm...> To: AGo...@cf... Cc: cod...@li... Date: 09/01/2016 09:24 AM Subject: Re: [Codenarc-user] Writing CodeNarc rules Not sure if you ever got an answer to this... Here is the latest Javadoc for MethodNode: http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html A MethodNode only ever has one Statement! so if your Method has only a TryCatchStatement then you know nothing follows it. If your method has-a BlockStatement then your method will be several statements long. The best way to explore is to write more unit tests and just look and see what is in the AST! On Thu, Aug 18, 2016 at 9:18 PM, <AGo...@cf...> wrote: Hello all. I am trying to write a CodeNarc rule and am struggling with just how to use the AST code visitor support (or anything else) to get were I want to go. Does anyone know of a resource that might be helpful and/or give me some firsthand assistance? I have looked at all of the obvious ones from the CodeNarc site as well as the distributed rules, google searches, etc. I am trying to write a rule that checks to make sure the body of particular methods consists entirely of a try/catch block where Exception is caught. I have gotten as far as verifying the first statement in the method is a try/catch statement using an AbstractMethodVisitor but am struggling a bit in figuring out how to make sure there is no statement following it in the method. This is where I am on my astVisitorClass. classMyTestAstVisitor extendsAbstractMethodVisitor { @Override voidvisitMethod(MethodNode methodNode) { if(Modifier.isPublic(methodNode.modifiers)) { if(AstUtil.isEmptyBlock(methodNode.code)) { addViolation(methodNode, "Action ${methodNode.name} in ${ currentClassName} is empty") } else{ deftryCatchStatement = methodNode.firstStatement if(!(tryCatchStatement instanceofTryCatchStatement)) { addViolation(methodNode, "First statement of action ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. name}") } else{ // try/catch statement, but nothing more? } } } } } I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. Thanks for any insight. -Andrew Goodspeed NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user -- Hamlet D'Arcy ham...@gm... ------------------------------------------------------------------------------ _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. |
From: Roshan D. <ros...@gm...> - 2016-09-02 01:23:06
|
Great, good to see you back in action! On Friday 2 September 2016, Hamlet D'Arcy <ham...@gm...> wrote: > I'm still alive! > > I work at Microsoft now but still in Switzerland. > > If anyone out there is using TypeScript then be sure to check out all my > TypeScript linting rules. It's even an official Microsoft git repo :) > https://github.com/Microsoft/tslint-microsoft-contrib > > I don't know.... there is just something about writing linting rules that > makes me happy :) > > > > On Thu, Sep 1, 2016 at 3:32 PM, Roshan Dawrani <ros...@gm... > <javascript:_e(%7B%7D,'cvml','ros...@gm...');>> wrote: > >> Aha! What a pleasant surprise to see a mail from you again. Long time, >> Hamlet! >> >> On Thu, Sep 1, 2016 at 6:52 PM, Hamlet D'Arcy <ham...@gm... >> <javascript:_e(%7B%7D,'cvml','ham...@gm...');>> wrote: >> >>> Not sure if you ever got an answer to this... >>> >>> Here is the latest Javadoc for MethodNode: http://docs.groovy >>> -lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html >>> >>> A MethodNode only ever has one Statement! so if your Method has only a >>> TryCatchStatement then you know nothing follows it. >>> If your method has-a BlockStatement then your method will be several >>> statements long. >>> >>> The best way to explore is to write more unit tests and just look and >>> see what is in the AST! >>> >>> On Thu, Aug 18, 2016 at 9:18 PM, <AGo...@cf... >>> <javascript:_e(%7B%7D,'cvml','AGo...@cf...');>> wrote: >>> >>>> Hello all. >>>> >>>> I am trying to write a CodeNarc rule and am struggling with just how to >>>> use the AST code visitor support (or anything else) to get were I want to >>>> go. Does anyone know of a resource that might be helpful and/or give me >>>> some firsthand assistance? I have looked at all of the obvious ones from >>>> the CodeNarc site as well as the distributed rules, google searches, etc. >>>> >>>> I am trying to write a rule that checks to make sure the body of >>>> particular methods consists entirely of a try/catch block where Exception >>>> is caught. I have gotten as far as verifying the first statement in the >>>> method is a try/catch statement using an AbstractMethodVisitor but am >>>> struggling a bit in figuring out how to make sure there is no statement >>>> following it in the method. >>>> >>>> This is where I am on my astVisitorClass. >>>> >>>> *class*MyTestAstVisitor *extends*AbstractMethodVisitor { >>>> @Override >>>> *void*visitMethod(MethodNode methodNode) { >>>> *if*(Modifier.*isPublic*(methodNode.modifiers)) { >>>> *if*(AstUtil.*isEmptyBlock*(methodNode.code)) { >>>> addViolation(methodNode, "Action ${methodNode.name} in >>>> ${currentClassName} is empty") >>>> } *else*{ >>>> *def*tryCatchStatement = methodNode.firstStatement >>>> *if*(!(tryCatchStatement *instanceof*TryCatchStatement)) >>>> { >>>> addViolation(methodNode, "First statement of >>>> action ${methodNode.name} in ${currentClassName} is >>>> ${tryCatchStatement.class.name}") >>>> } *else*{ >>>> // try/catch statement, but nothing more? >>>> } >>>> } >>>> } >>>> } >>>> } >>>> >>>> I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. >>>> >>>> Thanks for any insight. >>>> >>>> -Andrew Goodspeed >>>> NOTICE: This message and all attachments transmitted with it may >>>> contain sensitive and/or confidential information intended solely for the >>>> use of the addressee. If the reader of this message is not the intended >>>> recipient, you are hereby notified that any reading, dissemination, >>>> distribution, copying, or other use of this message or its attachments is >>>> strictly prohibited. If you have received this message in error, please >>>> notify the sender immediately and delete this message and all copies and >>>> backups thereof. If you choose to communicate with us by email, you should >>>> be aware that the security of incoming Internet email is not secure. We >>>> strongly encourage you to use encrypted email when sending sensitive and/or >>>> confidential information. By sending sensitive or confidential email >>>> messages that are not encrypted, you accept the risks of such lack of >>>> security and possible lack of confidentiality. If you elect to communicate >>>> from your workplace computer, you also should be aware that your employer >>>> and its agents have access to email communications between you and us. >>>> >>>> ------------------------------------------------------------ >>>> ------------------ >>>> >>>> _______________________________________________ >>>> Codenarc-user mailing list >>>> Cod...@li... >>>> <javascript:_e(%7B%7D,'cvml','Cod...@li...');> >>>> https://lists.sourceforge.net/lists/listinfo/codenarc-user >>>> >>>> >>> >>> >>> -- >>> Hamlet D'Arcy >>> ham...@gm... >>> <javascript:_e(%7B%7D,'cvml','ham...@gm...');> >>> >>> ------------------------------------------------------------ >>> ------------------ >>> >>> _______________________________________________ >>> Codenarc-user mailing list >>> Cod...@li... >>> <javascript:_e(%7B%7D,'cvml','Cod...@li...');> >>> https://lists.sourceforge.net/lists/listinfo/codenarc-user >>> >>> >> > > > -- > Hamlet D'Arcy > ham...@gm... <javascript:_e(%7B%7D,'cvml','ham...@gm...');> > |
From: Hamlet D'A. <ham...@gm...> - 2016-09-01 19:37:09
|
I'm still alive! I work at Microsoft now but still in Switzerland. If anyone out there is using TypeScript then be sure to check out all my TypeScript linting rules. It's even an official Microsoft git repo :) https://github.com/Microsoft/tslint-microsoft-contrib I don't know.... there is just something about writing linting rules that makes me happy :) On Thu, Sep 1, 2016 at 3:32 PM, Roshan Dawrani <ros...@gm...> wrote: > Aha! What a pleasant surprise to see a mail from you again. Long time, > Hamlet! > > On Thu, Sep 1, 2016 at 6:52 PM, Hamlet D'Arcy <ham...@gm...> wrote: > >> Not sure if you ever got an answer to this... >> >> Here is the latest Javadoc for MethodNode: http://docs.groovy >> -lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html >> >> A MethodNode only ever has one Statement! so if your Method has only a >> TryCatchStatement then you know nothing follows it. >> If your method has-a BlockStatement then your method will be several >> statements long. >> >> The best way to explore is to write more unit tests and just look and see >> what is in the AST! >> >> On Thu, Aug 18, 2016 at 9:18 PM, <AGo...@cf...> wrote: >> >>> Hello all. >>> >>> I am trying to write a CodeNarc rule and am struggling with just how to >>> use the AST code visitor support (or anything else) to get were I want to >>> go. Does anyone know of a resource that might be helpful and/or give me >>> some firsthand assistance? I have looked at all of the obvious ones from >>> the CodeNarc site as well as the distributed rules, google searches, etc. >>> >>> I am trying to write a rule that checks to make sure the body of >>> particular methods consists entirely of a try/catch block where Exception >>> is caught. I have gotten as far as verifying the first statement in the >>> method is a try/catch statement using an AbstractMethodVisitor but am >>> struggling a bit in figuring out how to make sure there is no statement >>> following it in the method. >>> >>> This is where I am on my astVisitorClass. >>> >>> *class*MyTestAstVisitor *extends*AbstractMethodVisitor { >>> @Override >>> *void*visitMethod(MethodNode methodNode) { >>> *if*(Modifier.*isPublic*(methodNode.modifiers)) { >>> *if*(AstUtil.*isEmptyBlock*(methodNode.code)) { >>> addViolation(methodNode, "Action ${methodNode.name} in >>> ${currentClassName} is empty") >>> } *else*{ >>> *def*tryCatchStatement = methodNode.firstStatement >>> *if*(!(tryCatchStatement *instanceof*TryCatchStatement)) >>> { >>> addViolation(methodNode, "First statement of action >>> ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. >>> name}") >>> } *else*{ >>> // try/catch statement, but nothing more? >>> } >>> } >>> } >>> } >>> } >>> >>> I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. >>> >>> Thanks for any insight. >>> >>> -Andrew Goodspeed >>> NOTICE: This message and all attachments transmitted with it may contain >>> sensitive and/or confidential information intended solely for the use of >>> the addressee. If the reader of this message is not the intended recipient, >>> you are hereby notified that any reading, dissemination, distribution, >>> copying, or other use of this message or its attachments is strictly >>> prohibited. If you have received this message in error, please notify the >>> sender immediately and delete this message and all copies and backups >>> thereof. If you choose to communicate with us by email, you should be aware >>> that the security of incoming Internet email is not secure. We strongly >>> encourage you to use encrypted email when sending sensitive and/or >>> confidential information. By sending sensitive or confidential email >>> messages that are not encrypted, you accept the risks of such lack of >>> security and possible lack of confidentiality. If you elect to communicate >>> from your workplace computer, you also should be aware that your employer >>> and its agents have access to email communications between you and us. >>> >>> ------------------------------------------------------------ >>> ------------------ >>> >>> _______________________________________________ >>> Codenarc-user mailing list >>> Cod...@li... >>> https://lists.sourceforge.net/lists/listinfo/codenarc-user >>> >>> >> >> >> -- >> Hamlet D'Arcy >> ham...@gm... >> >> ------------------------------------------------------------ >> ------------------ >> >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> >> > -- Hamlet D'Arcy ham...@gm... |
From: Roshan D. <ros...@gm...> - 2016-09-01 13:33:26
|
Aha! What a pleasant surprise to see a mail from you again. Long time, Hamlet! On Thu, Sep 1, 2016 at 6:52 PM, Hamlet D'Arcy <ham...@gm...> wrote: > Not sure if you ever got an answer to this... > > Here is the latest Javadoc for MethodNode: http://docs. > groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html > > A MethodNode only ever has one Statement! so if your Method has only a > TryCatchStatement then you know nothing follows it. > If your method has-a BlockStatement then your method will be several > statements long. > > The best way to explore is to write more unit tests and just look and see > what is in the AST! > > On Thu, Aug 18, 2016 at 9:18 PM, <AGo...@cf...> wrote: > >> Hello all. >> >> I am trying to write a CodeNarc rule and am struggling with just how to >> use the AST code visitor support (or anything else) to get were I want to >> go. Does anyone know of a resource that might be helpful and/or give me >> some firsthand assistance? I have looked at all of the obvious ones from >> the CodeNarc site as well as the distributed rules, google searches, etc. >> >> I am trying to write a rule that checks to make sure the body of >> particular methods consists entirely of a try/catch block where Exception >> is caught. I have gotten as far as verifying the first statement in the >> method is a try/catch statement using an AbstractMethodVisitor but am >> struggling a bit in figuring out how to make sure there is no statement >> following it in the method. >> >> This is where I am on my astVisitorClass. >> >> *class*MyTestAstVisitor *extends*AbstractMethodVisitor { >> @Override >> *void*visitMethod(MethodNode methodNode) { >> *if*(Modifier.*isPublic*(methodNode.modifiers)) { >> *if*(AstUtil.*isEmptyBlock*(methodNode.code)) { >> addViolation(methodNode, "Action ${methodNode.name} in ${ >> currentClassName} is empty") >> } *else*{ >> *def*tryCatchStatement = methodNode.firstStatement >> *if*(!(tryCatchStatement *instanceof*TryCatchStatement)) >> { >> addViolation(methodNode, "First statement of action >> ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. >> name}") >> } *else*{ >> // try/catch statement, but nothing more? >> } >> } >> } >> } >> } >> >> I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. >> >> Thanks for any insight. >> >> -Andrew Goodspeed >> NOTICE: This message and all attachments transmitted with it may contain >> sensitive and/or confidential information intended solely for the use of >> the addressee. If the reader of this message is not the intended recipient, >> you are hereby notified that any reading, dissemination, distribution, >> copying, or other use of this message or its attachments is strictly >> prohibited. If you have received this message in error, please notify the >> sender immediately and delete this message and all copies and backups >> thereof. If you choose to communicate with us by email, you should be aware >> that the security of incoming Internet email is not secure. We strongly >> encourage you to use encrypted email when sending sensitive and/or >> confidential information. By sending sensitive or confidential email >> messages that are not encrypted, you accept the risks of such lack of >> security and possible lack of confidentiality. If you elect to communicate >> from your workplace computer, you also should be aware that your employer >> and its agents have access to email communications between you and us. >> >> ------------------------------------------------------------ >> ------------------ >> >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> >> > > > -- > Hamlet D'Arcy > ham...@gm... > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > |
From: Hamlet D'A. <ham...@gm...> - 2016-09-01 13:22:56
|
Not sure if you ever got an answer to this... Here is the latest Javadoc for MethodNode: http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/ast/MethodNode.html A MethodNode only ever has one Statement! so if your Method has only a TryCatchStatement then you know nothing follows it. If your method has-a BlockStatement then your method will be several statements long. The best way to explore is to write more unit tests and just look and see what is in the AST! On Thu, Aug 18, 2016 at 9:18 PM, <AGo...@cf...> wrote: > Hello all. > > I am trying to write a CodeNarc rule and am struggling with just how to > use the AST code visitor support (or anything else) to get were I want to > go. Does anyone know of a resource that might be helpful and/or give me > some firsthand assistance? I have looked at all of the obvious ones from > the CodeNarc site as well as the distributed rules, google searches, etc. > > I am trying to write a rule that checks to make sure the body of > particular methods consists entirely of a try/catch block where Exception > is caught. I have gotten as far as verifying the first statement in the > method is a try/catch statement using an AbstractMethodVisitor but am > struggling a bit in figuring out how to make sure there is no statement > following it in the method. > > This is where I am on my astVisitorClass. > > *class*MyTestAstVisitor *extends*AbstractMethodVisitor { > @Override > *void*visitMethod(MethodNode methodNode) { > *if*(Modifier.*isPublic*(methodNode.modifiers)) { > *if*(AstUtil.*isEmptyBlock*(methodNode.code)) { > addViolation(methodNode, "Action ${methodNode.name} in ${ > currentClassName} is empty") > } *else*{ > *def*tryCatchStatement = methodNode.firstStatement > *if*(!(tryCatchStatement *instanceof*TryCatchStatement)) { > addViolation(methodNode, "First statement of action > ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. > name}") > } *else*{ > // try/catch statement, but nothing more? > } > } > } > } > } > > I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. > > Thanks for any insight. > > -Andrew Goodspeed > NOTICE: This message and all attachments transmitted with it may contain > sensitive and/or confidential information intended solely for the use of > the addressee. If the reader of this message is not the intended recipient, > you are hereby notified that any reading, dissemination, distribution, > copying, or other use of this message or its attachments is strictly > prohibited. If you have received this message in error, please notify the > sender immediately and delete this message and all copies and backups > thereof. If you choose to communicate with us by email, you should be aware > that the security of incoming Internet email is not secure. We strongly > encourage you to use encrypted email when sending sensitive and/or > confidential information. By sending sensitive or confidential email > messages that are not encrypted, you accept the risks of such lack of > security and possible lack of confidentiality. If you elect to communicate > from your workplace computer, you also should be aware that your employer > and its agents have access to email communications between you and us. > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > -- Hamlet D'Arcy ham...@gm... |
From: <chr...@we...> - 2016-08-29 12:15:16
|
Sorry for the delayed response. I would suggest installing Groovy, if you have not already done so, and then use the Groovy Console. That has been invaluable for me when writing rules and AST-parsing code. Paste a code sample into the console and then press Ctrl-T to open the AST Browser. Then match the AST-parsing code you are writing to what the console shows for the structure of the resulting AST. Chris From: AGo...@cf... [mailto:AGo...@cf...] Sent: Thursday, August 18, 2016 3:18 PM To: cod...@li... Subject: [Codenarc-user] Writing CodeNarc rules Hello all. I am trying to write a CodeNarc rule and am struggling with just how to use the AST code visitor support (or anything else) to get were I want to go. Does anyone know of a resource that might be helpful and/or give me some firsthand assistance? I have looked at all of the obvious ones from the CodeNarc site as well as the distributed rules, google searches, etc. I am trying to write a rule that checks to make sure the body of particular methods consists entirely of a try/catch block where Exception is caught. I have gotten as far as verifying the first statement in the method is a try/catch statement using an AbstractMethodVisitor but am struggling a bit in figuring out how to make sure there is no statement following it in the method. This is where I am on my astVisitorClass. classMyTestAstVisitor extendsAbstractMethodVisitor { @Override voidvisitMethod(MethodNode methodNode) { if(Modifier.isPublic(methodNode.modifiers)) { if(AstUtil.isEmptyBlock(methodNode.code)) { addViolation(methodNode, "Action ${methodNode.name} in ${currentClassName} is empty") } else{ deftryCatchStatement = methodNode.firstStatement if(!(tryCatchStatement instanceofTryCatchStatement)) { addViolation(methodNode, "First statement of action ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class.name}") } else{ // try/catch statement, but nothing more? } } } } } I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. Thanks for any insight. -Andrew Goodspeed NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. |
From: <AGo...@cf...> - 2016-08-18 19:32:26
|
Hello all. I am trying to write a CodeNarc rule and am struggling with just how to use the AST code visitor support (or anything else) to get were I want to go. Does anyone know of a resource that might be helpful and/or give me some firsthand assistance? I have looked at all of the obvious ones from the CodeNarc site as well as the distributed rules, google searches, etc. I am trying to write a rule that checks to make sure the body of particular methods consists entirely of a try/catch block where Exception is caught. I have gotten as far as verifying the first statement in the method is a try/catch statement using an AbstractMethodVisitor but am struggling a bit in figuring out how to make sure there is no statement following it in the method. This is where I am on my astVisitorClass. class MyTestAstVisitor extends AbstractMethodVisitor { @Override void visitMethod(MethodNode methodNode) { if (Modifier.isPublic(methodNode.modifiers)) { if (AstUtil.isEmptyBlock(methodNode.code)) { addViolation(methodNode, "Action ${methodNode.name} in ${ currentClassName} is empty") } else { def tryCatchStatement = methodNode.firstStatement if (!(tryCatchStatement instanceof TryCatchStatement)) { addViolation(methodNode, "First statement of action ${methodNode.name} in ${currentClassName} is ${tryCatchStatement.class. name}") } else { // try/catch statement, but nothing more? } } } } } I am running with CodeNarc 0.22 and Grails 2.2.4/Groovy 2.0.8. Thanks for any insight. -Andrew Goodspeed NOTICE: This message and all attachments transmitted with it may contain sensitive and/or confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof. If you choose to communicate with us by email, you should be aware that the security of incoming Internet email is not secure. We strongly encourage you to use encrypted email when sending sensitive and/or confidential information. By sending sensitive or confidential email messages that are not encrypted, you accept the risks of such lack of security and possible lack of confidentiality. If you elect to communicate from your workplace computer, you also should be aware that your employer and its agents have access to email communications between you and us. |
From: Chris M. <cm...@gm...> - 2016-02-27 19:48:23
|
The *CodeNarc Team *is proud to announce the release of version *0.25.1*. CodeNarc <http://codenarc.sourceforge.net/> is a static analysis tool for Groovy source code. Version *0.25.1* adds 2 new rules (bringing the total to 348 rules), and several bug fixes and other enhancements. Special thanks to Yuriy Chulovskyy for several contributions. *New Rules:* - *NoTabCharacter* rule (convention) - Check that source files do not contain the tab character. - *TrailingComma* rule (convention) - Checks for trailing comma in List and Map literals. See the full details in the release notes <https://github.com/CodeNarc/CodeNarc/blob/master/CHANGELOG.txt>. Check us out on GitHub <https://github.com/CodeNarc/CodeNarc>! The Grails CodeNarc Plugin <http://grails.org/plugin/codenarc> has been updated to version *0.25.1* as well. |
From: Chris M. <cm...@gm...> - 2015-07-10 22:03:38
|
The *CodeNarc Team *is proud to announce the release of version *0.24*. CodeNarc <http://codenarc.sourceforge.net/> is a static analysis tool for Groovy source code. Version *0.24* adds a new *sortable *HTML report, and provides the *beta *release of a mechanism for excluding a set of baseline violations Version *0.24* also adds 3 new rules (bringing the total to 346 rules), and several bug fixes and other enhancements. *New Rules:* - *AssignmentToStaticFieldFromInstanceMethod *rule (design) - Checks for assignment to a static field from an instance method. - *ClassNameSameAsSuperclass *rule (naming) - Checks for any class that has an identical name to its superclass. - *InterfaceNameSameAsSuperInterface *rule (naming) - Checks for any interface that has an identical name to its super-interface. See the full details in the release notes <https://github.com/CodeNarc/CodeNarc/blob/master/CHANGELOG.txt>. Check us out on GitHub <https://github.com/CodeNarc/CodeNarc>! The Grails CodeNarc Plugin <http://grails.org/plugin/codenarc> has been updated to version *0.24* as well. |
From: Chris M. <cm...@gm...> - 2015-02-24 00:33:34
|
The *CodeNarc Team *is proud to announce the release of version *0.23*. CodeNarc <http://codenarc.sourceforge.net/> is a static analysis tool for Groovy source code. Version *0.23* adds 2 new rules (bringing the total to 343 rules) and several bug fixes and enhancements. *New Rules:* - *NestedForLoop *rule (design) - Checks for nested for loops. - *ParameterCount *rule (size) - Checks if the number of parameters in method/constructor exceeds the number of parameters specified by the *maxParameters* property. See the full details in the release notes <https://github.com/CodeNarc/CodeNarc/blob/master/CHANGELOG.txt>. Check us out on GitHub <https://github.com/CodeNarc/CodeNarc>! The Grails CodeNarc Plugin <http://grails.org/plugin/codenarc> has been updated to version *0.23* as well. (The plugin was published and can be used, but for some reason, the plugin page does not yet show the 0.23 version) |
From: <chr...@we...> - 2014-11-03 22:10:32
|
>> Is there a way to make the rule ignore strings and comments? Unfortunately, no. That rule applies to the source text of the entire file, so it is not smart enough to understand context, unless you can encode that context within the regex. From: Eric Wehrmeister [mailto:eri...@gm...] Sent: Monday, November 03, 2014 4:19 PM To: cod...@li... Subject: [Codenarc-user] Illegal Regex Ignore String and Comments Hi, I'm using the Illegal Regex rule to disallow a few specific things in my groovy code. Is there a way to make the rule ignore strings and comments? For exemple, I want any question marks to be preceded by a space, but I'd like to not cause a violation if this occurs in a string or a comment (especially since strings may contain URIs with parameters specified using question marks) Thanks, Eric Wehrmeister |
From: Eric W. <eri...@gm...> - 2014-11-03 21:19:18
|
Hi, I'm using the Illegal Regex rule to disallow a few specific things in my groovy code. Is there a way to make the rule ignore strings and comments? For exemple, I want any question marks to be preceded by a space, but I'd like to not cause a violation if this occurs in a string or a comment (especially since strings may contain URIs with parameters specified using question marks) Thanks, Eric Wehrmeister |
From: Chris M. <cm...@gm...> - 2014-10-16 01:33:05
|
The *CodeNarc Team *is proud to announce the release of version *0.22*. CodeNarc <http://codenarc.sourceforge.net/> is a static analysis tool for Groovy source code. Version *0.22* adds 4 new rules (bringing the total to 341 rules) , a new IDE (Eclipse/Idea) text report type, and several bug fixes and enhancements. *New Rules:* - *PackageMatchesFilePath *rule (naming) - The source file path for a class should match the package hierarchy. - *Instanceof *rule (design) - Checks for use of the *instanceof * operator. - *UnnecessarySafeNavigationOperator *rule (unnecessary) - Check for the *safe navigation operator *(?.) applied to constants and literals, which can never be null. - *NoDef *rule (convention) - Check for all uses of the *def* keyword. The new *IdeTextReportWriter* is a text report formatter that includes automatic IDE (Eclipse/Idea) hyperlinks to source code. See the full details in the release notes <https://github.com/CodeNarc/CodeNarc/blob/master/CHANGELOG.txt>. Check us out on GitHub <https://github.com/CodeNarc/CodeNarc>! The Grails CodeNarc Plugin <http://grails.org/plugin/codenarc> has been updated to version *0.22* as well. |
From: Eric W. <eri...@gm...> - 2014-09-22 21:12:46
|
Hi All, I'm new to CodeNarc (sorry if this is the wrong place to ask this question!) and I've been trying to integrate it into a maven project. I want to use a custom ruleset, so I built an dummy XML ruleset to test it out. However, when I run mvn clean install, it doesn't appear that my rules are actually being enforced. When I remove the <rulesetfiles> tag in the POM, it works correctly, enforcing the default rules. Does anybody see something I'm doing wrong for my custom ruleset to work? Thanks everyone! -Eric Wehrmeister (see XML below) Here's my custom ruleset and my plugin configuration: <ruleset xmlns="http://codenarc.org/ruleset/1.0" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://codenarc.org/ruleset/1.0 > http://codenarc.org/ruleset-schema.xsd" > xsi:noNamespaceSchemaLocation=" > http://codenarc.org/ruleset-schema.xsd"> > > <description>Dummy rule set</description> > > <rule class='org.codenarc.rule.formatting.SpaceAfterIf'> > <property name='priority' value='1'/> > </rule> > > <rule class='org.codenarc.rule.basic.EmptyIfStatement'> > <property name='priority' value='1'/> > </rule> > > </ruleset> > I referenced this ruleset in my POM like this: <plugin> > <groupId>org.codehaus.mojo</groupId> > <artifactId>codenarc-maven-plugin</artifactId> > <version>0.18-1</version> > <configuration> > <sourceDirectory>${basedir}/src/test/groovy</sourceDirectory> > <maxPriority1Violations>0</maxPriority1Violations> > <maxPriority2Violations>0</maxPriority2Violations> > <maxPriority3Violations>0</maxPriority3Violations> > <rulesetfiles>${basedir}/rulesets/ruleset.xml</rulesetfiles> > <xmlOutputDirectory>${basedir}/</xmlOutputDirectory> > </configuration> > <executions> > <execution> > <id>execution1</id> > <phase>install</phase> > <goals> > <goal>codenarc</goal> > </goals> > </execution> > </executions> > </plugin> > |
From: Piotr B. <pbe...@gm...> - 2014-07-31 06:59:42
|
Ok, now I understand. Thanks for your reply! Piotr On Thu, Jul 31, 2014 at 2:23 AM, Chris Mair <cm...@gm...> wrote: > I'm not sure how to configure the version of Groovy used for that plugin. > Is that: > http://docs.codehaus.org/display/SONAR/Groovy+Plugin > > Maybe you can ask in that plugin issue tracker or email the project owner. > > CodeNarc is built with Groovy 1.7, but that is the minimum version. That > being said, new versions of Groovy do occasionally introduce breaking > changes in CodeNarc, and that is probably the case with new Java versions > as well.. I have not tried using the diamond operator myself yet. > > Chris > > > On Tue, Jul 29, 2014 at 2:03 PM, Piotr Betkier <pbe...@gm...> wrote: > >> Hello, >> >> I'm trying to use codenarc bundled in a groovy sonar plugin to analyze my >> groovy 2.3 project. During analysis I get compilation errors because of >> unexpected tokens, e.g. for diamond syntax from JDK7 (i.e. new List<>()). >> >> This led me to checking that codenarc uses groovy version of 1.7 to >> compile the source code. I couldn't find any information on how to set a >> different groovy version for codenarc to use during analysis. How do I >> analyze a project that uses a newer version of groovy? Am I missing >> something? >> >> Thanks, >> Piotr >> >> >> ------------------------------------------------------------------------------ >> Infragistics Professional >> Build stunning WinForms apps today! >> Reboot your WinForms applications with our WinForms controls. >> Build a bridge from your legacy apps to the future. >> >> http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> >> > |
From: Chris M. <cm...@gm...> - 2014-07-31 00:23:33
|
I'm not sure how to configure the version of Groovy used for that plugin. Is that: http://docs.codehaus.org/display/SONAR/Groovy+Plugin Maybe you can ask in that plugin issue tracker or email the project owner. CodeNarc is built with Groovy 1.7, but that is the minimum version. That being said, new versions of Groovy do occasionally introduce breaking changes in CodeNarc, and that is probably the case with new Java versions as well.. I have not tried using the diamond operator myself yet. Chris On Tue, Jul 29, 2014 at 2:03 PM, Piotr Betkier <pbe...@gm...> wrote: > Hello, > > I'm trying to use codenarc bundled in a groovy sonar plugin to analyze my > groovy 2.3 project. During analysis I get compilation errors because of > unexpected tokens, e.g. for diamond syntax from JDK7 (i.e. new List<>()). > > This led me to checking that codenarc uses groovy version of 1.7 to > compile the source code. I couldn't find any information on how to set a > different groovy version for codenarc to use during analysis. How do I > analyze a project that uses a newer version of groovy? Am I missing > something? > > Thanks, > Piotr > > > ------------------------------------------------------------------------------ > Infragistics Professional > Build stunning WinForms apps today! > Reboot your WinForms applications with our WinForms controls. > Build a bridge from your legacy apps to the future. > > http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > |
From: Piotr B. <pbe...@gm...> - 2014-07-29 18:03:09
|
Hello, I'm trying to use codenarc bundled in a groovy sonar plugin to analyze my groovy 2.3 project. During analysis I get compilation errors because of unexpected tokens, e.g. for diamond syntax from JDK7 (i.e. new List<>()). This led me to checking that codenarc uses groovy version of 1.7 to compile the source code. I couldn't find any information on how to set a different groovy version for codenarc to use during analysis. How do I analyze a project that uses a newer version of groovy? Am I missing something? Thanks, Piotr |
From: Chris M. <cm...@gm...> - 2014-04-23 02:27:25
|
The *CodeNarc Team *is proud to announce the release of version *0.21*. CodeNarc <http://codenarc.sourceforge.net/> is a static analysis tool for Groovy source code. Version *0.21* adds 15 new rules (bringing the total to 337 rules) and a bunch of bug fixes and enhancements. Check us out on GitHub<https://github.com/CodeNarc/CodeNarc> ! *New Rules* - #30: *GrailsMassAssignment* rule (grails) - Checks for mass assignment from a params Map within Grails domain classes. (Thanks to Brian Soby) - #38: *NoWildcardImports *rule (imports) - Wildcard imports, static or otherwise, should not be used. (Thanks to Kyle Boon) - #41: *ConsecutiveBlankLines *rule (formatting) - Makes sure there are no consecutive lines that are either blank or whitespace only. (Thanks to Joe Sondow) - #42: *BlankLineBeforePackage *rule (formatting) - Makes sure there are no blank lines before the package declaration of a source code file. (Thanks to Joe Sondow) - #43: *FileEndsWithoutNewline *rule (formatting) - Makes sure the source code file ends with a newline character. (Thanks to Joe Sondow) - #44: *MissingBlankLineAfterImports *rule (formatting) - Makes sure there is a blank line after the imports of a source code file. (Thanks to Joe Sondow) - #46: *MissingBlankLineAfterPackage *rule (formatting) - Makes sure there is a blank line after the package statement of a source code file. (Thanks to Joe Sondow) - #47: *TrailingWhitespaceRule (*formatting) - Checks that no lines of source code end with whitespace characters. (Thanks to Joe Sondow) - #411:* ExceptionExtendsThrowable *rule (exceptions) - Checks for classes that extend Throwable. Custom exception classes should subclass Exception or one of its descendants. - #341:* UnnecessaryCast *rule (unnecessary) - Checks for unnecessary cast operations. - #149:* IllegalSubclass *rule (generic) - Checks for classes that extend one of the specified set of illegal superclasses. - #157:* UnnecessaryToString *rule (unnecessary) - Checks for unnecessary calls to toString(). - #152:* JUnitPublicProperty *rule (junit) - Checks for public properties defined on JUnit test classes. - #422:* ToStringReturnsNull *rule (design) - Checks for toString() methods that return null. - #143:* MultipleUnaryOperators *rule (basic) - Checks for multiple consecutive unary operators. *Updated and Enhanced Rules* #31: *UnusedImport*: Extended to now also detect cases where the imported class name occurs as a substring in the source code. (Thanks to Rene Scheibe) #36: *UnnecessaryDefInMethodDeclaration*: Prevent false positives from modifiers within quoted method name. (Thanks to Rene Scheibe) #37: *LineLength*: Flags to ignore import and package statements line length. (Thanks to Kyle Boon) #35: *UnnecessaryPackageReference*: raises confusing violation for Script with package. #48: Fix Method chaining breaks *SpaceAfterComma*. #49: Fix *SpaceBeforeOpeningBrace* doesn't work on switch statements. #50: Fix *UnnecessaryDotClass *doesn't work if class is qualified #153: Fix *ClosureStatementOnOpeningLineOfMultipleLineClosure* does not catch multiline closure with only a single statement. Visit the CodeNarc Home Page <http://codenarc.sourceforge.net/> |
From: Marcin E. <mar...@pr...> - 2014-04-10 11:14:00
|
Cool, thanks! On Thu, Apr 10, 2014 at 12:11 PM, Chris Mair <cm...@gm...> wrote: > Yes, my hope is to do a release this month. But it will be at least a > couple weeks. > > Chris > > > On Thu, Apr 10, 2014 at 5:43 AM, Marcin Erdmann <mar...@pr... > > wrote: > >> Thanks to Joe Sondow's contributions there have been quite a few new >> rules added since 0.20 which I would like to use on my projects. Any chance >> for a 0.21 release soon? >> >> Cheers, >> Marcin >> >> >> ------------------------------------------------------------------------------ >> Put Bad Developers to Shame >> Dominate Development with Jenkins Continuous Integration >> Continuously Automate Build, Test & Deployment >> Start a new project now. Try Jenkins in the cloud. >> http://p.sf.net/sfu/13600_Cloudbees >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> >> > |
From: Chris M. <cm...@gm...> - 2014-04-10 11:11:46
|
Yes, my hope is to do a release this month. But it will be at least a couple weeks. Chris On Thu, Apr 10, 2014 at 5:43 AM, Marcin Erdmann <mar...@pr...>wrote: > Thanks to Joe Sondow's contributions there have been quite a few new rules > added since 0.20 which I would like to use on my projects. Any chance for a > 0.21 release soon? > > Cheers, > Marcin > > > ------------------------------------------------------------------------------ > Put Bad Developers to Shame > Dominate Development with Jenkins Continuous Integration > Continuously Automate Build, Test & Deployment > Start a new project now. Try Jenkins in the cloud. > http://p.sf.net/sfu/13600_Cloudbees > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > |
From: Marcin E. <mar...@pr...> - 2014-04-10 10:13:40
|
Thanks to Joe Sondow's contributions there have been quite a few new rules added since 0.20 which I would like to use on my projects. Any chance for a 0.21 release soon? Cheers, Marcin |