pmd-devel Mailing List for PMD (Page 11)
A source code analyzer
Brought to you by:
adangel,
juansotuyo
You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
(768) |
Aug
(543) |
Sep
(364) |
Oct
(326) |
Nov
(182) |
Dec
(148) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(144) |
Feb
(223) |
Mar
(339) |
Apr
(406) |
May
(128) |
Jun
(225) |
Jul
(171) |
Aug
(171) |
Sep
(153) |
Oct
(150) |
Nov
(176) |
Dec
(88) |
| 2004 |
Jan
(71) |
Feb
(28) |
Mar
(91) |
Apr
(184) |
May
(127) |
Jun
(144) |
Jul
(186) |
Aug
(78) |
Sep
(193) |
Oct
(153) |
Nov
(92) |
Dec
(177) |
| 2005 |
Jan
(223) |
Feb
(319) |
Mar
(253) |
Apr
(106) |
May
(215) |
Jun
(299) |
Jul
(341) |
Aug
(286) |
Sep
(270) |
Oct
(212) |
Nov
(283) |
Dec
(345) |
| 2006 |
Jan
(243) |
Feb
(426) |
Mar
(278) |
Apr
(254) |
May
(259) |
Jun
(197) |
Jul
(156) |
Aug
(84) |
Sep
(150) |
Oct
(719) |
Nov
(319) |
Dec
(169) |
| 2007 |
Jan
(484) |
Feb
(222) |
Mar
(61) |
Apr
(51) |
May
(63) |
Jun
(182) |
Jul
(177) |
Aug
(89) |
Sep
(46) |
Oct
(178) |
Nov
(116) |
Dec
(89) |
| 2008 |
Jan
(23) |
Feb
(198) |
Mar
(227) |
Apr
(203) |
May
(174) |
Jun
(215) |
Jul
(55) |
Aug
(152) |
Sep
(129) |
Oct
(177) |
Nov
(79) |
Dec
(84) |
| 2009 |
Jan
(91) |
Feb
(179) |
Mar
(102) |
Apr
(67) |
May
(40) |
Jun
(41) |
Jul
(43) |
Aug
(53) |
Sep
(4) |
Oct
(17) |
Nov
(48) |
Dec
(76) |
| 2010 |
Jan
(28) |
Feb
(17) |
Mar
(27) |
Apr
(9) |
May
(19) |
Jun
(50) |
Jul
(21) |
Aug
(9) |
Sep
(42) |
Oct
(30) |
Nov
(33) |
Dec
(10) |
| 2011 |
Jan
(14) |
Feb
(6) |
Mar
(18) |
Apr
(8) |
May
(4) |
Jun
(18) |
Jul
(21) |
Aug
(19) |
Sep
(298) |
Oct
(82) |
Nov
(102) |
Dec
(241) |
| 2012 |
Jan
(41) |
Feb
(29) |
Mar
(43) |
Apr
(18) |
May
(42) |
Jun
(53) |
Jul
(53) |
Aug
(43) |
Sep
(16) |
Oct
(20) |
Nov
(36) |
Dec
(26) |
| 2013 |
Jan
(15) |
Feb
(14) |
Mar
(36) |
Apr
(38) |
May
(20) |
Jun
(5) |
Jul
(6) |
Aug
(18) |
Sep
(3) |
Oct
(24) |
Nov
(14) |
Dec
(1) |
| 2014 |
Jan
(13) |
Feb
(12) |
Mar
(8) |
Apr
(19) |
May
(4) |
Jun
(4) |
Jul
(27) |
Aug
(18) |
Sep
(11) |
Oct
(15) |
Nov
(32) |
Dec
(13) |
| 2015 |
Jan
(11) |
Feb
(13) |
Mar
(21) |
Apr
(22) |
May
(32) |
Jun
(14) |
Jul
(11) |
Aug
(7) |
Sep
(33) |
Oct
(40) |
Nov
(20) |
Dec
(13) |
| 2016 |
Jan
(24) |
Feb
(16) |
Mar
(11) |
Apr
(25) |
May
(46) |
Jun
(13) |
Jul
(3) |
Aug
(3) |
Sep
(8) |
Oct
(3) |
Nov
(17) |
Dec
(9) |
| 2017 |
Jan
(6) |
Feb
(3) |
Mar
(13) |
Apr
(16) |
May
(7) |
Jun
(5) |
Jul
(30) |
Aug
(3) |
Sep
(3) |
Oct
(10) |
Nov
(2) |
Dec
(3) |
| 2018 |
Jan
(8) |
Feb
(4) |
Mar
(6) |
Apr
(2) |
May
(3) |
Jun
(3) |
Jul
(6) |
Aug
(4) |
Sep
(4) |
Oct
(4) |
Nov
(4) |
Dec
(5) |
| 2019 |
Jan
(3) |
Feb
(2) |
Mar
(3) |
Apr
(2) |
May
(3) |
Jun
(2) |
Jul
(5) |
Aug
(2) |
Sep
(5) |
Oct
(3) |
Nov
(7) |
Dec
(1) |
| 2020 |
Jan
(3) |
Feb
(2) |
Mar
(2) |
Apr
(2) |
May
(3) |
Jun
(2) |
Jul
(2) |
Aug
(2) |
Sep
(2) |
Oct
(3) |
Nov
(3) |
Dec
(2) |
| 2021 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
(4) |
May
(4) |
Jun
(3) |
Jul
(4) |
Aug
(2) |
Sep
(3) |
Oct
(5) |
Nov
(1) |
Dec
(1) |
| 2022 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(2) |
May
(2) |
Jun
(3) |
Jul
(2) |
Aug
(2) |
Sep
(3) |
Oct
(1) |
Nov
(2) |
Dec
(2) |
| 2023 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
(1) |
May
(2) |
Jun
(1) |
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
(1) |
Nov
(1) |
Dec
(1) |
| 2024 |
Jan
(1) |
Feb
(1) |
Mar
(1) |
Apr
(3) |
May
(1) |
Jun
(2) |
Jul
(2) |
Aug
(2) |
Sep
(1) |
Oct
(1) |
Nov
(8) |
Dec
(2) |
| 2025 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
(1) |
Aug
(1) |
Sep
(2) |
Oct
(1) |
Nov
|
Dec
|
|
From: Rory O'D. <ror...@or...> - 2017-09-21 20:36:06
|
Hi Andreas,
Three items to share with you today
* *JDK 9 General Availability
*
o GPL'd binaries from Oracle are available here:
+ http://jdk.java.net/9
o See Mark Reinhold's email for more details on the Release [1]
+ delivery of Project Jigsaw [2]
* Are you JDK 9 Ready ?
o The Quality Outreach wiki has been updated to include a JDK 9
Ready column.
o If you would like us to identify your project as JDK 9 ready ,
please let me know and I will add it to the wiki.
* Quality Outreach Report for September 2017**is available
o many thanks for your continued support and welcome to the new
projects!
Rgds,Rory
[1]
http://mail.openjdk.java.net/pipermail/announce/2017-September/000230.html
[2] https://mreinhold.org/blog/jigsaw-complete
--
Rgds,Rory O'Donnell
Quality Engineering Manager
Oracle EMEA , Dublin, Ireland
|
|
From: Rory O'D. <ror...@or...> - 2017-09-07 09:23:50
|
Hi Andreas, Oracle is proposing a rapid release model for Java SE going-forward. The high points are highlighted below, details of the changes can be found on Mark Reinhold’s blog [1] , OpenJDK discussion email list [2]. Under the proposed release model, after JDK 9, we will adopt a strict, time-based model with a new major release every six months, update releases every quarter, and a long-term support release every three years. The new JDK Project will run a bit differently than the past "JDK $N" Projects: - The main development line will always be open but fixes, enhancements, and features will be merged only when they're nearly finished. The main line will be Feature Complete [3] at all times. - We'll continue to use the JEP Process [4] for new features and other significant changes. The bar to target a JEP to a specific release will, however, be higher since the work must be Feature Complete in order to go in. Owners of large or risky features will be strongly encouraged to split such features up into smaller and safer parts, to integrate earlier in the release cycle, and to publish separate lines of early-access builds prior to integration. The JDK Updates Project will run in much the same way as the past "JDK $N" Updates Projects, though update releases will be strictly limited to fixes of security issues, regressions, and bugs in newer features. Related to this proposal, we intend to make a few changes in what we do: - Starting with JDK 9 we'll ship OpenJDK builds under the GPL [5], to make it easier for developers to deploy Java applications to cloud environments. We'll initially publish OpenJDK builds for Linux/x64, followed later by builds for macOS/x64 and Windows/x64. - We'll continue to ship proprietary "Oracle JDK" builds, which include "commercial features" [6] such as Java Flight Recorder and Mission Control [7], under a click-through binary-code license [8]. Oracle will continue to offer paid support for these builds. - After JDK 9 we'll open-source the commercial features in order to make the OpenJDK builds more attractive to developers and to reduce the differences between those builds and the Oracle JDK. This will take some time, but the ultimate goal is to make OpenJDK and Oracle JDK builds completely interchangeable. - Finally, for the long term we'll work with other OpenJDK contributors to establish an open build-and-test infrastructure. This will make it easier to publish early-access builds for features in development, and eventually make it possible for the OpenJDK Community itself to publish authoritative builds of the JDK. Questions , comments, feedback to OpenJDK discuss mailing list [2] Rgds,Rory [1]https://mreinhold.org/blog/forward-faster [2]http://mail.openjdk.java.net/pipermail/discuss/2017-September/004281.html [3]http://openjdk.java.net/projects/jdk8/milestones#Feature_Complete [4]http://openjdk.java.net/jeps/0 [5]http://openjdk.java.net/legal/gplv2+ce.html [6]http://www.oracle.com/technetwork/java/javase/terms/products/index.html [7]http://www.oracle.com/technetwork/java/javaseproducts/mission-control/index.html [8]http://www.oracle.com/technetwork/java/javase/terms/license/index.html |
|
From: Juan M. S. D. <jua...@gm...> - 2017-09-04 13:11:06
|
This looks as if you are incorrectly referencing the rule (notice the capital *‘D’* in *‘Design’* on your error message). You are also missing the language for the ruleset. As per the documentation <https://pmd.github.io/pmd-5.8.1/customizing/howtomakearuleset.html> the correct way to reference such a rule would be: <rule ref="rulesets/java/design.xml/CloseResource"/> In the future, please provide complete information when asking for help. The error message on it’s own may not be enough to help you. On this case, a copy of your ruleset (or a minimal failing ruleset) would have been expected. Regards On Tue, Aug 29, 2017 at 5:39 AM, Neha Phatak <neh...@tc...> wrote: > Dear Team, > > I am trying to customize my own pmd ruleset but getting error as. I am > trying to define java-design ruleset for CloseResource. Please help me why > this error occuring > > > > -- > Thanks & Regards > Neha Phatak > Tata Consultancy Services Limited > Ph:- 022-67781998 > Mailto: neh...@tc... > Website: http://www.tcs.com > ____________________________________________ > Experience certainty. IT Services > Business Solutions > Consulting > ____________________________________________ > > =====-----=====-----===== > Notice: The information contained in this e-mail > message and/or attachments to it may contain > confidential or privileged information. If you are > not the intended recipient, any dissemination, use, > review, distribution, printing or copying of the > information contained in this e-mail message > and/or attachments to it are strictly prohibited. If > you have received this communication in error, > please notify us by reply e-mail or telephone and > immediately and permanently delete the message > and any attachments. Thank you > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Pmd-devel mailing list > Pmd...@li... > https://lists.sourceforge.net/lists/listinfo/pmd-devel > > |
|
From: Neha P. <neh...@tc...> - 2017-08-29 08:51:37
|
Dear Team, I am trying to customize my own pmd ruleset but getting error as. I am trying to define java-design ruleset for CloseResource. Please help me why this error occuring -- Thanks & Regards Neha Phatak Tata Consultancy Services Limited Ph:- 022-67781998 Mailto: neh...@tc... Website: http://www.tcs.com ____________________________________________ Experience certainty. IT Services Business Solutions Consulting ____________________________________________ =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you |
|
From: Andreas D. <and...@ad...> - 2017-08-23 19:05:57
|
FYI - PMD is one of the Projects of the Week next week... -------- Weitergeleitete Nachricht -------- Betreff: SourceForge Project of the Week August 28th, 2017 Datum: Wed, 23 Aug 2017 14:13:01 +0800 Von: Joan Uy Ang <joa...@sl...> Hi, If you’re receiving this email it is because you are listed as an admin on our next Projects of the Week Issue for August 28th, 2017 on the SourceForge Blog. Here are the projects selected: *ferenoslinux* *pnp4nagios* *pmd* *gns-3* *gretl* *faac* *antix-linux* *asuswrt-merlin* *shotcut* You will see them reflected live on the SourceForge homepage and blog next week. Thanks, Joan Nadene SourceForge Community Coordinator |
|
From: Rory O'D. <ror...@or...> - 2017-08-08 09:51:37
|
Hi Andreas, Thank you very much for all your testing of JDK 9 during its development! Such contributions have significantly helped shape and improve JDK 9. Now that we have reached the JDK 9 Final Release Candidate phase [1] , I would like to ask if your project can be considered to be 'ready for JDK 9', or if there are any remaining show stopper issues which you've encountered when testing with the JDK 9 release candidate. JDK 9 b181 is available at http://jdk.java.net/9/ If you have a public web page, mailing list post, or even a tweet announcing you project's readiness for JDK 9, I'd love to add the URL to the upcoming JDK 9 readiness page on the Quality Outreach wiki. Looking forward to hearing from you, Rory [1] http://openjdk.java.net/projects/jdk9/ -- Rgds,Rory O'Donnell Quality Engineering Manager Oracle EMEA , Dublin, Ireland |
|
From: Caleb K. <cal...@en...> - 2017-07-17 18:27:05
|
Okay, guess I have some rewriting to do... Anyway, back to the other rule. I think I'll add some logic to test whether or not those nodes are indeed what I am looking for, instead of casting. Does that make sense? On Mon, Jul 17, 2017 at 1:20 PM, Juan Martín Sotuyo Dodero < jua...@gm...> wrote: > Don't duplicate code. > > Just run PMD using a custom ruleset, and on that you can reference the > NcssMethodCountRule with a custom value for properties. > > You can check the docs: https://pmd.github.io/pmd-5.8.1/customizing/ > howtomakearuleset.html > > On Mon, Jul 17, 2017 at 3:19 PM, Caleb Knox <cal...@en...> > wrote: > >> Sorry, I was unclear about the NcssMethodCountRule. I copy/pasted the >> code into my custom rule. >> >> Again, what do I change? >> >> On Mon, Jul 17, 2017 at 1:16 PM, Caleb Knox <cal...@en...> >> wrote: >> >>> As for your casts... why are you assuming ALL BooleanExpressions are >>>> formed with a method call and a literal? I can think of plenty of boolean >>>> expressions that are not built that way (ie: myVar == 1) >>> >>> >>> I am not, as far as I know. I am just looking for such expressions that >>> contain a method call and a literal. Specifically, and .size() comparison >>> to 0. >>> >>> Finally, do not edit the property value on the source. It's a property >>>> so people can customize the value on their rulesets. Just configure it as >>>> you wish on your custom ruleset. >>>> >>> >>> I am not, but in my custom rule, what property do I change? That is what >>> I had asked. >>> >>> On Mon, Jul 17, 2017 at 1:12 PM, Juan Martín Sotuyo Dodero < >>> jua...@gm...> wrote: >>> >>>> As for NPEs, you can either debug when analyzing your real-code, or >>>> make new code samples based on the contents of the file on which the NPE is >>>> found. You are most probably just missing cases on your test scenarios. >>>> >>>> As for your casts... why are you assuming ALL BooleanExpressions are >>>> formed with a method call and a literal? I can think of plenty of boolean >>>> expressions that are not built that way (ie: myVar == 1) >>>> >>>> Finally, do not edit the property value on the source. It's a property >>>> so people can customize the value on their rulesets. Just configure it as >>>> you wish on your custom ruleset. >>>> >>>> Regards >>>> >>>> On Mon, Jul 17, 2017 at 3:07 PM, Caleb Knox <cal...@en...> >>>> wrote: >>>> >>>>> Okay, sorry about that. The hard-coded ID rule is working from command >>>>> line as well. I am unsure as to what is broken. >>>>> >>>>> On Mon, Jul 17, 2017 at 1:01 PM, Caleb Knox <cal...@en...> >>>>> wrote: >>>>> >>>>>> Did some more testing... If I run from the command line, the ApexUseSizeOverIsEmptyRule >>>>>> works just fine. Hard-coded ID rule is probably broken. >>>>>> >>>>>> On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox < >>>>>> cal...@en...> wrote: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> For this rule, I sometimes get an NPE, depending on what Apex class >>>>>>> I'm analyzing. >>>>>>> >>>>>>> package net.sourceforge.pmd.lang.apex.custom; >>>>>>> >>>>>>> import java.util.regex.Matcher; >>>>>>> import java.util.regex.Pattern; >>>>>>> >>>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression; >>>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; >>>>>>> >>>>>>> // this rule checks for hard coded ids >>>>>>> >>>>>>> public class ApexHardCodedIdRule extends AbstractApexRule { >>>>>>> >>>>>>> public Object visit(ASTLiteralExpression node, Object data){ >>>>>>> >>>>>>> // look for string starting w/ 3 digits >>>>>>> Pattern pattern = Pattern.compile("^[0-9]{3}"); >>>>>>> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString()); >>>>>>> // NPE HAPPENS HERE >>>>>>> >>>>>>> // look for 15 or 18 digit string or >>>>>>> // look for 3 digit string at start >>>>>>> // of any string >>>>>>> if(node.getNode().getLiteral().toString().length() == 15 || >>>>>>> node.getNode().getLiteral().toString().length() == >>>>>>> 18 || >>>>>>> matcher.find()) { >>>>>>> >>>>>>> addViolation(data, node); >>>>>>> } >>>>>>> >>>>>>> return data; >>>>>>> >>>>>>> } >>>>>>> } >>>>>>> >>>>>>> And for this rule, I get an error while trying to cast types of >>>>>>> nodes. >>>>>>> >>>>>>> package net.sourceforge.pmd.lang.apex.custom; >>>>>>> >>>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression; >>>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression; >>>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression; >>>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; >>>>>>> >>>>>>> // this rule checks for the use of size() over isEmpty() >>>>>>> >>>>>>> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule { >>>>>>> >>>>>>> public Object visit(ASTBooleanExpression node, Object data){ >>>>>>> >>>>>>> ASTMethodCallExpression method = (ASTMethodCallExpression) >>>>>>> node.jjtGetChild(0); >>>>>>> ASTLiteralExpression exp = (ASTLiteralExpression) >>>>>>> node.jjtGetChild(1); >>>>>>> >>>>>>> // if comparison to 0 used in conjunction with size() method >>>>>>> // add violation >>>>>>> if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison") >>>>>>> >>>>>>> && method.getMethodName().toString().equalsIgnoreCase("size") >>>>>>> >>>>>>> && exp.getNode().getLiteral().toString().equalsIgnoreCase("0")) >>>>>>> { >>>>>>> addViolation(data, node); >>>>>>> } >>>>>>> >>>>>>> return data; >>>>>>> >>>>>>> } >>>>>>> >>>>>>> } >>>>>>> >>>>>>> >>>>>>> However, both of these classes run just fine when I use them in my >>>>>>> custom test class, with their respective custom test data. They both find >>>>>>> the correct errors in that case. >>>>>>> >>>>>>> I don't know why they work in a test environment, but get fatal >>>>>>> errors when I run them on other Apex classes. >>>>>>> >>>>>>> Also, when modifying the NcssMethodCountRule to 50 lines of code, do >>>>>>> I change the >>>>>>> >>>>>>> setProperty(MINIMUM_DESCRIPTOR, 40d); >>>>>>> >>>>>>> to 50d? >>>>>>> >>>>>>> Any help is welcome. >>>>>>> >>>>>>> -- >>>>>>> Caleb Knox >>>>>>> >>>>>>> Endeveran >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Caleb Knox >>>>>> >>>>>> Endeveran >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Caleb Knox >>>>> >>>>> Endeveran >>>>> >>>>> ------------------------------------------------------------ >>>>> ------------------ >>>>> Check out the vibrant tech community on one of the world's most >>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>> _______________________________________________ >>>>> Pmd-devel mailing list >>>>> Pmd...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/pmd-devel >>>>> >>>>> >>>> >>> >>> >>> -- >>> Caleb Knox >>> >>> Endeveran >>> >> >> >> >> -- >> Caleb Knox >> >> Endeveran >> > > -- Caleb Knox Endeveran |
|
From: Juan M. S. D. <jua...@gm...> - 2017-07-17 18:20:46
|
Don't duplicate code. Just run PMD using a custom ruleset, and on that you can reference the NcssMethodCountRule with a custom value for properties. You can check the docs: https://pmd.github.io/pmd-5.8.1/customizing/howtomakearuleset.html On Mon, Jul 17, 2017 at 3:19 PM, Caleb Knox <cal...@en...> wrote: > Sorry, I was unclear about the NcssMethodCountRule. I copy/pasted the code > into my custom rule. > > Again, what do I change? > > On Mon, Jul 17, 2017 at 1:16 PM, Caleb Knox <cal...@en...> > wrote: > >> As for your casts... why are you assuming ALL BooleanExpressions are >>> formed with a method call and a literal? I can think of plenty of boolean >>> expressions that are not built that way (ie: myVar == 1) >> >> >> I am not, as far as I know. I am just looking for such expressions that >> contain a method call and a literal. Specifically, and .size() comparison >> to 0. >> >> Finally, do not edit the property value on the source. It's a property so >>> people can customize the value on their rulesets. Just configure it as you >>> wish on your custom ruleset. >>> >> >> I am not, but in my custom rule, what property do I change? That is what >> I had asked. >> >> On Mon, Jul 17, 2017 at 1:12 PM, Juan Martín Sotuyo Dodero < >> jua...@gm...> wrote: >> >>> As for NPEs, you can either debug when analyzing your real-code, or make >>> new code samples based on the contents of the file on which the NPE is >>> found. You are most probably just missing cases on your test scenarios. >>> >>> As for your casts... why are you assuming ALL BooleanExpressions are >>> formed with a method call and a literal? I can think of plenty of boolean >>> expressions that are not built that way (ie: myVar == 1) >>> >>> Finally, do not edit the property value on the source. It's a property >>> so people can customize the value on their rulesets. Just configure it as >>> you wish on your custom ruleset. >>> >>> Regards >>> >>> On Mon, Jul 17, 2017 at 3:07 PM, Caleb Knox <cal...@en...> >>> wrote: >>> >>>> Okay, sorry about that. The hard-coded ID rule is working from command >>>> line as well. I am unsure as to what is broken. >>>> >>>> On Mon, Jul 17, 2017 at 1:01 PM, Caleb Knox <cal...@en...> >>>> wrote: >>>> >>>>> Did some more testing... If I run from the command line, the ApexUseSizeOverIsEmptyRule >>>>> works just fine. Hard-coded ID rule is probably broken. >>>>> >>>>> On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox <cal...@en... >>>>> > wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>> For this rule, I sometimes get an NPE, depending on what Apex class >>>>>> I'm analyzing. >>>>>> >>>>>> package net.sourceforge.pmd.lang.apex.custom; >>>>>> >>>>>> import java.util.regex.Matcher; >>>>>> import java.util.regex.Pattern; >>>>>> >>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression; >>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; >>>>>> >>>>>> // this rule checks for hard coded ids >>>>>> >>>>>> public class ApexHardCodedIdRule extends AbstractApexRule { >>>>>> >>>>>> public Object visit(ASTLiteralExpression node, Object data){ >>>>>> >>>>>> // look for string starting w/ 3 digits >>>>>> Pattern pattern = Pattern.compile("^[0-9]{3}"); >>>>>> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString()); >>>>>> // NPE HAPPENS HERE >>>>>> >>>>>> // look for 15 or 18 digit string or >>>>>> // look for 3 digit string at start >>>>>> // of any string >>>>>> if(node.getNode().getLiteral().toString().length() == 15 || >>>>>> node.getNode().getLiteral().toString().length() == >>>>>> 18 || >>>>>> matcher.find()) { >>>>>> >>>>>> addViolation(data, node); >>>>>> } >>>>>> >>>>>> return data; >>>>>> >>>>>> } >>>>>> } >>>>>> >>>>>> And for this rule, I get an error while trying to cast types of nodes. >>>>>> >>>>>> package net.sourceforge.pmd.lang.apex.custom; >>>>>> >>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression; >>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression; >>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression; >>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; >>>>>> >>>>>> // this rule checks for the use of size() over isEmpty() >>>>>> >>>>>> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule { >>>>>> >>>>>> public Object visit(ASTBooleanExpression node, Object data){ >>>>>> >>>>>> ASTMethodCallExpression method = (ASTMethodCallExpression) >>>>>> node.jjtGetChild(0); >>>>>> ASTLiteralExpression exp = (ASTLiteralExpression) >>>>>> node.jjtGetChild(1); >>>>>> >>>>>> // if comparison to 0 used in conjunction with size() method >>>>>> // add violation >>>>>> if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison") >>>>>> >>>>>> && method.getMethodName().toString().equalsIgnoreCase("size") >>>>>> >>>>>> && exp.getNode().getLiteral().toString().equalsIgnoreCase("0")) >>>>>> { >>>>>> addViolation(data, node); >>>>>> } >>>>>> >>>>>> return data; >>>>>> >>>>>> } >>>>>> >>>>>> } >>>>>> >>>>>> >>>>>> However, both of these classes run just fine when I use them in my >>>>>> custom test class, with their respective custom test data. They both find >>>>>> the correct errors in that case. >>>>>> >>>>>> I don't know why they work in a test environment, but get fatal >>>>>> errors when I run them on other Apex classes. >>>>>> >>>>>> Also, when modifying the NcssMethodCountRule to 50 lines of code, do >>>>>> I change the >>>>>> >>>>>> setProperty(MINIMUM_DESCRIPTOR, 40d); >>>>>> >>>>>> to 50d? >>>>>> >>>>>> Any help is welcome. >>>>>> >>>>>> -- >>>>>> Caleb Knox >>>>>> >>>>>> Endeveran >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Caleb Knox >>>>> >>>>> Endeveran >>>>> >>>> >>>> >>>> >>>> -- >>>> Caleb Knox >>>> >>>> Endeveran >>>> >>>> ------------------------------------------------------------ >>>> ------------------ >>>> Check out the vibrant tech community on one of the world's most >>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>> _______________________________________________ >>>> Pmd-devel mailing list >>>> Pmd...@li... >>>> https://lists.sourceforge.net/lists/listinfo/pmd-devel >>>> >>>> >>> >> >> >> -- >> Caleb Knox >> >> Endeveran >> > > > > -- > Caleb Knox > > Endeveran > |
|
From: Juan M. S. D. <jua...@gm...> - 2017-07-17 18:19:31
|
Yes you are..
public Object visit(ASTBooleanExpression node, Object data){
ASTMethodCallExpression method = (ASTMethodCallExpression)
node.jjtGetChild(0);
ASTLiteralExpression exp = (ASTLiteralExpression)
node.jjtGetChild(1);
The visit() method is called for all nodes of the BooleanExpression... and
you are assuming the types of it's children right away....
On Mon, Jul 17, 2017 at 3:16 PM, Caleb Knox <cal...@en...>
wrote:
> As for your casts... why are you assuming ALL BooleanExpressions are
>> formed with a method call and a literal? I can think of plenty of boolean
>> expressions that are not built that way (ie: myVar == 1)
>
>
> I am not, as far as I know. I am just looking for such expressions that
> contain a method call and a literal. Specifically, and .size() comparison
> to 0.
>
> Finally, do not edit the property value on the source. It's a property so
>> people can customize the value on their rulesets. Just configure it as you
>> wish on your custom ruleset.
>>
>
> I am not, but in my custom rule, what property do I change? That is what I
> had asked.
>
> On Mon, Jul 17, 2017 at 1:12 PM, Juan Martín Sotuyo Dodero <
> jua...@gm...> wrote:
>
>> As for NPEs, you can either debug when analyzing your real-code, or make
>> new code samples based on the contents of the file on which the NPE is
>> found. You are most probably just missing cases on your test scenarios.
>>
>> As for your casts... why are you assuming ALL BooleanExpressions are
>> formed with a method call and a literal? I can think of plenty of boolean
>> expressions that are not built that way (ie: myVar == 1)
>>
>> Finally, do not edit the property value on the source. It's a property so
>> people can customize the value on their rulesets. Just configure it as you
>> wish on your custom ruleset.
>>
>> Regards
>>
>> On Mon, Jul 17, 2017 at 3:07 PM, Caleb Knox <cal...@en...>
>> wrote:
>>
>>> Okay, sorry about that. The hard-coded ID rule is working from command
>>> line as well. I am unsure as to what is broken.
>>>
>>> On Mon, Jul 17, 2017 at 1:01 PM, Caleb Knox <cal...@en...>
>>> wrote:
>>>
>>>> Did some more testing... If I run from the command line, the ApexUseSizeOverIsEmptyRule
>>>> works just fine. Hard-coded ID rule is probably broken.
>>>>
>>>> On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox <cal...@en...>
>>>> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> For this rule, I sometimes get an NPE, depending on what Apex class
>>>>> I'm analyzing.
>>>>>
>>>>> package net.sourceforge.pmd.lang.apex.custom;
>>>>>
>>>>> import java.util.regex.Matcher;
>>>>> import java.util.regex.Pattern;
>>>>>
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>>>
>>>>> // this rule checks for hard coded ids
>>>>>
>>>>> public class ApexHardCodedIdRule extends AbstractApexRule {
>>>>>
>>>>> public Object visit(ASTLiteralExpression node, Object data){
>>>>>
>>>>> // look for string starting w/ 3 digits
>>>>> Pattern pattern = Pattern.compile("^[0-9]{3}");
>>>>> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString());
>>>>> // NPE HAPPENS HERE
>>>>>
>>>>> // look for 15 or 18 digit string or
>>>>> // look for 3 digit string at start
>>>>> // of any string
>>>>> if(node.getNode().getLiteral().toString().length() == 15 ||
>>>>> node.getNode().getLiteral().toString().length() == 18
>>>>> ||
>>>>> matcher.find()) {
>>>>>
>>>>> addViolation(data, node);
>>>>> }
>>>>>
>>>>> return data;
>>>>>
>>>>> }
>>>>> }
>>>>>
>>>>> And for this rule, I get an error while trying to cast types of nodes.
>>>>>
>>>>> package net.sourceforge.pmd.lang.apex.custom;
>>>>>
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>>>
>>>>> // this rule checks for the use of size() over isEmpty()
>>>>>
>>>>> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule {
>>>>>
>>>>> public Object visit(ASTBooleanExpression node, Object data){
>>>>>
>>>>> ASTMethodCallExpression method = (ASTMethodCallExpression)
>>>>> node.jjtGetChild(0);
>>>>> ASTLiteralExpression exp = (ASTLiteralExpression)
>>>>> node.jjtGetChild(1);
>>>>>
>>>>> // if comparison to 0 used in conjunction with size() method
>>>>> // add violation
>>>>> if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison")
>>>>>
>>>>> && method.getMethodName().toString().equalsIgnoreCase("size")
>>>>>
>>>>> && exp.getNode().getLiteral().toString().equalsIgnoreCase("0"))
>>>>> {
>>>>> addViolation(data, node);
>>>>> }
>>>>>
>>>>> return data;
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> However, both of these classes run just fine when I use them in my
>>>>> custom test class, with their respective custom test data. They both find
>>>>> the correct errors in that case.
>>>>>
>>>>> I don't know why they work in a test environment, but get fatal errors
>>>>> when I run them on other Apex classes.
>>>>>
>>>>> Also, when modifying the NcssMethodCountRule to 50 lines of code, do I
>>>>> change the
>>>>>
>>>>> setProperty(MINIMUM_DESCRIPTOR, 40d);
>>>>>
>>>>> to 50d?
>>>>>
>>>>> Any help is welcome.
>>>>>
>>>>> --
>>>>> Caleb Knox
>>>>>
>>>>> Endeveran
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Caleb Knox
>>>>
>>>> Endeveran
>>>>
>>>
>>>
>>>
>>> --
>>> Caleb Knox
>>>
>>> Endeveran
>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> Pmd-devel mailing list
>>> Pmd...@li...
>>> https://lists.sourceforge.net/lists/listinfo/pmd-devel
>>>
>>>
>>
>
>
> --
> Caleb Knox
>
> Endeveran
>
|
|
From: Caleb K. <cal...@en...> - 2017-07-17 18:19:13
|
Sorry, I was unclear about the NcssMethodCountRule. I copy/pasted the code
into my custom rule.
Again, what do I change?
On Mon, Jul 17, 2017 at 1:16 PM, Caleb Knox <cal...@en...>
wrote:
> As for your casts... why are you assuming ALL BooleanExpressions are
>> formed with a method call and a literal? I can think of plenty of boolean
>> expressions that are not built that way (ie: myVar == 1)
>
>
> I am not, as far as I know. I am just looking for such expressions that
> contain a method call and a literal. Specifically, and .size() comparison
> to 0.
>
> Finally, do not edit the property value on the source. It's a property so
>> people can customize the value on their rulesets. Just configure it as you
>> wish on your custom ruleset.
>>
>
> I am not, but in my custom rule, what property do I change? That is what I
> had asked.
>
> On Mon, Jul 17, 2017 at 1:12 PM, Juan Martín Sotuyo Dodero <
> jua...@gm...> wrote:
>
>> As for NPEs, you can either debug when analyzing your real-code, or make
>> new code samples based on the contents of the file on which the NPE is
>> found. You are most probably just missing cases on your test scenarios.
>>
>> As for your casts... why are you assuming ALL BooleanExpressions are
>> formed with a method call and a literal? I can think of plenty of boolean
>> expressions that are not built that way (ie: myVar == 1)
>>
>> Finally, do not edit the property value on the source. It's a property so
>> people can customize the value on their rulesets. Just configure it as you
>> wish on your custom ruleset.
>>
>> Regards
>>
>> On Mon, Jul 17, 2017 at 3:07 PM, Caleb Knox <cal...@en...>
>> wrote:
>>
>>> Okay, sorry about that. The hard-coded ID rule is working from command
>>> line as well. I am unsure as to what is broken.
>>>
>>> On Mon, Jul 17, 2017 at 1:01 PM, Caleb Knox <cal...@en...>
>>> wrote:
>>>
>>>> Did some more testing... If I run from the command line, the ApexUseSizeOverIsEmptyRule
>>>> works just fine. Hard-coded ID rule is probably broken.
>>>>
>>>> On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox <cal...@en...>
>>>> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> For this rule, I sometimes get an NPE, depending on what Apex class
>>>>> I'm analyzing.
>>>>>
>>>>> package net.sourceforge.pmd.lang.apex.custom;
>>>>>
>>>>> import java.util.regex.Matcher;
>>>>> import java.util.regex.Pattern;
>>>>>
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>>>
>>>>> // this rule checks for hard coded ids
>>>>>
>>>>> public class ApexHardCodedIdRule extends AbstractApexRule {
>>>>>
>>>>> public Object visit(ASTLiteralExpression node, Object data){
>>>>>
>>>>> // look for string starting w/ 3 digits
>>>>> Pattern pattern = Pattern.compile("^[0-9]{3}");
>>>>> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString());
>>>>> // NPE HAPPENS HERE
>>>>>
>>>>> // look for 15 or 18 digit string or
>>>>> // look for 3 digit string at start
>>>>> // of any string
>>>>> if(node.getNode().getLiteral().toString().length() == 15 ||
>>>>> node.getNode().getLiteral().toString().length() == 18
>>>>> ||
>>>>> matcher.find()) {
>>>>>
>>>>> addViolation(data, node);
>>>>> }
>>>>>
>>>>> return data;
>>>>>
>>>>> }
>>>>> }
>>>>>
>>>>> And for this rule, I get an error while trying to cast types of nodes.
>>>>>
>>>>> package net.sourceforge.pmd.lang.apex.custom;
>>>>>
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>>>> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
>>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>>>
>>>>> // this rule checks for the use of size() over isEmpty()
>>>>>
>>>>> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule {
>>>>>
>>>>> public Object visit(ASTBooleanExpression node, Object data){
>>>>>
>>>>> ASTMethodCallExpression method = (ASTMethodCallExpression)
>>>>> node.jjtGetChild(0);
>>>>> ASTLiteralExpression exp = (ASTLiteralExpression)
>>>>> node.jjtGetChild(1);
>>>>>
>>>>> // if comparison to 0 used in conjunction with size() method
>>>>> // add violation
>>>>> if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison")
>>>>>
>>>>> && method.getMethodName().toString().equalsIgnoreCase("size")
>>>>>
>>>>> && exp.getNode().getLiteral().toString().equalsIgnoreCase("0"))
>>>>> {
>>>>> addViolation(data, node);
>>>>> }
>>>>>
>>>>> return data;
>>>>>
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> However, both of these classes run just fine when I use them in my
>>>>> custom test class, with their respective custom test data. They both find
>>>>> the correct errors in that case.
>>>>>
>>>>> I don't know why they work in a test environment, but get fatal errors
>>>>> when I run them on other Apex classes.
>>>>>
>>>>> Also, when modifying the NcssMethodCountRule to 50 lines of code, do I
>>>>> change the
>>>>>
>>>>> setProperty(MINIMUM_DESCRIPTOR, 40d);
>>>>>
>>>>> to 50d?
>>>>>
>>>>> Any help is welcome.
>>>>>
>>>>> --
>>>>> Caleb Knox
>>>>>
>>>>> Endeveran
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Caleb Knox
>>>>
>>>> Endeveran
>>>>
>>>
>>>
>>>
>>> --
>>> Caleb Knox
>>>
>>> Endeveran
>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> Pmd-devel mailing list
>>> Pmd...@li...
>>> https://lists.sourceforge.net/lists/listinfo/pmd-devel
>>>
>>>
>>
>
>
> --
> Caleb Knox
>
> Endeveran
>
--
Caleb Knox
Endeveran
|
|
From: Caleb K. <cal...@en...> - 2017-07-17 18:16:59
|
>
> As for your casts... why are you assuming ALL BooleanExpressions are
> formed with a method call and a literal? I can think of plenty of boolean
> expressions that are not built that way (ie: myVar == 1)
I am not, as far as I know. I am just looking for such expressions that
contain a method call and a literal. Specifically, and .size() comparison
to 0.
Finally, do not edit the property value on the source. It's a property so
> people can customize the value on their rulesets. Just configure it as you
> wish on your custom ruleset.
>
I am not, but in my custom rule, what property do I change? That is what I
had asked.
On Mon, Jul 17, 2017 at 1:12 PM, Juan Martín Sotuyo Dodero <
jua...@gm...> wrote:
> As for NPEs, you can either debug when analyzing your real-code, or make
> new code samples based on the contents of the file on which the NPE is
> found. You are most probably just missing cases on your test scenarios.
>
> As for your casts... why are you assuming ALL BooleanExpressions are
> formed with a method call and a literal? I can think of plenty of boolean
> expressions that are not built that way (ie: myVar == 1)
>
> Finally, do not edit the property value on the source. It's a property so
> people can customize the value on their rulesets. Just configure it as you
> wish on your custom ruleset.
>
> Regards
>
> On Mon, Jul 17, 2017 at 3:07 PM, Caleb Knox <cal...@en...>
> wrote:
>
>> Okay, sorry about that. The hard-coded ID rule is working from command
>> line as well. I am unsure as to what is broken.
>>
>> On Mon, Jul 17, 2017 at 1:01 PM, Caleb Knox <cal...@en...>
>> wrote:
>>
>>> Did some more testing... If I run from the command line, the ApexUseSizeOverIsEmptyRule
>>> works just fine. Hard-coded ID rule is probably broken.
>>>
>>> On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox <cal...@en...>
>>> wrote:
>>>
>>>> Hello,
>>>>
>>>> For this rule, I sometimes get an NPE, depending on what Apex class I'm
>>>> analyzing.
>>>>
>>>> package net.sourceforge.pmd.lang.apex.custom;
>>>>
>>>> import java.util.regex.Matcher;
>>>> import java.util.regex.Pattern;
>>>>
>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>>
>>>> // this rule checks for hard coded ids
>>>>
>>>> public class ApexHardCodedIdRule extends AbstractApexRule {
>>>>
>>>> public Object visit(ASTLiteralExpression node, Object data){
>>>>
>>>> // look for string starting w/ 3 digits
>>>> Pattern pattern = Pattern.compile("^[0-9]{3}");
>>>> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString());
>>>> // NPE HAPPENS HERE
>>>>
>>>> // look for 15 or 18 digit string or
>>>> // look for 3 digit string at start
>>>> // of any string
>>>> if(node.getNode().getLiteral().toString().length() == 15 ||
>>>> node.getNode().getLiteral().toString().length() == 18
>>>> ||
>>>> matcher.find()) {
>>>>
>>>> addViolation(data, node);
>>>> }
>>>>
>>>> return data;
>>>>
>>>> }
>>>> }
>>>>
>>>> And for this rule, I get an error while trying to cast types of nodes.
>>>>
>>>> package net.sourceforge.pmd.lang.apex.custom;
>>>>
>>>> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
>>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>>> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
>>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>>
>>>> // this rule checks for the use of size() over isEmpty()
>>>>
>>>> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule {
>>>>
>>>> public Object visit(ASTBooleanExpression node, Object data){
>>>>
>>>> ASTMethodCallExpression method = (ASTMethodCallExpression)
>>>> node.jjtGetChild(0);
>>>> ASTLiteralExpression exp = (ASTLiteralExpression)
>>>> node.jjtGetChild(1);
>>>>
>>>> // if comparison to 0 used in conjunction with size() method
>>>> // add violation
>>>> if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison")
>>>>
>>>> && method.getMethodName().toString().equalsIgnoreCase("size")
>>>>
>>>> && exp.getNode().getLiteral().toString().equalsIgnoreCase("0"))
>>>> {
>>>> addViolation(data, node);
>>>> }
>>>>
>>>> return data;
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>> However, both of these classes run just fine when I use them in my
>>>> custom test class, with their respective custom test data. They both find
>>>> the correct errors in that case.
>>>>
>>>> I don't know why they work in a test environment, but get fatal errors
>>>> when I run them on other Apex classes.
>>>>
>>>> Also, when modifying the NcssMethodCountRule to 50 lines of code, do I
>>>> change the
>>>>
>>>> setProperty(MINIMUM_DESCRIPTOR, 40d);
>>>>
>>>> to 50d?
>>>>
>>>> Any help is welcome.
>>>>
>>>> --
>>>> Caleb Knox
>>>>
>>>> Endeveran
>>>>
>>>
>>>
>>>
>>> --
>>> Caleb Knox
>>>
>>> Endeveran
>>>
>>
>>
>>
>> --
>> Caleb Knox
>>
>> Endeveran
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Pmd-devel mailing list
>> Pmd...@li...
>> https://lists.sourceforge.net/lists/listinfo/pmd-devel
>>
>>
>
--
Caleb Knox
Endeveran
|
|
From: Juan M. S. D. <jua...@gm...> - 2017-07-17 18:12:59
|
As for NPEs, you can either debug when analyzing your real-code, or make
new code samples based on the contents of the file on which the NPE is
found. You are most probably just missing cases on your test scenarios.
As for your casts... why are you assuming ALL BooleanExpressions are formed
with a method call and a literal? I can think of plenty of boolean
expressions that are not built that way (ie: myVar == 1)
Finally, do not edit the property value on the source. It's a property so
people can customize the value on their rulesets. Just configure it as you
wish on your custom ruleset.
Regards
On Mon, Jul 17, 2017 at 3:07 PM, Caleb Knox <cal...@en...>
wrote:
> Okay, sorry about that. The hard-coded ID rule is working from command
> line as well. I am unsure as to what is broken.
>
> On Mon, Jul 17, 2017 at 1:01 PM, Caleb Knox <cal...@en...>
> wrote:
>
>> Did some more testing... If I run from the command line, the ApexUseSizeOverIsEmptyRule
>> works just fine. Hard-coded ID rule is probably broken.
>>
>> On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox <cal...@en...>
>> wrote:
>>
>>> Hello,
>>>
>>> For this rule, I sometimes get an NPE, depending on what Apex class I'm
>>> analyzing.
>>>
>>> package net.sourceforge.pmd.lang.apex.custom;
>>>
>>> import java.util.regex.Matcher;
>>> import java.util.regex.Pattern;
>>>
>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>
>>> // this rule checks for hard coded ids
>>>
>>> public class ApexHardCodedIdRule extends AbstractApexRule {
>>>
>>> public Object visit(ASTLiteralExpression node, Object data){
>>>
>>> // look for string starting w/ 3 digits
>>> Pattern pattern = Pattern.compile("^[0-9]{3}");
>>> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString());
>>> // NPE HAPPENS HERE
>>>
>>> // look for 15 or 18 digit string or
>>> // look for 3 digit string at start
>>> // of any string
>>> if(node.getNode().getLiteral().toString().length() == 15 ||
>>> node.getNode().getLiteral().toString().length() == 18 ||
>>> matcher.find()) {
>>>
>>> addViolation(data, node);
>>> }
>>>
>>> return data;
>>>
>>> }
>>> }
>>>
>>> And for this rule, I get an error while trying to cast types of nodes.
>>>
>>> package net.sourceforge.pmd.lang.apex.custom;
>>>
>>> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
>>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>>> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
>>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>>
>>> // this rule checks for the use of size() over isEmpty()
>>>
>>> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule {
>>>
>>> public Object visit(ASTBooleanExpression node, Object data){
>>>
>>> ASTMethodCallExpression method = (ASTMethodCallExpression)
>>> node.jjtGetChild(0);
>>> ASTLiteralExpression exp = (ASTLiteralExpression)
>>> node.jjtGetChild(1);
>>>
>>> // if comparison to 0 used in conjunction with size() method
>>> // add violation
>>> if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison")
>>>
>>> && method.getMethodName().toString().equalsIgnoreCase("size")
>>>
>>> && exp.getNode().getLiteral().toString().equalsIgnoreCase("0"))
>>> {
>>> addViolation(data, node);
>>> }
>>>
>>> return data;
>>>
>>> }
>>>
>>> }
>>>
>>>
>>> However, both of these classes run just fine when I use them in my
>>> custom test class, with their respective custom test data. They both find
>>> the correct errors in that case.
>>>
>>> I don't know why they work in a test environment, but get fatal errors
>>> when I run them on other Apex classes.
>>>
>>> Also, when modifying the NcssMethodCountRule to 50 lines of code, do I
>>> change the
>>>
>>> setProperty(MINIMUM_DESCRIPTOR, 40d);
>>>
>>> to 50d?
>>>
>>> Any help is welcome.
>>>
>>> --
>>> Caleb Knox
>>>
>>> Endeveran
>>>
>>
>>
>>
>> --
>> Caleb Knox
>>
>> Endeveran
>>
>
>
>
> --
> Caleb Knox
>
> Endeveran
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Pmd-devel mailing list
> Pmd...@li...
> https://lists.sourceforge.net/lists/listinfo/pmd-devel
>
>
|
|
From: Caleb K. <cal...@en...> - 2017-07-17 18:07:15
|
Okay, sorry about that. The hard-coded ID rule is working from command line
as well. I am unsure as to what is broken.
On Mon, Jul 17, 2017 at 1:01 PM, Caleb Knox <cal...@en...>
wrote:
> Did some more testing... If I run from the command line, the ApexUseSizeOverIsEmptyRule
> works just fine. Hard-coded ID rule is probably broken.
>
> On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox <cal...@en...>
> wrote:
>
>> Hello,
>>
>> For this rule, I sometimes get an NPE, depending on what Apex class I'm
>> analyzing.
>>
>> package net.sourceforge.pmd.lang.apex.custom;
>>
>> import java.util.regex.Matcher;
>> import java.util.regex.Pattern;
>>
>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>
>> // this rule checks for hard coded ids
>>
>> public class ApexHardCodedIdRule extends AbstractApexRule {
>>
>> public Object visit(ASTLiteralExpression node, Object data){
>>
>> // look for string starting w/ 3 digits
>> Pattern pattern = Pattern.compile("^[0-9]{3}");
>> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString());
>> // NPE HAPPENS HERE
>>
>> // look for 15 or 18 digit string or
>> // look for 3 digit string at start
>> // of any string
>> if(node.getNode().getLiteral().toString().length() == 15 ||
>> node.getNode().getLiteral().toString().length() == 18 ||
>> matcher.find()) {
>>
>> addViolation(data, node);
>> }
>>
>> return data;
>>
>> }
>> }
>>
>> And for this rule, I get an error while trying to cast types of nodes.
>>
>> package net.sourceforge.pmd.lang.apex.custom;
>>
>> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
>> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
>> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
>> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>>
>> // this rule checks for the use of size() over isEmpty()
>>
>> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule {
>>
>> public Object visit(ASTBooleanExpression node, Object data){
>>
>> ASTMethodCallExpression method = (ASTMethodCallExpression)
>> node.jjtGetChild(0);
>> ASTLiteralExpression exp = (ASTLiteralExpression)
>> node.jjtGetChild(1);
>>
>> // if comparison to 0 used in conjunction with size() method
>> // add violation
>> if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison")
>>
>> && method.getMethodName().toString().equalsIgnoreCase("size")
>>
>> && exp.getNode().getLiteral().toString().equalsIgnoreCase("0"))
>> {
>> addViolation(data, node);
>> }
>>
>> return data;
>>
>> }
>>
>> }
>>
>>
>> However, both of these classes run just fine when I use them in my custom
>> test class, with their respective custom test data. They both find the
>> correct errors in that case.
>>
>> I don't know why they work in a test environment, but get fatal errors
>> when I run them on other Apex classes.
>>
>> Also, when modifying the NcssMethodCountRule to 50 lines of code, do I
>> change the
>>
>> setProperty(MINIMUM_DESCRIPTOR, 40d);
>>
>> to 50d?
>>
>> Any help is welcome.
>>
>> --
>> Caleb Knox
>>
>> Endeveran
>>
>
>
>
> --
> Caleb Knox
>
> Endeveran
>
--
Caleb Knox
Endeveran
|
|
From: Caleb K. <cal...@en...> - 2017-07-17 18:02:00
|
Did some more testing... If I run from the command line, the
ApexUseSizeOverIsEmptyRule
works just fine. Hard-coded ID rule is probably broken.
On Mon, Jul 17, 2017 at 12:18 PM, Caleb Knox <cal...@en...>
wrote:
> Hello,
>
> For this rule, I sometimes get an NPE, depending on what Apex class I'm
> analyzing.
>
> package net.sourceforge.pmd.lang.apex.custom;
>
> import java.util.regex.Matcher;
> import java.util.regex.Pattern;
>
> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>
> // this rule checks for hard coded ids
>
> public class ApexHardCodedIdRule extends AbstractApexRule {
>
> public Object visit(ASTLiteralExpression node, Object data){
>
> // look for string starting w/ 3 digits
> Pattern pattern = Pattern.compile("^[0-9]{3}");
> Matcher matcher = pattern.matcher(node.getNode().getLiteral().toString());
> // NPE HAPPENS HERE
>
> // look for 15 or 18 digit string or
> // look for 3 digit string at start
> // of any string
> if(node.getNode().getLiteral().toString().length() == 15 ||
> node.getNode().getLiteral().toString().length() == 18 ||
> matcher.find()) {
>
> addViolation(data, node);
> }
>
> return data;
>
> }
> }
>
> And for this rule, I get an error while trying to cast types of nodes.
>
> package net.sourceforge.pmd.lang.apex.custom;
>
> import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
> import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
> import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
> import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
>
> // this rule checks for the use of size() over isEmpty()
>
> public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule {
>
> public Object visit(ASTBooleanExpression node, Object data){
>
> ASTMethodCallExpression method = (ASTMethodCallExpression)
> node.jjtGetChild(0);
> ASTLiteralExpression exp = (ASTLiteralExpression)
> node.jjtGetChild(1);
>
> // if comparison to 0 used in conjunction with size() method
> // add violation
> if(node.getNode().getBooleanExpressionType().
> toString().equalsIgnoreCase("comparison")
> && method.getMethodName().toString().equalsIgnoreCase("size")
>
> && exp.getNode().getLiteral().
> toString().equalsIgnoreCase("0")) {
> addViolation(data, node);
> }
>
> return data;
>
> }
>
> }
>
>
> However, both of these classes run just fine when I use them in my custom
> test class, with their respective custom test data. They both find the
> correct errors in that case.
>
> I don't know why they work in a test environment, but get fatal errors
> when I run them on other Apex classes.
>
> Also, when modifying the NcssMethodCountRule to 50 lines of code, do I
> change the
>
> setProperty(MINIMUM_DESCRIPTOR, 40d);
>
> to 50d?
>
> Any help is welcome.
>
> --
> Caleb Knox
>
> Endeveran
>
--
Caleb Knox
Endeveran
|
|
From: Caleb K. <cal...@en...> - 2017-07-17 17:18:15
|
Hello,
For this rule, I sometimes get an NPE, depending on what Apex class I'm
analyzing.
package net.sourceforge.pmd.lang.apex.custom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
// this rule checks for hard coded ids
public class ApexHardCodedIdRule extends AbstractApexRule {
public Object visit(ASTLiteralExpression node, Object data){
// look for string starting w/ 3 digits
Pattern pattern = Pattern.compile("^[0-9]{3}");
Matcher matcher =
pattern.matcher(node.getNode().getLiteral().toString()); // NPE HAPPENS HERE
// look for 15 or 18 digit string or
// look for 3 digit string at start
// of any string
if(node.getNode().getLiteral().toString().length() == 15 ||
node.getNode().getLiteral().toString().length() == 18 ||
matcher.find()) {
addViolation(data, node);
}
return data;
}
}
And for this rule, I get an error while trying to cast types of nodes.
package net.sourceforge.pmd.lang.apex.custom;
import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
// this rule checks for the use of size() over isEmpty()
public class ApexUseSizeOverIsEmptyRule extends AbstractApexRule {
public Object visit(ASTBooleanExpression node, Object data){
ASTMethodCallExpression method = (ASTMethodCallExpression)
node.jjtGetChild(0);
ASTLiteralExpression exp = (ASTLiteralExpression)
node.jjtGetChild(1);
// if comparison to 0 used in conjunction with size() method
// add violation
if(node.getNode().getBooleanExpressionType().toString().equalsIgnoreCase("comparison")
&&
method.getMethodName().toString().equalsIgnoreCase("size")
&&
exp.getNode().getLiteral().toString().equalsIgnoreCase("0")) {
addViolation(data, node);
}
return data;
}
}
However, both of these classes run just fine when I use them in my custom
test class, with their respective custom test data. They both find the
correct errors in that case.
I don't know why they work in a test environment, but get fatal errors when
I run them on other Apex classes.
Also, when modifying the NcssMethodCountRule to 50 lines of code, do I
change the
setProperty(MINIMUM_DESCRIPTOR, 40d);
to 50d?
Any help is welcome.
--
Caleb Knox
Endeveran
|
|
From: Rory O'D. <ror...@or...> - 2017-07-17 12:06:11
|
Hi Andreas, *JDK 9 Early Access* build 178 is available at : - jdk.java.net/9/ A summary of all the changes in this build are listed here <http://download.java.net/java/jdk9/changes/jdk-9+178.html>. Changes which were introduced since the last availability email that may be of interest : * b175 - Module system implementation refresh**(6/2017 update) * b175 - no longer has "-ea" in the version string and the system property "java version" is now simply "9" o *java -version* >java version "9" >Java(TM) SE Runtime Environment (build 9+175) >Java HotSpot(TM) 64-Bit Server VM (build 9+175, mixed mode) o *Bundle name changes:* e.g. jdk-9+175_linux-x86_bin.tar.gz *JDK 8u152 Early Access* build 05 is available at : - jdk.java.net/8/ <http://jdk.java.net/8/> A summary of all the changes in this build are listed here <http://download.java.net/java/jdk8u152/changes/jdk8u152-b05.html>. Rgds,Rory -- Rgds,Rory O'Donnell Quality Engineering Manager Oracle EMEA , Dublin, Ireland |
|
From: Juan M. S. D. <jua...@gm...> - 2017-07-14 23:41:23
|
ApexOptimizeSoqlRule: > > So, what I mean is that I'd like to check the ForEach to see if there is a > Soql expression within its declaration, because that's a direct child node. > Is that wrong? Isn't this the "right" way to do it? Why do you want to look for it if it's ok? > Actually, I am not sure how to do this, since > ASTVariableDeclarationStatements doesn't have a getCanonicalQuery() > method, or anything like that. I think you got this mixed up. The getCanonicalQuery() method is for the SOQL's raw node, but you don't really care about it for this rule. You just want to check there the variable to which the SOQL is assigned to is used. ApexReadabilityRule: > > Triggers in Salesforce should not have any logic. The trigger should call > a handler. Given an example of what would be right / wrong would certainly help. I'd not even be able to recognize a trigger from a class at this moment. ApexSingleSoqlResultRule > I can't seem to figure out how to check for a QueryException specifically > as in the TryCatchFinallyBlockStatement node, there isn't a way to access > what's inside the catch() argument, from what I can tell using PMD Designer. I'd have to check, but you can probably get it from the raw node from Apex Jorje (node.getNode())... Not sure though On Fri, Jul 14, 2017 at 2:33 PM, Caleb Knox <cal...@en...> wrote: > ApexSingleSoqlResultRule > > I am checking ASTSoqlExpression nodes. If their parent nodes include a >>> try/catch, no violation. Else, add violation. >>> >> 2 things here. I believe you already thought about this, but the try may >> not be a direct parent but some other ancestor of the node, and you have to >> actually check if the exception being caught is a QueryException >> > I can't seem to figure out how to check for a QueryException specifically > as in the TryCatchFinallyBlockStatement node, there isn't a way to access > what's inside the catch() argument, from what I can tell using PMD Designer. > > > On Fri, Jul 14, 2017 at 10:46 AM, Caleb Knox <cal...@en...> > wrote: > >> >> ApexOptimizeSoqlRule: >>> >>> looking at ASTSoqlExpression nodes and checking their parents for a >>>> List<> declaration >>> >>> This is actually good. Once you get that List<> declaration, you need >>> to check if it is being used in a foreach and if so flag it. >>> >> Actually, I am not sure how to do this, since >> ASTVariableDeclarationStatements doesn't have a getCanonicalQuery() >> method, or anything like that. >> >> >> On Fri, Jul 14, 2017 at 10:15 AM, Caleb Knox <cal...@en...> >> wrote: >> >>> ApexOptimizeSoqlRule: >>> >>> I was planning on looking at ASTForEachStatement nodes, checking the >>>> children for an ASTSoqlExpression node >>>> >>> I’m not sure I understand this… as far as I can tell, this is actually >>>> the desired code, so there is no point ins searching for it (you only want >>>> to add warnings for violations). >>>> >>> So, what I mean is that I'd like to check the ForEach to see if there is >>> a Soql expression within its declaration, because that's a direct child >>> node. Is that wrong? >>> >>> >>> ApexReadabilityRule: >>> >>> >>>> - Non trigger framework code exists in triggers => add to violation >>>> count >>>> >>>> I’m not sure what this would be. I’m not an Apex developer. Given >>>> proper samples I may assist you non the lest given I do know about it’s AST. >>>> >>> Triggers in Salesforce should not have any logic. The trigger should >>> call a handler. >>> >>> Thanks. >>> >>> >>> On Fri, Jul 14, 2017 at 9:14 AM, Caleb Knox <cal...@en...> >>> wrote: >>> >>>> Thanks for the insight. I'll get back to you about the ApexOptimizeSoql >>>> if I don't get it right soon. >>>> >>>> I can definitely add these rules to PMD, assuming my boss okays it. >>>> >>>> On Thu, Jul 13, 2017 at 6:48 PM, Juan Martín Sotuyo Dodero < >>>> jua...@gm...> wrote: >>>> >>>>> Hi Caleb, >>>>> >>>>> I’m glad to see you are making progress. Are you planning to >>>>> contribute these rules back to PMD? If so, it will be easier / we will be >>>>> far more willing to help you out. Just submit a PR for each in such case >>>>> and we will comment directly on your code. >>>>> >>>>> In the meantime, let me go in order: >>>>> ApexOptimizeSoqlRule: >>>>> >>>>> I was planning on looking at ASTForEachStatement nodes, checking the >>>>> children for an ASTSoqlExpression node >>>>> >>>>> I’m not sure I understand this… as far as I can tell, this is actually >>>>> the desired code, so there is no point ins searching for it (you only want >>>>> to add warnings for violations). >>>>> >>>>> looking at ASTSoqlExpression nodes and checking their parents for a >>>>> List<> declaration >>>>> >>>>> This is actually good. Once you get that List<> declaration, you need >>>>> to check if it is being used in a foreach and if so flag it. >>>>> ApexSingleSoqlResultRule >>>>> >>>>> I am checking ASTSoqlExpression nodes. If their parent nodes include a >>>>> try/catch, no violation. Else, add violation. >>>>> >>>>> 2 things here. I believe you already thought about this, but the try >>>>> may not be a direct parent but some other ancestor of the node, and you >>>>> have to actually check if the exception being caught is a >>>>> QueryException >>>>> >>>>> I also check the ASTSoqlExpression for a LIMIT 1 since that’s how >>>>> people avoid the QueryException. >>>>> >>>>> This is a must to avoid flagging all SOQL. Given ASTSoqlExpression >>>>> node you can do node.getNode().getCanonicalQuery() to obtain the >>>>> contents of the expression being used. >>>>> ApexCommentRule >>>>> >>>>> can I just use a Java rule, like CommentRequiredRule? >>>>> >>>>> No you can’t. The Java rules use the Java Lexer and Parser, that only >>>>> recognize Java code. You need Apex specific rules to do this. >>>>> >>>>> Comments are not part of the AST, so doing this will not be trivial. >>>>> I’m not sure the Jorje parser provides access to comments at all, I’d have >>>>> to check the APIs and do some tests… >>>>> ApexReadabilityRule >>>>> >>>>> >>>>> - Lines of code in a method exceed 50 => add to violation count >>>>> >>>>> This is already implemented as apex-complexity/NcssMethodCount >>>>> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#NcssMethodCount>. >>>>> The default is 40 lines (without comments), but can be configured >>>>> >>>>> >>>>> - Nested if statements exceed more than 3 => add to violation count >>>>> >>>>> This is already implemented as apex-complexity/AvoidDeeplyNes >>>>> tedIfStmts >>>>> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#AvoidDeeplyNestedIfStmts>. >>>>> The default limit is exactly 3, you would have to set it to 4 to allow up >>>>> to 3. >>>>> >>>>> >>>>> - Non trigger framework code exists in triggers => add to >>>>> violation count >>>>> >>>>> I’m not sure what this would be. I’m not an Apex developer. Given >>>>> proper samples I may assist you non the lest given I do know about it’s AST. >>>>> >>>>> Regards, >>>>> >>>>> >>>>> On Thu, Jul 13, 2017 at 6:38 PM, Caleb Knox <cal...@en...> >>>>> wrote: >>>>> >>>>>> Hi there folks, >>>>>> >>>>>> I am trying to implement a few more rules for the project I've >>>>>> emailed about before, before we send it off to our customers. This is >>>>>> working with Salesforce/Apex classes. >>>>>> >>>>>> Here they are: >>>>>> >>>>>> >>>>>> >>>>>> *ApexOptimizeSoqlRule* >>>>>> Example: >>>>>> >>>>>> List<Account> acct = […]; >>>>>> for (Account a : acct ) { >>>>>> >>>>>> } >>>>>> >>>>>> // add violation >>>>>> >>>>>> ------------------------------------------- >>>>>> >>>>>> // optimized version >>>>>> >>>>>> for (Account acct : [Select … ] ) { >>>>>> >>>>>> } >>>>>> >>>>>> // all good >>>>>> >>>>>> For this rule, I was planning on looking at ASTForEachStatement >>>>>> nodes, checking the children for an ASTSoqlExpression node, as well as >>>>>> looking at ASTSoqlExpression nodes and checking their parents for a List<> >>>>>> declaration. However, what I have is not working, so I am wondering if my >>>>>> basic way of thinking about this rule is wrong, and if I should do >>>>>> something else. >>>>>> >>>>>> >>>>>> >>>>>> *ApexSingleSoqlResultRule* >>>>>> Example: >>>>>> >>>>>> Account acct = [Select Id From Account Where Name = ‘abc’ ]; >>>>>> >>>>>> // Get QueryException back if 0 or duplicate >>>>>> >>>>>> // People try to avoid by doing: >>>>>> >>>>>> List<Account> acct = [Select … LIMIT 1]; // bad practice to avoid >>>>>> dupes etc --> add violation >>>>>> >>>>>> if (acct.size() > 0 ) >>>>>> >>>>>> [...] >>>>>> >>>>>> >>>>>> -------------------------------------------- >>>>>> >>>>>> // Best practice is: >>>>>> >>>>>> try { >>>>>> Account acct = […]; >>>>>> } catch (QueryException q){ >>>>>> >>>>>> } >>>>>> >>>>>> For this rule, I am checking ASTSoqlExpression nodes. If their parent >>>>>> nodes include a try/catch, no violation. Else, add violation. >>>>>> >>>>>> I also check the ASTSoqlExpression for a LIMIT 1 since that's how >>>>>> people avoid the QueryException. But, I don't quite know how to do that. >>>>>> >>>>>> Maybe something like this? >>>>>> >>>>>> if(node.getNode().getQuery().toLowerCase().contains("list") && >>>>>> node.getNode().getQuery().toLowerCase().contains("limit >>>>>> 1")) >>>>>> >>>>>> >>>>>> *ApexCommentRule* >>>>>> >>>>>> The last two rules are related to readability. The first one looks at >>>>>> the following: >>>>>> >>>>>> - No class or method comments => add to violation count >>>>>> >>>>>> >>>>>> For this, can I just use a Java rule, like CommentRequiredRule? >>>>>> >>>>>> *ApexReadabilityRule* >>>>>> >>>>>> The last one follows these criteria: >>>>>> >>>>>> - Lines of code in a method exceed 50 => add to violation count >>>>>> - Nested if statements exceed more than 3 => add to violation >>>>>> count >>>>>> - Non trigger framework code exists in triggers => add to >>>>>> violation count >>>>>> >>>>>> >>>>>> I'm not sure how to do this last one. >>>>>> >>>>>> If you have any insight or feedback, let me know! >>>>>> >>>>>> Thank you. >>>>>> >>>>>> -- >>>>>> Caleb Knox >>>>>> >>>>>> Endeveran >>>>>> >>>>>> ------------------------------------------------------------ >>>>>> ------------------ >>>>>> Check out the vibrant tech community on one of the world's most >>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>> _______________________________________________ >>>>>> Pmd-devel mailing list >>>>>> Pmd...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/pmd-devel >>>>>> >>>>>> >>>>> >>>> >>>> >>>> -- >>>> Caleb Knox >>>> >>>> Endeveran >>>> >>> >>> >>> >>> -- >>> Caleb Knox >>> >>> Endeveran >>> >> >> >> >> -- >> Caleb Knox >> >> Endeveran >> > > > > -- > Caleb Knox > > Endeveran > |
|
From: Juan M. S. D. <jua...@gm...> - 2017-07-14 18:47:17
|
Yes you can. You have a couple overrides to `addViolation` that allow passing arguments for message interpolation. https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java#L421-L435 On Fri, Jul 14, 2017 at 2:18 PM, Caleb Knox <cal...@en...> wrote: > Hey all, > > For PMD rule messages, can we somehow pass a parameter from a rule's Java > class into the XML file? > > For example: > > "You had " + count + " repeated increment statements. This is above the > threshold. Try instead: var += " + count + "." > > or something. > > Thanks much. > > -- > Caleb Knox > > Endeveran > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Pmd-devel mailing list > Pmd...@li... > https://lists.sourceforge.net/lists/listinfo/pmd-devel > > |
|
From: Caleb K. <cal...@en...> - 2017-07-14 17:33:45
|
ApexSingleSoqlResultRule I am checking ASTSoqlExpression nodes. If their parent nodes include a >> try/catch, no violation. Else, add violation. >> > 2 things here. I believe you already thought about this, but the try may > not be a direct parent but some other ancestor of the node, and you have to > actually check if the exception being caught is a QueryException > I can't seem to figure out how to check for a QueryException specifically as in the TryCatchFinallyBlockStatement node, there isn't a way to access what's inside the catch() argument, from what I can tell using PMD Designer. On Fri, Jul 14, 2017 at 10:46 AM, Caleb Knox <cal...@en...> wrote: > > ApexOptimizeSoqlRule: >> >> looking at ASTSoqlExpression nodes and checking their parents for a >>> List<> declaration >> >> This is actually good. Once you get that List<> declaration, you need to >> check if it is being used in a foreach and if so flag it. >> > Actually, I am not sure how to do this, since > ASTVariableDeclarationStatements doesn't have a getCanonicalQuery() > method, or anything like that. > > > On Fri, Jul 14, 2017 at 10:15 AM, Caleb Knox <cal...@en...> > wrote: > >> ApexOptimizeSoqlRule: >> >> I was planning on looking at ASTForEachStatement nodes, checking the >>> children for an ASTSoqlExpression node >>> >> I’m not sure I understand this… as far as I can tell, this is actually >>> the desired code, so there is no point ins searching for it (you only want >>> to add warnings for violations). >>> >> So, what I mean is that I'd like to check the ForEach to see if there is >> a Soql expression within its declaration, because that's a direct child >> node. Is that wrong? >> >> >> ApexReadabilityRule: >> >> >>> - Non trigger framework code exists in triggers => add to violation >>> count >>> >>> I’m not sure what this would be. I’m not an Apex developer. Given proper >>> samples I may assist you non the lest given I do know about it’s AST. >>> >> Triggers in Salesforce should not have any logic. The trigger should call >> a handler. >> >> Thanks. >> >> >> On Fri, Jul 14, 2017 at 9:14 AM, Caleb Knox <cal...@en...> >> wrote: >> >>> Thanks for the insight. I'll get back to you about the ApexOptimizeSoql >>> if I don't get it right soon. >>> >>> I can definitely add these rules to PMD, assuming my boss okays it. >>> >>> On Thu, Jul 13, 2017 at 6:48 PM, Juan Martín Sotuyo Dodero < >>> jua...@gm...> wrote: >>> >>>> Hi Caleb, >>>> >>>> I’m glad to see you are making progress. Are you planning to contribute >>>> these rules back to PMD? If so, it will be easier / we will be far more >>>> willing to help you out. Just submit a PR for each in such case and we will >>>> comment directly on your code. >>>> >>>> In the meantime, let me go in order: >>>> ApexOptimizeSoqlRule: >>>> >>>> I was planning on looking at ASTForEachStatement nodes, checking the >>>> children for an ASTSoqlExpression node >>>> >>>> I’m not sure I understand this… as far as I can tell, this is actually >>>> the desired code, so there is no point ins searching for it (you only want >>>> to add warnings for violations). >>>> >>>> looking at ASTSoqlExpression nodes and checking their parents for a >>>> List<> declaration >>>> >>>> This is actually good. Once you get that List<> declaration, you need >>>> to check if it is being used in a foreach and if so flag it. >>>> ApexSingleSoqlResultRule >>>> >>>> I am checking ASTSoqlExpression nodes. If their parent nodes include a >>>> try/catch, no violation. Else, add violation. >>>> >>>> 2 things here. I believe you already thought about this, but the try >>>> may not be a direct parent but some other ancestor of the node, and you >>>> have to actually check if the exception being caught is a >>>> QueryException >>>> >>>> I also check the ASTSoqlExpression for a LIMIT 1 since that’s how >>>> people avoid the QueryException. >>>> >>>> This is a must to avoid flagging all SOQL. Given ASTSoqlExpression node >>>> you can do node.getNode().getCanonicalQuery() to obtain the contents >>>> of the expression being used. >>>> ApexCommentRule >>>> >>>> can I just use a Java rule, like CommentRequiredRule? >>>> >>>> No you can’t. The Java rules use the Java Lexer and Parser, that only >>>> recognize Java code. You need Apex specific rules to do this. >>>> >>>> Comments are not part of the AST, so doing this will not be trivial. >>>> I’m not sure the Jorje parser provides access to comments at all, I’d have >>>> to check the APIs and do some tests… >>>> ApexReadabilityRule >>>> >>>> >>>> - Lines of code in a method exceed 50 => add to violation count >>>> >>>> This is already implemented as apex-complexity/NcssMethodCount >>>> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#NcssMethodCount>. >>>> The default is 40 lines (without comments), but can be configured >>>> >>>> >>>> - Nested if statements exceed more than 3 => add to violation count >>>> >>>> This is already implemented as apex-complexity/AvoidDeeplyNestedIfStmts >>>> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#AvoidDeeplyNestedIfStmts>. >>>> The default limit is exactly 3, you would have to set it to 4 to allow up >>>> to 3. >>>> >>>> >>>> - Non trigger framework code exists in triggers => add to violation >>>> count >>>> >>>> I’m not sure what this would be. I’m not an Apex developer. Given >>>> proper samples I may assist you non the lest given I do know about it’s AST. >>>> >>>> Regards, >>>> >>>> >>>> On Thu, Jul 13, 2017 at 6:38 PM, Caleb Knox <cal...@en...> >>>> wrote: >>>> >>>>> Hi there folks, >>>>> >>>>> I am trying to implement a few more rules for the project I've emailed >>>>> about before, before we send it off to our customers. This is working with >>>>> Salesforce/Apex classes. >>>>> >>>>> Here they are: >>>>> >>>>> >>>>> >>>>> *ApexOptimizeSoqlRule* >>>>> Example: >>>>> >>>>> List<Account> acct = […]; >>>>> for (Account a : acct ) { >>>>> >>>>> } >>>>> >>>>> // add violation >>>>> >>>>> ------------------------------------------- >>>>> >>>>> // optimized version >>>>> >>>>> for (Account acct : [Select … ] ) { >>>>> >>>>> } >>>>> >>>>> // all good >>>>> >>>>> For this rule, I was planning on looking at ASTForEachStatement nodes, >>>>> checking the children for an ASTSoqlExpression node, as well as looking at >>>>> ASTSoqlExpression nodes and checking their parents for a List<> >>>>> declaration. However, what I have is not working, so I am wondering if my >>>>> basic way of thinking about this rule is wrong, and if I should do >>>>> something else. >>>>> >>>>> >>>>> >>>>> *ApexSingleSoqlResultRule* >>>>> Example: >>>>> >>>>> Account acct = [Select Id From Account Where Name = ‘abc’ ]; >>>>> >>>>> // Get QueryException back if 0 or duplicate >>>>> >>>>> // People try to avoid by doing: >>>>> >>>>> List<Account> acct = [Select … LIMIT 1]; // bad practice to avoid >>>>> dupes etc --> add violation >>>>> >>>>> if (acct.size() > 0 ) >>>>> >>>>> [...] >>>>> >>>>> >>>>> -------------------------------------------- >>>>> >>>>> // Best practice is: >>>>> >>>>> try { >>>>> Account acct = […]; >>>>> } catch (QueryException q){ >>>>> >>>>> } >>>>> >>>>> For this rule, I am checking ASTSoqlExpression nodes. If their parent >>>>> nodes include a try/catch, no violation. Else, add violation. >>>>> >>>>> I also check the ASTSoqlExpression for a LIMIT 1 since that's how >>>>> people avoid the QueryException. But, I don't quite know how to do that. >>>>> >>>>> Maybe something like this? >>>>> >>>>> if(node.getNode().getQuery().toLowerCase().contains("list") && >>>>> node.getNode().getQuery().toLowerCase().contains("limit >>>>> 1")) >>>>> >>>>> >>>>> *ApexCommentRule* >>>>> >>>>> The last two rules are related to readability. The first one looks at >>>>> the following: >>>>> >>>>> - No class or method comments => add to violation count >>>>> >>>>> >>>>> For this, can I just use a Java rule, like CommentRequiredRule? >>>>> >>>>> *ApexReadabilityRule* >>>>> >>>>> The last one follows these criteria: >>>>> >>>>> - Lines of code in a method exceed 50 => add to violation count >>>>> - Nested if statements exceed more than 3 => add to violation >>>>> count >>>>> - Non trigger framework code exists in triggers => add to >>>>> violation count >>>>> >>>>> >>>>> I'm not sure how to do this last one. >>>>> >>>>> If you have any insight or feedback, let me know! >>>>> >>>>> Thank you. >>>>> >>>>> -- >>>>> Caleb Knox >>>>> >>>>> Endeveran >>>>> >>>>> ------------------------------------------------------------ >>>>> ------------------ >>>>> Check out the vibrant tech community on one of the world's most >>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>> _______________________________________________ >>>>> Pmd-devel mailing list >>>>> Pmd...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/pmd-devel >>>>> >>>>> >>>> >>> >>> >>> -- >>> Caleb Knox >>> >>> Endeveran >>> >> >> >> >> -- >> Caleb Knox >> >> Endeveran >> > > > > -- > Caleb Knox > > Endeveran > -- Caleb Knox Endeveran |
|
From: Caleb K. <cal...@en...> - 2017-07-14 17:18:54
|
Hey all, For PMD rule messages, can we somehow pass a parameter from a rule's Java class into the XML file? For example: "You had " + count + " repeated increment statements. This is above the threshold. Try instead: var += " + count + "." or something. Thanks much. -- Caleb Knox Endeveran |
|
From: Caleb K. <cal...@en...> - 2017-07-14 15:46:17
|
ApexOptimizeSoqlRule: > > looking at ASTSoqlExpression nodes and checking their parents for a List<> >> declaration > > This is actually good. Once you get that List<> declaration, you need to > check if it is being used in a foreach and if so flag it. > Actually, I am not sure how to do this, since ASTVariableDeclarationStatements doesn't have a getCanonicalQuery() method, or anything like that. On Fri, Jul 14, 2017 at 10:15 AM, Caleb Knox <cal...@en...> wrote: > ApexOptimizeSoqlRule: > > I was planning on looking at ASTForEachStatement nodes, checking the >> children for an ASTSoqlExpression node >> > I’m not sure I understand this… as far as I can tell, this is actually the >> desired code, so there is no point ins searching for it (you only want to >> add warnings for violations). >> > So, what I mean is that I'd like to check the ForEach to see if there is a > Soql expression within its declaration, because that's a direct child node. > Is that wrong? > > > ApexReadabilityRule: > > >> - Non trigger framework code exists in triggers => add to violation >> count >> >> I’m not sure what this would be. I’m not an Apex developer. Given proper >> samples I may assist you non the lest given I do know about it’s AST. >> > Triggers in Salesforce should not have any logic. The trigger should call > a handler. > > Thanks. > > > On Fri, Jul 14, 2017 at 9:14 AM, Caleb Knox <cal...@en...> > wrote: > >> Thanks for the insight. I'll get back to you about the ApexOptimizeSoql >> if I don't get it right soon. >> >> I can definitely add these rules to PMD, assuming my boss okays it. >> >> On Thu, Jul 13, 2017 at 6:48 PM, Juan Martín Sotuyo Dodero < >> jua...@gm...> wrote: >> >>> Hi Caleb, >>> >>> I’m glad to see you are making progress. Are you planning to contribute >>> these rules back to PMD? If so, it will be easier / we will be far more >>> willing to help you out. Just submit a PR for each in such case and we will >>> comment directly on your code. >>> >>> In the meantime, let me go in order: >>> ApexOptimizeSoqlRule: >>> >>> I was planning on looking at ASTForEachStatement nodes, checking the >>> children for an ASTSoqlExpression node >>> >>> I’m not sure I understand this… as far as I can tell, this is actually >>> the desired code, so there is no point ins searching for it (you only want >>> to add warnings for violations). >>> >>> looking at ASTSoqlExpression nodes and checking their parents for a >>> List<> declaration >>> >>> This is actually good. Once you get that List<> declaration, you need >>> to check if it is being used in a foreach and if so flag it. >>> ApexSingleSoqlResultRule >>> >>> I am checking ASTSoqlExpression nodes. If their parent nodes include a >>> try/catch, no violation. Else, add violation. >>> >>> 2 things here. I believe you already thought about this, but the try may >>> not be a direct parent but some other ancestor of the node, and you have to >>> actually check if the exception being caught is a QueryException >>> >>> I also check the ASTSoqlExpression for a LIMIT 1 since that’s how people >>> avoid the QueryException. >>> >>> This is a must to avoid flagging all SOQL. Given ASTSoqlExpression node >>> you can do node.getNode().getCanonicalQuery() to obtain the contents of >>> the expression being used. >>> ApexCommentRule >>> >>> can I just use a Java rule, like CommentRequiredRule? >>> >>> No you can’t. The Java rules use the Java Lexer and Parser, that only >>> recognize Java code. You need Apex specific rules to do this. >>> >>> Comments are not part of the AST, so doing this will not be trivial. I’m >>> not sure the Jorje parser provides access to comments at all, I’d have to >>> check the APIs and do some tests… >>> ApexReadabilityRule >>> >>> >>> - Lines of code in a method exceed 50 => add to violation count >>> >>> This is already implemented as apex-complexity/NcssMethodCount >>> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#NcssMethodCount>. >>> The default is 40 lines (without comments), but can be configured >>> >>> >>> - Nested if statements exceed more than 3 => add to violation count >>> >>> This is already implemented as apex-complexity/AvoidDeeplyNestedIfStmts >>> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#AvoidDeeplyNestedIfStmts>. >>> The default limit is exactly 3, you would have to set it to 4 to allow up >>> to 3. >>> >>> >>> - Non trigger framework code exists in triggers => add to violation >>> count >>> >>> I’m not sure what this would be. I’m not an Apex developer. Given proper >>> samples I may assist you non the lest given I do know about it’s AST. >>> >>> Regards, >>> >>> >>> On Thu, Jul 13, 2017 at 6:38 PM, Caleb Knox <cal...@en...> >>> wrote: >>> >>>> Hi there folks, >>>> >>>> I am trying to implement a few more rules for the project I've emailed >>>> about before, before we send it off to our customers. This is working with >>>> Salesforce/Apex classes. >>>> >>>> Here they are: >>>> >>>> >>>> >>>> *ApexOptimizeSoqlRule* >>>> Example: >>>> >>>> List<Account> acct = […]; >>>> for (Account a : acct ) { >>>> >>>> } >>>> >>>> // add violation >>>> >>>> ------------------------------------------- >>>> >>>> // optimized version >>>> >>>> for (Account acct : [Select … ] ) { >>>> >>>> } >>>> >>>> // all good >>>> >>>> For this rule, I was planning on looking at ASTForEachStatement nodes, >>>> checking the children for an ASTSoqlExpression node, as well as looking at >>>> ASTSoqlExpression nodes and checking their parents for a List<> >>>> declaration. However, what I have is not working, so I am wondering if my >>>> basic way of thinking about this rule is wrong, and if I should do >>>> something else. >>>> >>>> >>>> >>>> *ApexSingleSoqlResultRule* >>>> Example: >>>> >>>> Account acct = [Select Id From Account Where Name = ‘abc’ ]; >>>> >>>> // Get QueryException back if 0 or duplicate >>>> >>>> // People try to avoid by doing: >>>> >>>> List<Account> acct = [Select … LIMIT 1]; // bad practice to avoid dupes >>>> etc --> add violation >>>> >>>> if (acct.size() > 0 ) >>>> >>>> [...] >>>> >>>> >>>> -------------------------------------------- >>>> >>>> // Best practice is: >>>> >>>> try { >>>> Account acct = […]; >>>> } catch (QueryException q){ >>>> >>>> } >>>> >>>> For this rule, I am checking ASTSoqlExpression nodes. If their parent >>>> nodes include a try/catch, no violation. Else, add violation. >>>> >>>> I also check the ASTSoqlExpression for a LIMIT 1 since that's how >>>> people avoid the QueryException. But, I don't quite know how to do that. >>>> >>>> Maybe something like this? >>>> >>>> if(node.getNode().getQuery().toLowerCase().contains("list") && >>>> node.getNode().getQuery().toLowerCase().contains("limit >>>> 1")) >>>> >>>> >>>> *ApexCommentRule* >>>> >>>> The last two rules are related to readability. The first one looks at >>>> the following: >>>> >>>> - No class or method comments => add to violation count >>>> >>>> >>>> For this, can I just use a Java rule, like CommentRequiredRule? >>>> >>>> *ApexReadabilityRule* >>>> >>>> The last one follows these criteria: >>>> >>>> - Lines of code in a method exceed 50 => add to violation count >>>> - Nested if statements exceed more than 3 => add to violation count >>>> - Non trigger framework code exists in triggers => add to >>>> violation count >>>> >>>> >>>> I'm not sure how to do this last one. >>>> >>>> If you have any insight or feedback, let me know! >>>> >>>> Thank you. >>>> >>>> -- >>>> Caleb Knox >>>> >>>> Endeveran >>>> >>>> ------------------------------------------------------------ >>>> ------------------ >>>> Check out the vibrant tech community on one of the world's most >>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>> _______________________________________________ >>>> Pmd-devel mailing list >>>> Pmd...@li... >>>> https://lists.sourceforge.net/lists/listinfo/pmd-devel >>>> >>>> >>> >> >> >> -- >> Caleb Knox >> >> Endeveran >> > > > > -- > Caleb Knox > > Endeveran > -- Caleb Knox Endeveran |
|
From: Caleb K. <cal...@en...> - 2017-07-14 15:15:24
|
ApexOptimizeSoqlRule: I was planning on looking at ASTForEachStatement nodes, checking the > children for an ASTSoqlExpression node > I’m not sure I understand this… as far as I can tell, this is actually the > desired code, so there is no point ins searching for it (you only want to > add warnings for violations). > So, what I mean is that I'd like to check the ForEach to see if there is a Soql expression within its declaration, because that's a direct child node. Is that wrong? ApexReadabilityRule: > - Non trigger framework code exists in triggers => add to violation > count > > I’m not sure what this would be. I’m not an Apex developer. Given proper > samples I may assist you non the lest given I do know about it’s AST. > Triggers in Salesforce should not have any logic. The trigger should call a handler. Thanks. On Fri, Jul 14, 2017 at 9:14 AM, Caleb Knox <cal...@en...> wrote: > Thanks for the insight. I'll get back to you about the ApexOptimizeSoql if > I don't get it right soon. > > I can definitely add these rules to PMD, assuming my boss okays it. > > On Thu, Jul 13, 2017 at 6:48 PM, Juan Martín Sotuyo Dodero < > jua...@gm...> wrote: > >> Hi Caleb, >> >> I’m glad to see you are making progress. Are you planning to contribute >> these rules back to PMD? If so, it will be easier / we will be far more >> willing to help you out. Just submit a PR for each in such case and we will >> comment directly on your code. >> >> In the meantime, let me go in order: >> ApexOptimizeSoqlRule: >> >> I was planning on looking at ASTForEachStatement nodes, checking the >> children for an ASTSoqlExpression node >> >> I’m not sure I understand this… as far as I can tell, this is actually >> the desired code, so there is no point ins searching for it (you only want >> to add warnings for violations). >> >> looking at ASTSoqlExpression nodes and checking their parents for a >> List<> declaration >> >> This is actually good. Once you get that List<> declaration, you need to >> check if it is being used in a foreach and if so flag it. >> ApexSingleSoqlResultRule >> >> I am checking ASTSoqlExpression nodes. If their parent nodes include a >> try/catch, no violation. Else, add violation. >> >> 2 things here. I believe you already thought about this, but the try may >> not be a direct parent but some other ancestor of the node, and you have to >> actually check if the exception being caught is a QueryException >> >> I also check the ASTSoqlExpression for a LIMIT 1 since that’s how people >> avoid the QueryException. >> >> This is a must to avoid flagging all SOQL. Given ASTSoqlExpression node >> you can do node.getNode().getCanonicalQuery() to obtain the contents of >> the expression being used. >> ApexCommentRule >> >> can I just use a Java rule, like CommentRequiredRule? >> >> No you can’t. The Java rules use the Java Lexer and Parser, that only >> recognize Java code. You need Apex specific rules to do this. >> >> Comments are not part of the AST, so doing this will not be trivial. I’m >> not sure the Jorje parser provides access to comments at all, I’d have to >> check the APIs and do some tests… >> ApexReadabilityRule >> >> >> - Lines of code in a method exceed 50 => add to violation count >> >> This is already implemented as apex-complexity/NcssMethodCount >> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#NcssMethodCount>. >> The default is 40 lines (without comments), but can be configured >> >> >> - Nested if statements exceed more than 3 => add to violation count >> >> This is already implemented as apex-complexity/AvoidDeeplyNestedIfStmts >> <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#AvoidDeeplyNestedIfStmts>. >> The default limit is exactly 3, you would have to set it to 4 to allow up >> to 3. >> >> >> - Non trigger framework code exists in triggers => add to violation >> count >> >> I’m not sure what this would be. I’m not an Apex developer. Given proper >> samples I may assist you non the lest given I do know about it’s AST. >> >> Regards, >> >> >> On Thu, Jul 13, 2017 at 6:38 PM, Caleb Knox <cal...@en...> >> wrote: >> >>> Hi there folks, >>> >>> I am trying to implement a few more rules for the project I've emailed >>> about before, before we send it off to our customers. This is working with >>> Salesforce/Apex classes. >>> >>> Here they are: >>> >>> >>> >>> *ApexOptimizeSoqlRule* >>> Example: >>> >>> List<Account> acct = […]; >>> for (Account a : acct ) { >>> >>> } >>> >>> // add violation >>> >>> ------------------------------------------- >>> >>> // optimized version >>> >>> for (Account acct : [Select … ] ) { >>> >>> } >>> >>> // all good >>> >>> For this rule, I was planning on looking at ASTForEachStatement nodes, >>> checking the children for an ASTSoqlExpression node, as well as looking at >>> ASTSoqlExpression nodes and checking their parents for a List<> >>> declaration. However, what I have is not working, so I am wondering if my >>> basic way of thinking about this rule is wrong, and if I should do >>> something else. >>> >>> >>> >>> *ApexSingleSoqlResultRule* >>> Example: >>> >>> Account acct = [Select Id From Account Where Name = ‘abc’ ]; >>> >>> // Get QueryException back if 0 or duplicate >>> >>> // People try to avoid by doing: >>> >>> List<Account> acct = [Select … LIMIT 1]; // bad practice to avoid dupes >>> etc --> add violation >>> >>> if (acct.size() > 0 ) >>> >>> [...] >>> >>> >>> -------------------------------------------- >>> >>> // Best practice is: >>> >>> try { >>> Account acct = […]; >>> } catch (QueryException q){ >>> >>> } >>> >>> For this rule, I am checking ASTSoqlExpression nodes. If their parent >>> nodes include a try/catch, no violation. Else, add violation. >>> >>> I also check the ASTSoqlExpression for a LIMIT 1 since that's how people >>> avoid the QueryException. But, I don't quite know how to do that. >>> >>> Maybe something like this? >>> >>> if(node.getNode().getQuery().toLowerCase().contains("list") && >>> node.getNode().getQuery().toLowerCase().contains("limit >>> 1")) >>> >>> >>> *ApexCommentRule* >>> >>> The last two rules are related to readability. The first one looks at >>> the following: >>> >>> - No class or method comments => add to violation count >>> >>> >>> For this, can I just use a Java rule, like CommentRequiredRule? >>> >>> *ApexReadabilityRule* >>> >>> The last one follows these criteria: >>> >>> - Lines of code in a method exceed 50 => add to violation count >>> - Nested if statements exceed more than 3 => add to violation count >>> - Non trigger framework code exists in triggers => add to >>> violation count >>> >>> >>> I'm not sure how to do this last one. >>> >>> If you have any insight or feedback, let me know! >>> >>> Thank you. >>> >>> -- >>> Caleb Knox >>> >>> Endeveran >>> >>> ------------------------------------------------------------ >>> ------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>> _______________________________________________ >>> Pmd-devel mailing list >>> Pmd...@li... >>> https://lists.sourceforge.net/lists/listinfo/pmd-devel >>> >>> >> > > > -- > Caleb Knox > > Endeveran > -- Caleb Knox Endeveran |
|
From: Caleb K. <cal...@en...> - 2017-07-14 14:14:18
|
Thanks for the insight. I'll get back to you about the ApexOptimizeSoql if I don't get it right soon. I can definitely add these rules to PMD, assuming my boss okays it. On Thu, Jul 13, 2017 at 6:48 PM, Juan Martín Sotuyo Dodero < jua...@gm...> wrote: > Hi Caleb, > > I’m glad to see you are making progress. Are you planning to contribute > these rules back to PMD? If so, it will be easier / we will be far more > willing to help you out. Just submit a PR for each in such case and we will > comment directly on your code. > > In the meantime, let me go in order: > ApexOptimizeSoqlRule: > > I was planning on looking at ASTForEachStatement nodes, checking the > children for an ASTSoqlExpression node > > I’m not sure I understand this… as far as I can tell, this is actually the > desired code, so there is no point ins searching for it (you only want to > add warnings for violations). > > looking at ASTSoqlExpression nodes and checking their parents for a List<> > declaration > > This is actually good. Once you get that List<> declaration, you need to > check if it is being used in a foreach and if so flag it. > ApexSingleSoqlResultRule > > I am checking ASTSoqlExpression nodes. If their parent nodes include a > try/catch, no violation. Else, add violation. > > 2 things here. I believe you already thought about this, but the try may > not be a direct parent but some other ancestor of the node, and you have to > actually check if the exception being caught is a QueryException > > I also check the ASTSoqlExpression for a LIMIT 1 since that’s how people > avoid the QueryException. > > This is a must to avoid flagging all SOQL. Given ASTSoqlExpression node > you can do node.getNode().getCanonicalQuery() to obtain the contents of > the expression being used. > ApexCommentRule > > can I just use a Java rule, like CommentRequiredRule? > > No you can’t. The Java rules use the Java Lexer and Parser, that only > recognize Java code. You need Apex specific rules to do this. > > Comments are not part of the AST, so doing this will not be trivial. I’m > not sure the Jorje parser provides access to comments at all, I’d have to > check the APIs and do some tests… > ApexReadabilityRule > > > - Lines of code in a method exceed 50 => add to violation count > > This is already implemented as apex-complexity/NcssMethodCount > <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#NcssMethodCount>. > The default is 40 lines (without comments), but can be configured > > > - Nested if statements exceed more than 3 => add to violation count > > This is already implemented as apex-complexity/AvoidDeeplyNestedIfStmts > <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#AvoidDeeplyNestedIfStmts>. > The default limit is exactly 3, you would have to set it to 4 to allow up > to 3. > > > - Non trigger framework code exists in triggers => add to violation > count > > I’m not sure what this would be. I’m not an Apex developer. Given proper > samples I may assist you non the lest given I do know about it’s AST. > > Regards, > > > On Thu, Jul 13, 2017 at 6:38 PM, Caleb Knox <cal...@en...> > wrote: > >> Hi there folks, >> >> I am trying to implement a few more rules for the project I've emailed >> about before, before we send it off to our customers. This is working with >> Salesforce/Apex classes. >> >> Here they are: >> >> >> >> *ApexOptimizeSoqlRule* >> Example: >> >> List<Account> acct = […]; >> for (Account a : acct ) { >> >> } >> >> // add violation >> >> ------------------------------------------- >> >> // optimized version >> >> for (Account acct : [Select … ] ) { >> >> } >> >> // all good >> >> For this rule, I was planning on looking at ASTForEachStatement nodes, >> checking the children for an ASTSoqlExpression node, as well as looking at >> ASTSoqlExpression nodes and checking their parents for a List<> >> declaration. However, what I have is not working, so I am wondering if my >> basic way of thinking about this rule is wrong, and if I should do >> something else. >> >> >> >> *ApexSingleSoqlResultRule* >> Example: >> >> Account acct = [Select Id From Account Where Name = ‘abc’ ]; >> >> // Get QueryException back if 0 or duplicate >> >> // People try to avoid by doing: >> >> List<Account> acct = [Select … LIMIT 1]; // bad practice to avoid dupes >> etc --> add violation >> >> if (acct.size() > 0 ) >> >> [...] >> >> >> -------------------------------------------- >> >> // Best practice is: >> >> try { >> Account acct = […]; >> } catch (QueryException q){ >> >> } >> >> For this rule, I am checking ASTSoqlExpression nodes. If their parent >> nodes include a try/catch, no violation. Else, add violation. >> >> I also check the ASTSoqlExpression for a LIMIT 1 since that's how people >> avoid the QueryException. But, I don't quite know how to do that. >> >> Maybe something like this? >> >> if(node.getNode().getQuery().toLowerCase().contains("list") && >> node.getNode().getQuery().toLowerCase().contains("limit >> 1")) >> >> >> *ApexCommentRule* >> >> The last two rules are related to readability. The first one looks at the >> following: >> >> - No class or method comments => add to violation count >> >> >> For this, can I just use a Java rule, like CommentRequiredRule? >> >> *ApexReadabilityRule* >> >> The last one follows these criteria: >> >> - Lines of code in a method exceed 50 => add to violation count >> - Nested if statements exceed more than 3 => add to violation count >> - Non trigger framework code exists in triggers => add to violation >> count >> >> >> I'm not sure how to do this last one. >> >> If you have any insight or feedback, let me know! >> >> Thank you. >> >> -- >> Caleb Knox >> >> Endeveran >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Pmd-devel mailing list >> Pmd...@li... >> https://lists.sourceforge.net/lists/listinfo/pmd-devel >> >> > -- Caleb Knox Endeveran |
|
From: Juan M. S. D. <jua...@gm...> - 2017-07-13 23:48:09
|
Hi Caleb, I’m glad to see you are making progress. Are you planning to contribute these rules back to PMD? If so, it will be easier / we will be far more willing to help you out. Just submit a PR for each in such case and we will comment directly on your code. In the meantime, let me go in order: ApexOptimizeSoqlRule: I was planning on looking at ASTForEachStatement nodes, checking the children for an ASTSoqlExpression node I’m not sure I understand this… as far as I can tell, this is actually the desired code, so there is no point ins searching for it (you only want to add warnings for violations). looking at ASTSoqlExpression nodes and checking their parents for a List<> declaration This is actually good. Once you get that List<> declaration, you need to check if it is being used in a foreach and if so flag it. ApexSingleSoqlResultRule I am checking ASTSoqlExpression nodes. If their parent nodes include a try/catch, no violation. Else, add violation. 2 things here. I believe you already thought about this, but the try may not be a direct parent but some other ancestor of the node, and you have to actually check if the exception being caught is a QueryException I also check the ASTSoqlExpression for a LIMIT 1 since that’s how people avoid the QueryException. This is a must to avoid flagging all SOQL. Given ASTSoqlExpression node you can do node.getNode().getCanonicalQuery() to obtain the contents of the expression being used. ApexCommentRule can I just use a Java rule, like CommentRequiredRule? No you can’t. The Java rules use the Java Lexer and Parser, that only recognize Java code. You need Apex specific rules to do this. Comments are not part of the AST, so doing this will not be trivial. I’m not sure the Jorje parser provides access to comments at all, I’d have to check the APIs and do some tests… ApexReadabilityRule - Lines of code in a method exceed 50 => add to violation count This is already implemented as apex-complexity/NcssMethodCount <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#NcssMethodCount>. The default is 40 lines (without comments), but can be configured - Nested if statements exceed more than 3 => add to violation count This is already implemented as apex-complexity/AvoidDeeplyNestedIfStmts <https://pmd.github.io/pmd-5.8.1/pmd-apex/rules/apex/complexity.html#AvoidDeeplyNestedIfStmts>. The default limit is exactly 3, you would have to set it to 4 to allow up to 3. - Non trigger framework code exists in triggers => add to violation count I’m not sure what this would be. I’m not an Apex developer. Given proper samples I may assist you non the lest given I do know about it’s AST. Regards, On Thu, Jul 13, 2017 at 6:38 PM, Caleb Knox <cal...@en...> wrote: > Hi there folks, > > I am trying to implement a few more rules for the project I've emailed > about before, before we send it off to our customers. This is working with > Salesforce/Apex classes. > > Here they are: > > > > *ApexOptimizeSoqlRule* > Example: > > List<Account> acct = […]; > for (Account a : acct ) { > > } > > // add violation > > ------------------------------------------- > > // optimized version > > for (Account acct : [Select … ] ) { > > } > > // all good > > For this rule, I was planning on looking at ASTForEachStatement nodes, > checking the children for an ASTSoqlExpression node, as well as looking at > ASTSoqlExpression nodes and checking their parents for a List<> > declaration. However, what I have is not working, so I am wondering if my > basic way of thinking about this rule is wrong, and if I should do > something else. > > > > *ApexSingleSoqlResultRule* > Example: > > Account acct = [Select Id From Account Where Name = ‘abc’ ]; > > // Get QueryException back if 0 or duplicate > > // People try to avoid by doing: > > List<Account> acct = [Select … LIMIT 1]; // bad practice to avoid dupes > etc --> add violation > > if (acct.size() > 0 ) > > [...] > > > -------------------------------------------- > > // Best practice is: > > try { > Account acct = […]; > } catch (QueryException q){ > > } > > For this rule, I am checking ASTSoqlExpression nodes. If their parent > nodes include a try/catch, no violation. Else, add violation. > > I also check the ASTSoqlExpression for a LIMIT 1 since that's how people > avoid the QueryException. But, I don't quite know how to do that. > > Maybe something like this? > > if(node.getNode().getQuery().toLowerCase().contains("list") && > node.getNode().getQuery().toLowerCase().contains("limit > 1")) > > > *ApexCommentRule* > > The last two rules are related to readability. The first one looks at the > following: > > - No class or method comments => add to violation count > > > For this, can I just use a Java rule, like CommentRequiredRule? > > *ApexReadabilityRule* > > The last one follows these criteria: > > - Lines of code in a method exceed 50 => add to violation count > - Nested if statements exceed more than 3 => add to violation count > - Non trigger framework code exists in triggers => add to violation > count > > > I'm not sure how to do this last one. > > If you have any insight or feedback, let me know! > > Thank you. > > -- > Caleb Knox > > Endeveran > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Pmd-devel mailing list > Pmd...@li... > https://lists.sourceforge.net/lists/listinfo/pmd-devel > > |
|
From: Caleb K. <cal...@en...> - 2017-07-13 22:09:55
|
Hi there folks,
I am trying to implement a few more rules for the project I've emailed
about before, before we send it off to our customers. This is working with
Salesforce/Apex classes.
Here they are:
*ApexOptimizeSoqlRule*
Example:
List<Account> acct = […];
for (Account a : acct ) {
}
// add violation
-------------------------------------------
// optimized version
for (Account acct : [Select … ] ) {
}
// all good
For this rule, I was planning on looking at ASTForEachStatement nodes,
checking the children for an ASTSoqlExpression node, as well as looking at
ASTSoqlExpression nodes and checking their parents for a List<>
declaration. However, what I have is not working, so I am wondering if my
basic way of thinking about this rule is wrong, and if I should do
something else.
*ApexSingleSoqlResultRule*
Example:
Account acct = [Select Id From Account Where Name = ‘abc’ ];
// Get QueryException back if 0 or duplicate
// People try to avoid by doing:
List<Account> acct = [Select … LIMIT 1]; // bad practice to avoid dupes etc
--> add violation
if (acct.size() > 0 )
[...]
--------------------------------------------
// Best practice is:
try {
Account acct = […];
} catch (QueryException q){
}
For this rule, I am checking ASTSoqlExpression nodes. If their parent nodes
include a try/catch, no violation. Else, add violation.
I also check the ASTSoqlExpression for a LIMIT 1 since that's how people
avoid the QueryException. But, I don't quite know how to do that.
Maybe something like this?
if(node.getNode().getQuery().toLowerCase().contains("list") &&
node.getNode().getQuery().toLowerCase().contains("limit 1"))
*ApexCommentRule*
The last two rules are related to readability. The first one looks at the
following:
- No class or method comments => add to violation count
For this, can I just use a Java rule, like CommentRequiredRule?
*ApexReadabilityRule*
The last one follows these criteria:
- Lines of code in a method exceed 50 => add to violation count
- Nested if statements exceed more than 3 => add to violation count
- Non trigger framework code exists in triggers => add to violation
count
I'm not sure how to do this last one.
If you have any insight or feedback, let me know!
Thank you.
--
Caleb Knox
Endeveran
|