New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codenarc integration #517
Codenarc integration #517
Conversation
6f05f1b
to
2f1d026
Compare
70a2257
to
04aa74d
Compare
f8d6b45
to
254b16a
Compare
f9b633a
to
18ff652
Compare
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
18ff652
to
3ae4036
Compare
83d1469
to
a421c61
Compare
19d8633
to
7ee3e84
Compare
7528866
to
8146b94
Compare
applications/accounting/groovyScripts/admin/ListInvoiceItemTypesGlAccount.groovy
Outdated
Show resolved
Hide resolved
bc76f88
to
c80896e
Compare
…tarter Ruleset (OFBIZ-11167) Customize SpaceAroundMapEntryColon rule to respect community opinion Map in OFBiz groovy should respect [key: value] syntax Add LineLength parameter to 150 length Remove TrailingComma codenarc rule : Check whether list and map literals contain optional trailing comma. Remove DuplicateString/NumberLiteral codenarc rules : since we are not using OOP in groovy, these rule generate lots of unwanted issue. Comment with TODO AbcMetric CodeNarc rule : Checks the ABC size metric for methods/classes. A method (or "closure field") with an ABC score greater than the maxMethodAbcScore property (60) causes a violation. Likewise, a class that has an (average method) ABC score greater than the maxClassAverageMethodAbcScore property (60) causes a violation. Comment with TODO NestedBlockDepth CodeNarc rule : Checks for blocks or closures nested more than maxNestedBlockDepth (5) levels deep. This need discussion and investigation about the impact on groovyScripts Remove FactoryMethodName codenarc rules : A factory method is a method that creates objects, and they are typically named either buildFoo(), makeFoo(), or createFoo(). This rule enforces that only one naming convention is used. It defaults to makeFoo(), but that can be changed using the property 'regex'. This kind of control is not suitable in groovy scripting (not OOP) Comment ImplicitClosureParameter codenarc rules : Checks for the implicit it closure parameter being used. Also checks if an explicit it parameter has been specified. Commented since in certain cases is easy to read. To be discussed. Comment CyclomaticComplexity codenarc rules : Checks the cyclomatic complexity for methods/classes.A method (or "closure field") with a cyclomatic complexity value greater than the maxMethodComplexity property (20) causes a violation. Likewise, a class that has an (average method) cyclomatic complexityvalue greater than the maxClassAverageMethodComplexity property (20) causes a violation. Commented since some scripts require serious refactoring. Comment CatchException codenarc rules : Catching Exception is often too broad or general. It should usually be restricted to framework or infrastructure code, rather than application code. Commented since we need to discuss about execption CatchException for scripting (allow global Exception catching) Comment ParameterReassignment codenarc rules : Checks for a method or closure parameter being reassigned to a new value within the body of the method/closure, which is a confusing and questionable practice. Use a temporary variable instead. Commented since we need to discuss about execption CatchException for scripting (allow global Exception catching) Remove DuplicateList/MapLiterals codenarc rules : Not sure we want that Code containing duplicate List literals should contains constants (no class for groovyScripts) Remove JavaIoPackageAccess codenarc rules : This rule reports violations of the Enterprise JavaBeans specification by using the java.io package to access files or the file system. Applying this rule imply removing all access to file system. Remove instanceof codenarc rules : This rule checks for use of the instanceof operator. Use the ignoreTypeNames property to configure ignored type names. Those should be avoided and replaced using polymorphism. In our case, main issue are about testing Map / List types. Comment MethodSize codenarc rules : Checks if the size of a method exceeds the number of lines specified by the maxLines property (100). This will be implemented later, such needs method extraction. Comment ParameterCount codenarc rules : Checks if the number of parameters in method/constructor exceeds the number of parameters specified by the maxParameters property. Remove codenarc ClassJavadoc rules : Makes sure each class and interface definition is preceded by javadoc. Enum definitions are not checked, due to strange behavior in the Groovy AST.
An assignment operator (=) was used in a conditional test. This is usually a typo, and the comparison operator (==) was intended. Not Tested in this case.
…ments where the assert boolean condition expression is a constant or literal value.
…nt or an exception is thrown. If code appears after one of these statements then it will never be executed and can be safely deleted.
…not be caught and ignored (swallowed).
…d serve no purpose.
…low multi referencing the same object. Fix codenarc UnnecessaryObjectReferences rule : Violations are triggered when an excessive set of consecutive statements all reference the same variable. This can be made more readable by using a with or identity block.
applications/order/groovyScripts/shoppinglist/ShoppingListServices.groovy
Show resolved
Hide resolved
applications/product/groovyScripts/facility/facility/CountFacilityInventoryByProduct.groovy
Show resolved
Hide resolved
applications/product/groovyScripts/facility/facility/CountFacilityInventoryByProduct.groovy
Show resolved
Hide resolved
SonarCloud Quality Gate failed. 1 Bug No Coverage information |
@gilPts, It looks like we are getting close to completing this review :) For the conflicting files, BalanceSheet.groovy has changed quite significantly since the CodeNarc Integration work began. Would it be worth copying the latest BalanceSheet.groovy from trunk and then applying the CodeNarc cleanup. I'm not sure what would be the cleanest way to do this and keep git happy? Any Git experts on hand to comment? Similarly, the bug raised by SonarCloud was resolved in trunk for file, |
@nmalin - are you happy with the response to your questions in the review tracker, here - https://cwiki.apache.org/confluence/display/OFBIZ/Codenarc+integration+review+tracker ? If so, please could you mark the review results for MarketingCampaignReport.groovy, TrackingCodeReport.groovy and LookupBulkAddProducts.groovy as passed. |
@JacquesLeRoux , in the tracker (https://cwiki.apache.org/confluence/display/OFBIZ/Codenarc+integration+review+tracker) you mentioned work was needed. What sort of changes are needed, or was the WORK_NEEDED review result put there to highlight a possible conflict? |
@danwatford , it's possible conflicts related to change for https://issues.apache.org/jira/browse/OFBIZ-12793 "Cannot add a new geo point to a facility" |
Good news indeed then since, assuming Nicolas' questions have been resolved, that means the only outstanding things left on this PR is to resolve the merge conflicts, which includes FacilityGeoServices.groovy. @JacquesLeRoux I think it is ok to mark FacilityGeoServices.groovy as PASSED since merge conflicts affect more that just that single file. Or alternatively we should mark all the conflicted files as NEEDS_WORK to highlight that some action still remains to be done? |
I changed to "passed", since indeed anyway conflicts will show and will need to be fixed. |
Hi @gilPts , I just tried a
In the CodeNarc report I see there are 448 Priority 2 issues and 4396 Priority 3 issues listed. It seems unlikely that we will be able to address all of these quickly. Do you know if CodeNarc can be configured with a threshold of permitted Priority 2 and Priority 3 issues that would allow the build to proceed? This is approach we use with Checkstyle. If so, then over time we could gradually reduce the permitted number of issues until we hopefully reach zero, improving code 'hygiene' over time, but also getting CodeNarc integration in place as soon as possible. |
Hello, |
About BalanceSheet.groovy and others framework groovy file, I can rebase this branch onto trunk and process the files that are detected by codenarc, then push in another pull request listing the files I worked on. |
Ah, I think the plugins explains it. The first file reported is Unless we have a way to exclude, plugins will end up getting included in checks. Having a threshold might be really useful for integrators who have written their own groovy scripts but don't want to or can't reach zero CodeNarc issues at this time. |
Sounds good to me |
I did not found yet a way to exclude plugins, if someone has a guess, it could be nice :) |
If we suppose it's (only) about integration (GH actions and BB) we could not load the plugins when checking? |
I'm not sure. Even if we build ofbiz-framework without the plugins initially. When we subsequently pull the plugins, the 'check' gradle tasks will run again. It would also make the build process more complicated. I think easiest will be to have a threshold as this will give integrators a way to allow their own plugins/modifications to pass checking without forcing them to immediately fix every issue that CodeNarc might report. |
I was actually wondering if Codenarc was providing threshold, according to* it is. |
The Gradle CodeNarc plugin has similar settings to set thresholds: |
I just pushed #618 for the last reviews. |
Closing as a rebased version of this PR's branch was handled through #618 . |
Implemented: add codenarc and fix first basic rules.
(OFBIZ-11167)