pmd / pmd-github-action

GitHub Action for PMD
MIT License
39 stars 25 forks source link

Allow the --force-language PMD CLI option #265

Open vt89 opened 6 months ago

vt89 commented 6 months ago

The PMD CLI has the --force-language options to force a language to be used for all input files, irrespective of file names.

This feature allows us to use GitHub Actions for Salesforce projects.

vt89 commented 4 months ago

@adangel News about this feature?

adangel commented 4 months ago

This feature allows us to use GitHub Actions for Salesforce projects.

Can you give an example of your use case? What exactly are "Salesforce projects"?

vt89 commented 4 months ago

@adangel Salesforce stores XML information in files using extensions like.object, .permissionset instead of .xml. Even if I define a PMD rule for XML language, since files do not have the .xml extension, the PMD engine does not process them.

I see the PMD cli provides the option --force-language to handle these cases and it is mentioned here: PMD CLI reference.

So, if your GitHub Action provides the --force-language input we can use it to cover the scenario I mentioned above. I hope my explanation helps you understand my initial request

adangel commented 4 months ago

Thanks for sharing. I heard about .flow files, but never about .object or .permissionset (note: I'm not a apex/salesforce developer at all).

Do you know, whether these files have an official documentation?

See also https://github.com/pmd/pmd/discussions/4877 and especially this comment which collects existing issues around this topic.

Regarding the implementation of this feature in pmd-github-action: I assume, your salesforce project contains of: .cls files (which are Apex source files), .flow files (which are XML-files describing a "Salesforce Flow"), .object files (which are XML files for ??), .permissionset files (which are XML files for ??), and maybe others (visualforce?). If you want to analyze your project, you would need to integrate the pmd-github-action in your workflow multiple times with different parameters... Furthermore, you can only configure sourcePath - if your XML files are in the same directory as the apex sources, this would mean, that .cls would be parsed as xml files, which will fail for sure. You would either need to use include/exclude filters in your rulesets or we need an additional parameters to specify exactly, which files should be analyzed by PMD.

Do you know of an open source sample Salesforce project, which shows such a structure and that we can reuse as a test case?

vt89 commented 4 months ago

Thanks @adangel for showing interest!

Official documentation is here:

In the above links, file suffixes like .object, .profile , .permissionset are mentioned and example files are also shown. Those are three examples but there are more files with 'special' extensions.

Regarding the implementation, I got your point about having files with different extensions in the same folder. I may try to create multiple jobs in my GitHub Workflow: one for each file extension that I want to analyze and use the sourcePath parameter. For example, the GitHub Workflow will have one job for the .profile files and I provide the sourcePath where these files are stored, another one for permissionSet, etc.

If pmd-github-action also provide other PMD CLI parameters like --dir, --file-list then I think we will have multiple alternatives :-)

Regarding the open source sample Salesforce project I was not able to find any official one provided by Salesforce. If you need it, I can create a new one by myself and share it with you. Let me know if it makes sense to you.

Thanks again @adangel