You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unified Salesforce ruleset incl. Apex, Visualforce & XML Metadata #3846
I'm not sure if this is the proper way to file a request like this, but I'm filing this minimally to seed additional discussion after a chat with @rsoesemann. In addition to the more first-class PMD Apex and PMD Visualforce rules, there are other Salesforce-specific rules which are based on XML XPath for validation of Salesforce XML-based metadata files. Currently these are informally accumulating here:
but for the Salesforce developer community that uses PMD, it would be wonderful to have a centralized rule repository that includes these rules as well as those for Apex and Visualforce.
It seems like perhaps the documentation for PMD Apex and PMD Visualforce might be reorganized slightly in the main documentationRule Reference section to include a new section for Salesforce XML Rules alongside Salesforce Apex Rules (notice the rename from Apex Rules so that they group together in the left nav) and Salesforce Visualforce Rules. It would be even better if these could be nested under Salesforce Rules with children of Apex Rules, Visualforce Rules, and XML Rules but I'm assuming that needs to be a flat list. Anyway, the new Salesforce XML Rules would include the globally-applicable XML XPath-based rules that pretty much any project would use as well as documentation on how to construct new XML XPath rules for other metadata based on project-specific requirements.
@adangel and @oowekyala I fully support this idea and request. The current enhancements that allow to not only scan Apex and Visualforce in Salesforce but also the hundreds of XML dialects for Salesforce metadata are a game-changer and people are really excited about it.
@SCWells72, I, and others would love to now provide a ton of such XML rules in a ruleset hosted in this repo.
The best would be to have a single Salesforce ruleset containing all rules for Apex, Visualforce, and XML but as I understand the structure. Documentation and other things are generated based on top of the languages where Apex and Visualforce are separate languages and Salesforce XML is not a language at all.
Would it be doable (without breaking the concept) to add a section to XML like the existing "Error Prone"? Something like "Salesforce Metadata"?
I can see how this feature request would be useful, and I support it. There is currently no precedent for publishing multi-language rulesets directly from PMD though, so we have to break new ground.
Maybe a nice way to do this would be to create a new module pmd-salesforce, which pulls in pmd-xml, pmd-apex and pmd-visualforce, which has its own rulesets/salesforce/quickstart.xml? I expect this would show up in your screenshot as a new "Salesforce Rules" dropdown (above "Salesforce VisualForce Rules"), with a ruleset index like for other languages. The documentation generator might have to be slightly updated, I'm not sure about this. One advantage is that salesforce users would only need to pull in one language module to get all the relevant ones.
@oowekyala this would be the optimum. Would that also work with the Salesforce-specific XML rules? As far as I understand as they are not a separate language such a multi-language auto-pull from the doc engine would ignore them.
Or do you propose to also add a "Salesforce XML" section in the XML rules?
Would that also work with the Salesforce-specific XML rules? As far as I understand as they are not a separate language such a multi-language auto-pull from the doc engine would ignore them.
So I think we would define a new XML language module for "Salesforce XML". Now we could put this in the new pmd-salesforce module, or the current pmd-xml module. I think it probably makes more sense to put it in the new module, since these rules are probably better discoverable from the salesforce module. The documentation generator would produce a page for "Salesforce XML" rules, and most likely a page for the ruleset index that contains the saleforce quickstart.xml (I'm not sure this will work out of the box, but it shouldn't be too much work)
Hi, @oowekyala. Are there any existing precedents for "meta" modules like this that aggregate multiple existing modules?
changed the title [-]Provide centralized examples of XML XPath rules for Salesforce XML metadata files[/-][+]Doc site shows central Salesforce ruleset incl. Apex, Visualforce and XML Custom rules for Metadata[/+]on Mar 17, 2022
changed the title [-]Doc site shows central Salesforce ruleset incl. Apex, Visualforce and XML Custom rules for Metadata[/-][+]Doc site shows central Salesforce ruleset incl. Apex, Visualforce & XML Metadata[/+]on Mar 17, 2022
In the "Salesforce Realm", one deals with apex code, visualforce code and some XML dialects
Grouping them together seems to be a natural fit
There are new rules you want to contribute and share and distribute
Here are my 2 cents:
I also like the idea of grouping the languages apex and vf into a own module. We have done something similar (although more complex and in the end different...) with scala (see folder pmd-scala-modules). The structuring can happen on two layers: filesystem layer - so how we organize the source code. That means, it will be backwards compatible in terms of maven coordinates, if we create a folder "pmd-salesforce" and move into it the currently existing folders "pmd-apex", "pmd-apex-jorje", "pmd-visualforce". We could keep the groupId/artifactId the same to have it compatible. The only downside I see is the not working mapping from groupId/artifactId to source code: Given a groupId="net.sourceforge.pmd", it is sometimes helpful to deduce from the artifactId the actual location of the sourcecode in the repository. The extra folder "pmd-salesforce" would not be presented and might cause confusion. That can only be fixed with breaking compatibility.
Having the new rules/rulesets as part of the main repository applies the exactly same release cycle to them. In the past @oowekyala and I discussed some idea around a semi-official repo like "pmd-contributions", which could contain additional rules and rulesets and even languages. Since it is a different repository, it could use a different release cycle. However, there are open questions around how to actually use and distribute the artifacts from the repo. Also generating a documentation site would be useful as well. Without more work done on this side, the artifacts would need to be copied manually into your local pmd-bin-xxx/lib folder (or added as maven dependency). There are also questions about who maintains this repo. Also the compatibility needs to be considered: e.g. which version of pmd-contrib works together with which version of pmd; same question arise since we moved out the pmd-designer (formerly module pmd-ui).
Taking a step back and looking at the rules/rulesets we ship with the "official" pmd distribution: These rules are part of main repo, are maintained as part of the "default" work we do. The rules are considered to be general enough, that they are useful for everybody using the language. Looking from this angle, then we definitively should integrate these rules into the official distribution and into the main repo (given that the rules you want to add are useful for the majority of users).
To explain, how the current documentation is generated (this is done by the module pmd-doc, so can be changed - it doesn't need to stay the way it is now):
pmd-doc depends on all other modules
it scans for the registered languages
each language produces a own section under "Rule Reference"
for each language, each registered ruleset is rendered
There can be more than one language in one maven module. E.g. pmd-xml produces the sections "XML Rules", "XSL Rules", and "Maven POM Rules". Since we register 3 "languages".
That's all. The grouping currently only happens based on language. To automate the grouping of apex+visualforce+salesforce-xml, this information needs to be added somewhere (maybe we just hardcode it in pmd-doc).
Next steps from my point of view:
Create a new top-level folder "pmd-salesforce-xml". This maven module depends on pmd-xml and registers a language "Salesforce XML Metadata". This will then appear in the doc as "Salesforce XML Metadata Rules". This module contains the rules for XML Metadata.
Question: Where to place the combined ruleset, which contains rules from apex, visualforce and xml? For now, we could place it as well under pmd-salesforce-xml? Or we create a module "pmd-saleforce-rules"?
If we decide to drop the direct mapping from artifactId to source folder (like we did in the past for the scala modules), then: create a folder pmd-salesforce, move pmd-apex, pmd-apex-jorje, pmd-visualforce, pmd-salesforce-xml into it. Note: the folder pmd-salesforce would be just a folder, not a maven module. It is just to structure the main repository a bit.
Adjust rule documentation generator (living in pmd-doc) to group the rules/rulesets from the salesforce realm under one place.
Combining Apex and Visualforce alone is not enough. The XML metadata rules also need to go into such a unified Salesforce rulesset
I honestly see no need for an extra repo or release cycle. The current release cadence is often and more than perfect for me and other contributors to add Custom XML rules to the Salesforce ruleset
Regarding documentation and testing I had hoped that Custom XPath rules are MUCH easier to handle. Everything is contained in the node. So anyone contributing a new rule creates a PR on this single rulesset.xml.
I see more than ONE Salesforce metadata XML dialect coming in the near future. @aidan-harding already investigated into writing a parser for Salesforce Flow XML in [xml] New language to detect issues in Salesforce Flow #3413. The current XML implementation is good enough for the most XML metadata formats but we should plan for a structure like
changed the title [-]Doc site shows central Salesforce ruleset incl. Apex, Visualforce & XML Metadata[/-][+]Unified Salesforce ruleset incl. Apex, Visualforce & XML Metadata[/+]on Mar 17, 2022
@rsoesemann the only thing I don't necessarily agree with is the need for a separate language/AST for flow. Flow documents already adhere to the common XSD for Salesforce metadata files. If we're thinking that XPath-based XML rules are sufficient for those other document types--and XPath is obviously EXTREMELY flexible for criteria-based node selection--then they should work just as well for those documents. Another language that is effectively a proxy for the existing XML AST seems superfluous. I think we should just have Apex, Visualforce, and XML (all under Salesforce, of course) for now. The only others that might be added in time would be Aura and LWC, and those are already well-covered by custom ESLint rules from Salesforce anyway.
@rsoesemann, sure. I was responding to the comment in the linked issue about adding a new language specifically for Flow and the corresponding escalation of flow metadata as a peer to "other" metadata. In reality, all Salesforce XML metadata conforms to a single metadata.xsd (which I actually already bundle with IC2 to provide XML validation, code completion, etc.). A Flow-specific AST would be very close to isomorphic with the existing XML AST for the same document, and therefore the expressed XPath rules would be virtually identical. That's why I termed such work superfluous. Perhaps @aidan-harding has found use cases that aren't (easily) supported by the XML AST?
I just think if you start to pick apart the various XML file subtypes, you're going to end up with unnecessary and potentially confusing bifurcation. I would start with "Salesforce XML" as a peer to "Salesforce Apex" and "Salesforce Visualforce" and see if a natural splintering of distinct subtypes occurs as people use it.
Regarding documentation and testing I had hoped that Custom XPath rules are MUCH easier to handle. Everything is contained in the node. So anyone contributing a new rule creates a PR on this single rulesset.xml.
Documentation is indeed inside the a ruleset-xml file. Note, we'll still have the different categories, so there is no single ruleset.
The tests are still mandatory - we try to not accept rule contributions without tests...
For the combined ruleset (the quickstart.xml or the "unified Salesforce ruleset"), tests are not necessary, because this ruleset is expected to only contain rule references and not rules.
I think, we agreed that the restructuring of the salesforce relates modules in pmd under a same common parent directory (probably pmd-salesforce) and creating a pmd-salesforce-xml module is a good idea. But (speaking now for @oowekyala and myself) we as maintainers won't have the capacity to do this - we are relying on contributions.
The following steps should get the assignee (TBD) started:
(base your work off of the latest master)
create a new directory pmd-salesforce-modules, move pmd-apex, pmd-apex-jorje, and pmd-visualforce into there; adjust relative paths in the pom.xml files
create a new maven module pmd-salesforce-xml inside pmd-salesforce-modules
this has a dependency on pmd-xml
create an implementation of BaseLanguageModule for SalesForce Flow (use eg PomLanguageModule as template)
Please keep in mind the packaging conventions: classes for the language should live in net.sourceforge.pmd.lang.flow and subpackages
under pmd-salesforce-xml/src/main/resources, create categories for the flow language (eg category/flow/codestyle.xml), add a couple of rules (and tests, in src/test/java)
create a new module pmd-salesforce inside pmd-salesforce-modules
this has a dependency on pmd-apex, pmd-visualforce, pmd-salesforce-xml
create a new ruleset, eg rulesets/salesforce/quickstart.xml, with references to the most useful rules for apex, flow, and visualforce.
submit a PR and wait for reviews
Whoever decides to take this on, please request that we assign you to this issue. If you're stuck, open a draft PR and ask for specific guidance (please don't overload this ticket)
@SCWells72 you seem interested, would you have capacity for this? Otherwise @rsoesemann please help with finding an assignee
@rsoesemann I would certainly love to see it done but between work and my kids back in school, I can't imagine finding the free time anytime in the near future. Sorry...
@SCWells72@jonny-harte I know I'm late to the party here, but this is something I'm actively working on. I had an issue with getting the filename in 7 and after a bit of back and forth, @jsotuyod mentioned the need for a contribution for Salesforce Metadata. I'm happy to take that on myself, as it's something I'm grinding on anyways. I'm a little green when it comes to contributing so any guidance would be appreciated (case in point, I attempted to build PMD last night locally and ran into some security issues with the Maven validate.) Should I start a discussion thread for this or something?
Activity
rsoesemann commentedon Mar 16, 2022
@adangel and @oowekyala I fully support this idea and request. The current enhancements that allow to not only scan Apex and Visualforce in Salesforce but also the hundreds of XML dialects for Salesforce metadata are a game-changer and people are really excited about it.
@SCWells72, I, and others would love to now provide a ton of such XML rules in a ruleset hosted in this repo.
The best would be to have a single Salesforce ruleset containing all rules for Apex, Visualforce, and XML but as I understand the structure. Documentation and other things are generated based on top of the languages where Apex and Visualforce are separate languages and Salesforce XML is not a language at all.
Would it be doable (without breaking the concept) to add a section to XML like the existing "Error Prone"? Something like "Salesforce Metadata"?
oowekyala commentedon Mar 16, 2022
I can see how this feature request would be useful, and I support it. There is currently no precedent for publishing multi-language rulesets directly from PMD though, so we have to break new ground.
Maybe a nice way to do this would be to create a new module
pmd-salesforce, which pulls inpmd-xml,pmd-apexandpmd-visualforce, which has its ownrulesets/salesforce/quickstart.xml? I expect this would show up in your screenshot as a new "Salesforce Rules" dropdown (above "Salesforce VisualForce Rules"), with a ruleset index like for other languages. The documentation generator might have to be slightly updated, I'm not sure about this. One advantage is that salesforce users would only need to pull in one language module to get all the relevant ones.rsoesemann commentedon Mar 16, 2022
@oowekyala this would be the optimum. Would that also work with the Salesforce-specific XML rules? As far as I understand as they are not a separate language such a multi-language auto-pull from the doc engine would ignore them.
Or do you propose to also add a "Salesforce XML" section in the XML rules?
SCWells72 commentedon Mar 16, 2022
Hi, @oowekyala. Are there any existing precedents for "meta" modules like this that aggregate multiple existing modules?
oowekyala commentedon Mar 16, 2022
So I think we would define a new XML language module for "Salesforce XML". Now we could put this in the new
pmd-salesforcemodule, or the currentpmd-xmlmodule. I think it probably makes more sense to put it in the new module, since these rules are probably better discoverable from the salesforce module. The documentation generator would produce a page for "Salesforce XML" rules, and most likely a page for the ruleset index that contains the saleforcequickstart.xml(I'm not sure this will work out of the box, but it shouldn't be too much work)In our codebase, there isn't ^^
[-]Provide centralized examples of XML XPath rules for Salesforce XML metadata files[/-][+]Doc site shows central Salesforce ruleset incl. Apex, Visualforce and XML Custom rules for Metadata[/+]rsoesemann commentedon Mar 17, 2022
@SCWells72 I adjusted the title to better reflect our new agreed-on goal.
@oowekyala what are the proposed next steps?
[-]Doc site shows central Salesforce ruleset incl. Apex, Visualforce and XML Custom rules for Metadata[/-][+]Doc site shows central Salesforce ruleset incl. Apex, Visualforce & XML Metadata[/+]adangel commentedon Mar 17, 2022
To summarize what I understand:
Here are my 2 cents:
I also like the idea of grouping the languages apex and vf into a own module. We have done something similar (although more complex and in the end different...) with scala (see folder pmd-scala-modules). The structuring can happen on two layers: filesystem layer - so how we organize the source code. That means, it will be backwards compatible in terms of maven coordinates, if we create a folder "pmd-salesforce" and move into it the currently existing folders "pmd-apex", "pmd-apex-jorje", "pmd-visualforce". We could keep the groupId/artifactId the same to have it compatible. The only downside I see is the not working mapping from groupId/artifactId to source code: Given a groupId="net.sourceforge.pmd", it is sometimes helpful to deduce from the artifactId the actual location of the sourcecode in the repository. The extra folder "pmd-salesforce" would not be presented and might cause confusion. That can only be fixed with breaking compatibility.
Having the new rules/rulesets as part of the main repository applies the exactly same release cycle to them. In the past @oowekyala and I discussed some idea around a semi-official repo like "pmd-contributions", which could contain additional rules and rulesets and even languages. Since it is a different repository, it could use a different release cycle. However, there are open questions around how to actually use and distribute the artifacts from the repo. Also generating a documentation site would be useful as well. Without more work done on this side, the artifacts would need to be copied manually into your local pmd-bin-xxx/lib folder (or added as maven dependency). There are also questions about who maintains this repo. Also the compatibility needs to be considered: e.g. which version of pmd-contrib works together with which version of pmd; same question arise since we moved out the pmd-designer (formerly module pmd-ui).
Taking a step back and looking at the rules/rulesets we ship with the "official" pmd distribution: These rules are part of main repo, are maintained as part of the "default" work we do. The rules are considered to be general enough, that they are useful for everybody using the language. Looking from this angle, then we definitively should integrate these rules into the official distribution and into the main repo (given that the rules you want to add are useful for the majority of users).
To explain, how the current documentation is generated (this is done by the module pmd-doc, so can be changed - it doesn't need to stay the way it is now):
That's all. The grouping currently only happens based on language. To automate the grouping of apex+visualforce+salesforce-xml, this information needs to be added somewhere (maybe we just hardcode it in pmd-doc).
Next steps from my point of view:
rsoesemann commentedon Mar 17, 2022
Your summary is correct @adangel. A few comments:
Combining Apex and Visualforce alone is not enough. The XML metadata rules also need to go into such a unified Salesforce rulesset
I honestly see no need for an extra repo or release cycle. The current release cadence is often and more than perfect for me and other contributors to add Custom XML rules to the Salesforce ruleset
Regarding documentation and testing I had hoped that Custom XPath rules are MUCH easier to handle. Everything is contained in the node. So anyone contributing a new rule creates a PR on this single rulesset.xml.
I see more than ONE Salesforce metadata XML dialect coming in the near future. @aidan-harding already investigated into writing a parser for Salesforce Flow XML in [xml] New language to detect issues in Salesforce Flow #3413. The current XML implementation is good enough for the most XML metadata formats but we should plan for a structure like
Salesforce
@SCWells72 do you you agree ?
[-]Doc site shows central Salesforce ruleset incl. Apex, Visualforce & XML Metadata[/-][+]Unified Salesforce ruleset incl. Apex, Visualforce & XML Metadata[/+]SCWells72 commentedon Mar 17, 2022
@rsoesemann the only thing I don't necessarily agree with is the need for a separate language/AST for flow. Flow documents already adhere to the common XSD for Salesforce metadata files. If we're thinking that XPath-based XML rules are sufficient for those other document types--and XPath is obviously EXTREMELY flexible for criteria-based node selection--then they should work just as well for those documents. Another language that is effectively a proxy for the existing XML AST seems superfluous. I think we should just have Apex, Visualforce, and XML (all under Salesforce, of course) for now. The only others that might be added in time would be Aura and LWC, and those are already well-covered by custom ESLint rules from Salesforce anyway.
SCWells72 commentedon Mar 17, 2022
@rsoesemann, sure. I was responding to the comment in the linked issue about adding a new language specifically for Flow and the corresponding escalation of flow metadata as a peer to "other" metadata. In reality, all Salesforce XML metadata conforms to a single
metadata.xsd(which I actually already bundle with IC2 to provide XML validation, code completion, etc.). A Flow-specific AST would be very close to isomorphic with the existing XML AST for the same document, and therefore the expressed XPath rules would be virtually identical. That's why I termed such work superfluous. Perhaps @aidan-harding has found use cases that aren't (easily) supported by the XML AST?I just think if you start to pick apart the various XML file subtypes, you're going to end up with unnecessary and potentially confusing bifurcation. I would start with "Salesforce XML" as a peer to "Salesforce Apex" and "Salesforce Visualforce" and see if a natural splintering of distinct subtypes occurs as people use it.
Add additional tests to detect changed rules
adangel commentedon Mar 24, 2022
Documentation is indeed inside the a ruleset-xml file. Note, we'll still have the different categories, so there is no single ruleset.
The tests are still mandatory - we try to not accept rule contributions without tests...
For the combined ruleset (the quickstart.xml or the "unified Salesforce ruleset"), tests are not necessary, because this ruleset is expected to only contain rule references and not rules.
I think, we agreed that the restructuring of the salesforce relates modules in pmd under a same common parent directory (probably pmd-salesforce) and creating a pmd-salesforce-xml module is a good idea. But (speaking now for @oowekyala and myself) we as maintainers won't have the capacity to do this - we are relying on contributions.
rsoesemann commentedon Mar 24, 2022
Sure @adangel or @oowekyala could you give some guidance on what would need to be done where to make that happen?
oowekyala commentedon Mar 28, 2022
The following steps should get the assignee (TBD) started:
pmd-salesforce-modules, move pmd-apex, pmd-apex-jorje, and pmd-visualforce into there; adjust relative paths in the pom.xml filespmd-salesforce-xmlinsidepmd-salesforce-modulesBaseLanguageModulefor SalesForce Flow (use eg PomLanguageModule as template)net.sourceforge.pmd.lang.flowand subpackagespmd-salesforce-xml/src/main/resources, create categories for the flow language (egcategory/flow/codestyle.xml), add a couple of rules (and tests, in src/test/java)pmd-salesforceinsidepmd-salesforce-modulesrulesets/salesforce/quickstart.xml, with references to the most useful rules for apex, flow, and visualforce.Whoever decides to take this on, please request that we assign you to this issue. If you're stuck, open a draft PR and ask for specific guidance (please don't overload this ticket)
@SCWells72 you seem interested, would you have capacity for this? Otherwise @rsoesemann please help with finding an assignee
rsoesemann commentedon Mar 28, 2022
Thanks for this outline @oowekyala. Scott and I will care about progress but not very soon. So please leave this open.
rsoesemann commentedon Aug 29, 2022
@SCWells72 do you have an appetite for this?
SCWells72 commentedon Aug 29, 2022
@rsoesemann I would certainly love to see it done but between work and my kids back in school, I can't imagine finding the free time anytime in the near future. Sorry...
jonny-harte commentedon Dec 13, 2023
Hi, is this going to be worked on. It looks really useful!
justinstroud-campmeeker commentedon Mar 21, 2024
@SCWells72 @jonny-harte I know I'm late to the party here, but this is something I'm actively working on. I had an issue with getting the filename in 7 and after a bit of back and forth, @jsotuyod mentioned the need for a contribution for Salesforce Metadata. I'm happy to take that on myself, as it's something I'm grinding on anyways. I'm a little green when it comes to contributing so any guidance would be appreciated (case in point, I attempted to build PMD last night locally and ran into some security issues with the Maven validate.) Should I start a discussion thread for this or something?
jsotuyod commentedon Mar 21, 2024
@justinstroudbah feel free to start a discussion! we will try to assist you as best we can.