Skip to content
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

[CY-6271] Support .cjs extension #65

Closed
jhildenbiddle opened this issue Jun 26, 2022 · 5 comments · May be fixed by #66
Closed

[CY-6271] Support .cjs extension #65

jhildenbiddle opened this issue Jun 26, 2022 · 5 comments · May be fixed by #66
Labels
jira-issue Issue tracked on JIRA

Comments

@jhildenbiddle
Copy link

jhildenbiddle commented Jun 26, 2022

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/[email protected]
  with:
    project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
    coverage-reports: coverage/lcov.info
    language: Javascript

This 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:

https://github.com/codacy/codacy-plugins-api/blob/master/src/main/scala/com/codacy/plugins/api/languages/Language.scala#L102

Hopefully a small update there can resolve the issue, but I know it's rarely that easy. :)

@github-actions github-actions bot added the jira-issue Issue tracked on JIRA label Jun 26, 2022
@github-actions github-actions bot changed the title Support .cjs extension [CY-6271] Support .cjs extension Jun 26, 2022
@github-actions
Copy link

Internal ticket created : CY-6271

@jhildenbiddle
Copy link
Author

Ping @franciscodua since this seems very similar to #61. Thanks!

@stefanvacareanu7
Copy link
Contributor

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
Copy link
Author

Thanks @stefanvacareanu7.

TLDR: PMD breaks with .cjs files.

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 .mjs are supported:

CleanShot 2022-08-17 at 11 38 44@2x

Without adding the extension, the log for the latest commit analysis shows the following error:

CleanShot 2022-08-17 at 11 46 07@2x

If I add .cjs to the file extensions section as instructed, the logs show a different error:

CleanShot 2022-08-17 at 11 42 07@2x

Error on file src/index.cjs:1. Cause: PMDException: Error while parsing /src/src/index.cjs
Error on file src/util.cjs:1. Cause: PMDException: Error while parsing /src/src/util.cjs
Error on file tests/index.test.js:1. Cause: PMDException: Error while processing /src/tests/index.test.js

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 .cjs files with Codacy, both .mjs and .cjs are widely-used extensions within the Node ecosystem so supporting one by default without the other feels like a miss. Just my $0.02.

@DMarinhoCodacy
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira-issue Issue tracked on JIRA
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants