Repository navigation
[CY-6271] Support .cjs extension #65
Description
Similar to #61.
I recently ran into an issue using Codacy Coverage Reporter GitHub Action where codacy-coverage-reporter was failing with a "Can't guess the report language" error. I use Codacy on several projects and had not experienced this before. Here are the relevant parts of the log:
2022-06-25 06:19:38.548Z info [ConfigurationRules] API base URL: https://api.codacy.com/ - (ConfigurationRules.scala:79)
[32](https://github.com/jhildenbiddle/mergedeep/runs/7052111013?check_suite_focus=true#step:6:33)
2022-06-25 06:19:38.663Z info [CommitUUIDProvider] CI/CD provider GitHub Actions found Commit UUID c215d24a954cb2e7a657606c910a1598e4697b1f - (CommitUUIDProvider.scala:132)
[33](https://github.com/jhildenbiddle/mergedeep/runs/7052111013?check_suite_focus=true#step:6:34)
2022-06-25 06:19:38.663Z info [ReportRules] Parsing coverage data from: /home/runner/work/mergedeep/mergedeep/coverage/lcov.info ... - (ReportRules.scala:37)
[34](https://github.com/jhildenbiddle/mergedeep/runs/7052111013?check_suite_focus=true#step:6:35)
2022-06-25 06:19:38.668Z info [ReportRules] Coverage parser used is com.codacy.parsers.implementation.LCOVParser$@51e6bdbd - (ReportRules.scala:42)
[35](https://github.com/jhildenbiddle/mergedeep/runs/7052111013?check_suite_focus=true#step:6:36)
2022-06-25 06:19:38.669Z info [ReportRules] Generated coverage report: /tmp/codacy-coverage-11970218897261936170.json (1.53 kB) - (ReportRules.scala:255)
[36](https://github.com/jhildenbiddle/mergedeep/runs/7052111013?check_suite_focus=true#step:6:37)
2022-06-25 06:19:38.669Z info [ReportRules] Uploading coverage data... - (ReportRules.scala:256)
[37](https://github.com/jhildenbiddle/mergedeep/runs/7052111013?check_suite_focus=true#step:6:38)
2022-06-25 06:19:38.669Z error [CodacyCoverageReporter] Can't guess the report language - (CodacyCoverageReporter.scala:25)
I eventually realized that the difference between this project and previous projects is the use of .cjs instead of .js as the file extension for my source files. This was done to differentiate between CommonJS modules (.cjs), ES modules (.mjs), and standard Javascript files (.js). I was able to resolve the coverage reporter issue by forcing the language to "Javascript":
- name: Report code coverage
uses: codacy/codacy-coverage-reporter-action@v1.3.0
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage/lcov.info
language: JavascriptThis allowed codacy-coverage-reporter to complete without error, but none of the .cjs files were processed by Codacy despite the coverage report containing information for them.
Looking at the source linked in the docs, it appears that at least part of the issue is the missing .cjs association in Language.scala:
Hopefully a small update there can resolve the issue, but I know it's rarely that easy. :)
Activity
[-]Support .cjs extension[/-][+][CY-6271] Support .cjs extension[/+]github-actions commentedon Jun 26, 2022
Internal ticket created : CY-6271
jhildenbiddle commentedon Jul 30, 2022
Ping @franciscodua since this seems very similar to #61. Thanks!
stefanvacareanu7 commentedon Aug 17, 2022
Hi there,
Thanks for reaching out!
You can use the file extensions feature to configure the accepted extensions for Javascript language.
Let me know if this helps.
Stefan
jhildenbiddle commentedon Aug 17, 2022
Thanks @stefanvacareanu7.
TLDR: PMD breaks with
.cjsfiles.Details...
The project I was working on is now live, so for context:
The tooltip on the web UI states that only
.js,.jsx,.jsm,.vue, and.mjsare supported:Without adding the extension, the log for the latest commit analysis shows the following error:
If I add
.cjsto the file extensions section as instructed, the logs show a different error:Since PMD is failing, I disabled this tool and all tests now pass as expected. I can live without PMD, but it would be nice if this tool worked as well since I'm using it to analyze other repos.
Also, while I'm happy to find a workaround for analyzing
.cjsfiles with Codacy, both.mjsand.cjsare widely-used extensions within the Node ecosystem so supporting one by default without the other feels like a miss. Just my $0.02.DMarinhoCodacy commentedon May 30, 2023
Hello,
We already bumped PMD to the latest stable version and we tested already .cjs files with success.
Feel free to make more tests and let us know.
Kind regards,
David Marinho