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

JS-421 Fix new-rule script #4917

Closed
wants to merge 27 commits into from
Closed

JS-421 Fix new-rule script #4917

wants to merge 27 commits into from

Conversation

kebetsi
Copy link
Contributor

@kebetsi kebetsi commented Nov 20, 2024

JS-421

  • Refactored the scripts inside tools folder to make use of the same helpers.
    • generate-meta.ts
    • new-rule.ts
    • generate-external-rule-docs.ts
    • generate-rule-indexes.ts
  • The new rule will prompt the user for all needed input (using inquirer.js)
  • Java class will now implement the correct parent class depending if it's a rule for MAIN or TEST
  • All Java check classes have been renamed to use the Sonar rule id. This makes it much easier to synchronize both sides
  • The index with all java checks is now autogenerated on npm ci (as we do in the node.js side) in a git ignored file (AllChecks.java)

@kebetsi kebetsi requested review from vdiez and zglicz November 20, 2024 12:45
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Fix new-rule script JS-421 Fix new-rule script Nov 20, 2024
@kebetsi kebetsi marked this pull request as draft November 21, 2024 07:48
@kebetsi kebetsi removed request for zglicz and vdiez November 21, 2024 07:48
vdiez added 18 commits November 25, 2024 16:48
# Conflicts:
#	package-lock.json
#	packages/jsts/src/rules/README.md
#	packages/jsts/src/rules/S100/meta.ts
#	packages/jsts/src/rules/S101/meta.ts
#	packages/jsts/src/rules/S104/meta.ts
#	packages/jsts/src/rules/S105/meta.ts
#	packages/jsts/src/rules/S1066/meta.ts
#	packages/jsts/src/rules/S1067/meta.ts
#	packages/jsts/src/rules/S1068/meta.ts
#	packages/jsts/src/rules/S107/meta.ts
#	packages/jsts/src/rules/S1077/meta.ts
#	packages/jsts/src/rules/S1082/meta.ts
#	packages/jsts/src/rules/S109/meta.ts
#	packages/jsts/src/rules/S1105/meta.ts
#	packages/jsts/src/rules/S1110/meta.ts
#	packages/jsts/src/rules/S1116/meta.ts
#	packages/jsts/src/rules/S1119/meta.ts
#	packages/jsts/src/rules/S1121/meta.ts
#	packages/jsts/src/rules/S1125/meta.ts
#	packages/jsts/src/rules/S1126/meta.ts
#	packages/jsts/src/rules/S1128/meta.ts
#	packages/jsts/src/rules/S1134/meta.ts
#	packages/jsts/src/rules/S1135/meta.ts
#	packages/jsts/src/rules/S1154/meta.ts
#	packages/jsts/src/rules/S117/meta.ts
#	packages/jsts/src/rules/S1172/meta.ts
#	packages/jsts/src/rules/S1186/meta.ts
#	packages/jsts/src/rules/S1192/meta.ts
#	packages/jsts/src/rules/S1219/meta.ts
#	packages/jsts/src/rules/S1226/meta.ts
#	packages/jsts/src/rules/S124/meta.ts
#	packages/jsts/src/rules/S125/meta.ts
#	packages/jsts/src/rules/S126/meta.ts
#	packages/jsts/src/rules/S1264/meta.ts
#	packages/jsts/src/rules/S128/meta.ts
#	packages/jsts/src/rules/S1301/meta.ts
#	packages/jsts/src/rules/S131/meta.ts
#	packages/jsts/src/rules/S1313/meta.ts
#	packages/jsts/src/rules/S134/meta.ts
#	packages/jsts/src/rules/S135/meta.ts
#	packages/jsts/src/rules/S138/meta.ts
#	packages/jsts/src/rules/S1438/meta.ts
#	packages/jsts/src/rules/S1439/meta.ts
#	packages/jsts/src/rules/S1444/meta.ts
#	packages/jsts/src/rules/S1451/meta.ts
#	packages/jsts/src/rules/S1472/meta.ts
#	packages/jsts/src/rules/S1479/meta.ts
#	packages/jsts/src/rules/S1481/meta.ts
#	packages/jsts/src/rules/S1488/meta.ts
#	packages/jsts/src/rules/S1515/meta.ts
#	packages/jsts/src/rules/S1523/meta.ts
#	packages/jsts/src/rules/S1526/meta.ts
#	packages/jsts/src/rules/S1527/meta.ts
#	packages/jsts/src/rules/S1528/meta.ts
#	packages/jsts/src/rules/S1529/meta.ts
#	packages/jsts/src/rules/S1530/meta.ts
#	packages/jsts/src/rules/S1533/meta.ts
#	packages/jsts/src/rules/S1534/meta.ts
#	packages/jsts/src/rules/S1535/meta.ts
#	packages/jsts/src/rules/S1541/meta.ts
#	packages/jsts/src/rules/S1607/meta.ts
#	packages/jsts/src/rules/S1751/meta.ts
#	packages/jsts/src/rules/S1763/meta.ts
#	packages/jsts/src/rules/S1764/meta.ts
#	packages/jsts/src/rules/S1788/meta.ts
#	packages/jsts/src/rules/S1821/meta.ts
#	packages/jsts/src/rules/S1848/meta.ts
#	packages/jsts/src/rules/S1854/meta.ts
#	packages/jsts/src/rules/S1862/meta.ts
#	packages/jsts/src/rules/S1871/meta.ts
#	packages/jsts/src/rules/S1874/meta.ts
#	packages/jsts/src/rules/S1940/meta.ts
#	packages/jsts/src/rules/S1994/meta.ts
#	packages/jsts/src/rules/S2004/meta.ts
#	packages/jsts/src/rules/S2068/meta.ts
#	packages/jsts/src/rules/S2077/meta.ts
#	packages/jsts/src/rules/S2092/meta.ts
#	packages/jsts/src/rules/S2123/meta.ts
#	packages/jsts/src/rules/S2137/meta.ts
#	packages/jsts/src/rules/S2138/meta.ts
#	packages/jsts/src/rules/S2187/meta.ts
#	packages/jsts/src/rules/S2189/meta.ts
#	packages/jsts/src/rules/S2201/meta.ts
#	packages/jsts/src/rules/S2208/meta.ts
#	packages/jsts/src/rules/S2234/meta.ts
#	packages/jsts/src/rules/S2245/meta.ts
#	packages/jsts/src/rules/S2251/meta.ts
#	packages/jsts/src/rules/S2255/meta.ts
#	packages/jsts/src/rules/S2259/meta.ts
#	packages/jsts/src/rules/S2301/meta.ts
#	packages/jsts/src/rules/S2310/meta.ts
#	packages/jsts/src/rules/S2376/meta.ts
#	packages/jsts/src/rules/S2392/meta.ts
#	packages/jsts/src/rules/S2424/meta.ts
#	packages/jsts/src/rules/S2428/meta.ts
#	packages/jsts/src/rules/S2430/meta.ts
#	packages/jsts/src/rules/S2486/meta.ts
#	packages/jsts/src/rules/S2589/meta.ts
#	packages/jsts/src/rules/S2598/meta.ts
#	packages/jsts/src/rules/S2612/meta.ts
#	packages/jsts/src/rules/S2639/meta.ts
#	packages/jsts/src/rules/S2681/meta.ts
#	packages/jsts/src/rules/S2688/meta.ts
#	packages/jsts/src/rules/S2692/meta.ts
#	packages/jsts/src/rules/S2699/meta.ts
#	packages/jsts/src/rules/S2703/meta.ts
#	packages/jsts/src/rules/S2737/meta.ts
#	packages/jsts/src/rules/S2755/meta.ts
#	packages/jsts/src/rules/S2757/meta.ts
#	packages/jsts/src/rules/S2814/meta.ts
#	packages/jsts/src/rules/S2817/meta.ts
#	packages/jsts/src/rules/S2819/meta.ts
#	packages/jsts/src/rules/S2870/meta.ts
#	packages/jsts/src/rules/S2871/meta.ts
#	packages/jsts/src/rules/S2970/meta.ts
#	packages/jsts/src/rules/S2990/meta.ts
#	packages/jsts/src/rules/S2999/meta.ts
#	packages/jsts/src/rules/S3001/meta.ts
#	packages/jsts/src/rules/S3003/meta.ts
#	packages/jsts/src/rules/S3317/meta.ts
#	packages/jsts/src/rules/S3330/meta.ts
#	packages/jsts/src/rules/S3358/meta.ts
#	packages/jsts/src/rules/S3402/meta.ts
#	packages/jsts/src/rules/S3403/meta.ts
#	packages/jsts/src/rules/S3415/meta.ts
#	packages/jsts/src/rules/S3498/meta.ts
#	packages/jsts/src/rules/S3499/meta.ts
#	packages/jsts/src/rules/S3500/meta.ts
#	packages/jsts/src/rules/S3504/meta.ts
#	packages/jsts/src/rules/S3512/meta.ts
#	packages/jsts/src/rules/S3513/meta.ts
#	packages/jsts/src/rules/S3514/meta.ts
#	packages/jsts/src/rules/S3516/meta.ts
#	packages/jsts/src/rules/S3524/meta.ts
#	packages/jsts/src/rules/S3525/meta.ts
#	packages/jsts/src/rules/S3531/meta.ts
#	packages/jsts/src/rules/S3533/meta.ts
#	packages/jsts/src/rules/S3579/meta.ts
#	packages/jsts/src/rules/S3616/meta.ts
#	packages/jsts/src/rules/S3626/meta.ts
#	packages/jsts/src/rules/S3686/meta.ts
#	packages/jsts/src/rules/S3696/meta.ts
#	packages/jsts/src/rules/S3699/meta.ts
#	packages/jsts/src/rules/S3723/meta.ts
#	packages/jsts/src/rules/S3735/meta.ts
#	packages/jsts/src/rules/S3757/meta.ts
#	packages/jsts/src/rules/S3758/meta.ts
#	packages/jsts/src/rules/S3760/meta.ts
#	packages/jsts/src/rules/S3776/meta.ts
#	packages/jsts/src/rules/S3782/meta.ts
#	packages/jsts/src/rules/S3785/meta.ts
#	packages/jsts/src/rules/S3796/meta.ts
#	packages/jsts/src/rules/S3798/meta.ts
#	packages/jsts/src/rules/S3800/meta.ts
#	packages/jsts/src/rules/S3801/meta.ts
#	packages/jsts/src/rules/S3827/meta.ts
#	packages/jsts/src/rules/S3854/meta.ts
#	packages/jsts/src/rules/S3923/meta.ts
#	packages/jsts/src/rules/S3972/meta.ts
#	packages/jsts/src/rules/S3973/meta.ts
#	packages/jsts/src/rules/S3981/meta.ts
#	packages/jsts/src/rules/S3984/meta.ts
#	packages/jsts/src/rules/S4023/meta.ts
#	packages/jsts/src/rules/S4030/meta.ts
#	packages/jsts/src/rules/S4036/meta.ts
#	packages/jsts/src/rules/S4043/meta.ts
#	packages/jsts/src/rules/S4084/meta.ts
#	packages/jsts/src/rules/S4123/meta.ts
#	packages/jsts/src/rules/S4138/meta.ts
#	packages/jsts/src/rules/S4139/meta.ts
#	packages/jsts/src/rules/S4143/meta.ts
#	packages/jsts/src/rules/S4144/meta.ts
#	packages/jsts/src/rules/S4156/meta.ts
#	packages/jsts/src/rules/S4158/meta.ts
#	packages/jsts/src/rules/S4165/meta.ts
#	packages/jsts/src/rules/S4275/meta.ts
#	packages/jsts/src/rules/S4322/meta.ts
#	packages/jsts/src/rules/S4323/meta.ts
#	packages/jsts/src/rules/S4324/meta.ts
#	packages/jsts/src/rules/S4327/meta.ts
#	packages/jsts/src/rules/S4328/meta.ts
#	packages/jsts/src/rules/S4335/meta.ts
#	packages/jsts/src/rules/S4423/meta.ts
#	packages/jsts/src/rules/S4426/meta.ts
#	packages/jsts/src/rules/S4502/meta.ts
#	packages/jsts/src/rules/S4507/meta.ts
#	packages/jsts/src/rules/S4524/meta.ts
#	packages/jsts/src/rules/S4619/meta.ts
#	packages/jsts/src/rules/S4619/rule.ts
#	packages/jsts/src/rules/S4621/meta.ts
#	packages/jsts/src/rules/S4622/meta.ts
#	packages/jsts/src/rules/S4623/meta.ts
#	packages/jsts/src/rules/S4624/meta.ts
#	packages/jsts/src/rules/S4634/meta.ts
#	packages/jsts/src/rules/S4721/meta.ts
#	packages/jsts/src/rules/S4782/meta.ts
#	packages/jsts/src/rules/S4784/meta.ts
#	packages/jsts/src/rules/S4787/meta.ts
#	packages/jsts/src/rules/S4790/meta.ts
#	packages/jsts/src/rules/S4798/meta.ts
#	packages/jsts/src/rules/S4817/meta.ts
#	packages/jsts/src/rules/S4818/meta.ts
#	packages/jsts/src/rules/S4822/meta.ts
#	packages/jsts/src/rules/S4823/meta.ts
#	packages/jsts/src/rules/S4829/meta.ts
#	packages/jsts/src/rules/S4830/meta.ts
#	packages/jsts/src/rules/S5042/meta.ts
#	packages/jsts/src/rules/S5122/meta.ts
#	packages/jsts/src/rules/S5148/meta.ts
#	packages/jsts/src/rules/S5247/meta.ts
#	packages/jsts/src/rules/S5254/meta.ts
#	packages/jsts/src/rules/S5256/meta.ts
#	packages/jsts/src/rules/S5257/meta.ts
#	packages/jsts/src/rules/S5260/meta.ts
#	packages/jsts/src/rules/S5264/meta.ts
#	packages/jsts/src/rules/S5332/meta.ts
#	packages/jsts/src/rules/S5443/meta.ts
#	packages/jsts/src/rules/S5527/meta.ts
#	packages/jsts/src/rules/S5542/meta.ts
#	packages/jsts/src/rules/S5547/meta.ts
#	packages/jsts/src/rules/S5604/meta.ts
#	packages/jsts/src/rules/S5659/meta.ts
#	packages/jsts/src/rules/S5689/meta.ts
#	packages/jsts/src/rules/S5691/meta.ts
#	packages/jsts/src/rules/S5693/meta.ts
#	packages/jsts/src/rules/S5725/meta.ts
#	packages/jsts/src/rules/S5728/meta.ts
#	packages/jsts/src/rules/S5730/meta.ts
#	packages/jsts/src/rules/S5732/meta.ts
#	packages/jsts/src/rules/S5734/meta.ts
#	packages/jsts/src/rules/S5736/meta.ts
#	packages/jsts/src/rules/S5739/meta.ts
#	packages/jsts/src/rules/S5742/meta.ts
#	packages/jsts/src/rules/S5743/meta.ts
#	packages/jsts/src/rules/S5757/meta.ts
#	packages/jsts/src/rules/S5759/meta.ts
#	packages/jsts/src/rules/S5842/meta.ts
#	packages/jsts/src/rules/S5843/meta.ts
#	packages/jsts/src/rules/S5850/meta.ts
#	packages/jsts/src/rules/S5852/meta.ts
#	packages/jsts/src/rules/S5856/meta.ts
#	packages/jsts/src/rules/S5860/meta.ts
#	packages/jsts/src/rules/S5863/meta.ts
#	packages/jsts/src/rules/S5867/meta.ts
#	packages/jsts/src/rules/S5868/meta.ts
#	packages/jsts/src/rules/S5869/meta.ts
#	packages/jsts/src/rules/S5876/meta.ts
#	packages/jsts/src/rules/S5958/meta.ts
#	packages/jsts/src/rules/S5973/meta.ts
#	packages/jsts/src/rules/S6019/meta.ts
#	packages/jsts/src/rules/S6035/meta.ts
#	packages/jsts/src/rules/S6079/meta.ts
#	packages/jsts/src/rules/S6080/meta.ts
#	packages/jsts/src/rules/S6092/meta.ts
#	packages/jsts/src/rules/S6245/meta.ts
#	packages/jsts/src/rules/S6249/meta.ts
#	packages/jsts/src/rules/S6252/meta.ts
#	packages/jsts/src/rules/S6265/meta.ts
#	packages/jsts/src/rules/S6268/meta.ts
#	packages/jsts/src/rules/S6270/meta.ts
#	packages/jsts/src/rules/S6275/meta.ts
#	packages/jsts/src/rules/S6281/meta.ts
#	packages/jsts/src/rules/S6299/meta.ts
#	packages/jsts/src/rules/S6302/meta.ts
#	packages/jsts/src/rules/S6303/meta.ts
#	packages/jsts/src/rules/S6304/meta.ts
#	packages/jsts/src/rules/S6308/meta.ts
#	packages/jsts/src/rules/S6317/meta.ts
#	packages/jsts/src/rules/S6319/meta.ts
#	packages/jsts/src/rules/S6321/meta.ts
#	packages/jsts/src/rules/S6323/meta.ts
#	packages/jsts/src/rules/S6324/meta.ts
#	packages/jsts/src/rules/S6326/meta.ts
#	packages/jsts/src/rules/S6327/meta.ts
#	packages/jsts/src/rules/S6328/meta.ts
#	packages/jsts/src/rules/S6329/meta.ts
#	packages/jsts/src/rules/S6330/meta.ts
#	packages/jsts/src/rules/S6331/meta.ts
#	packages/jsts/src/rules/S6332/meta.ts
#	packages/jsts/src/rules/S6333/meta.ts
#	packages/jsts/src/rules/S6351/meta.ts
#	packages/jsts/src/rules/S6353/meta.ts
#	packages/jsts/src/rules/S6397/meta.ts
#	packages/jsts/src/rules/S6426/meta.ts
#	packages/jsts/src/rules/S6439/meta.ts
#	packages/jsts/src/rules/S6440/meta.ts
#	packages/jsts/src/rules/S6441/meta.ts
#	packages/jsts/src/rules/S6442/meta.ts
#	packages/jsts/src/rules/S6443/meta.ts
#	packages/jsts/src/rules/S6477/meta.ts
#	packages/jsts/src/rules/S6478/meta.ts
#	packages/jsts/src/rules/S6479/meta.ts
#	packages/jsts/src/rules/S6481/meta.ts
#	packages/jsts/src/rules/S6486/meta.ts
#	packages/jsts/src/rules/S6535/meta.ts
#	packages/jsts/src/rules/S6544/meta.ts
#	packages/jsts/src/rules/S6551/meta.ts
#	packages/jsts/src/rules/S6557/meta.ts
#	packages/jsts/src/rules/S6564/meta.ts
#	packages/jsts/src/rules/S6571/meta.ts
#	packages/jsts/src/rules/S6572/meta.ts
#	packages/jsts/src/rules/S6582/meta.ts
#	packages/jsts/src/rules/S6594/meta.ts
#	packages/jsts/src/rules/S6598/meta.ts
#	packages/jsts/src/rules/S6606/meta.ts
#	packages/jsts/src/rules/S6627/meta.ts
#	packages/jsts/src/rules/S6643/meta.ts
#	packages/jsts/src/rules/S6647/meta.ts
#	packages/jsts/src/rules/S6660/meta.ts
#	packages/jsts/src/rules/S6661/meta.ts
#	packages/jsts/src/rules/S6666/meta.ts
#	packages/jsts/src/rules/S6676/meta.ts
#	packages/jsts/src/rules/S6679/meta.ts
#	packages/jsts/src/rules/S6747/meta.ts
#	packages/jsts/src/rules/S6749/meta.ts
#	packages/jsts/src/rules/S6754/meta.ts
#	packages/jsts/src/rules/S6759/meta.ts
#	packages/jsts/src/rules/S6788/meta.ts
#	packages/jsts/src/rules/S6791/meta.ts
#	packages/jsts/src/rules/S6827/meta.ts
#	packages/jsts/src/rules/S6844/meta.ts
#	packages/jsts/src/rules/S6853/meta.ts
#	packages/jsts/src/rules/S6957/meta.ts
#	packages/jsts/src/rules/S6958/meta.ts
#	packages/jsts/src/rules/S6959/meta.ts
#	packages/jsts/src/rules/S7059/meta.ts
#	packages/jsts/src/rules/S7060/meta.ts
#	packages/jsts/src/rules/S881/meta.ts
#	packages/jsts/src/rules/S888/meta.ts
#	packages/jsts/src/rules/S905/meta.ts
#	packages/jsts/src/rules/S930/meta.ts
#	packages/jsts/src/rules/core/index.ts
#	packages/jsts/src/rules/decorated.ts
#	packages/jsts/src/rules/external.ts
#	packages/jsts/src/rules/helpers/isHtmlElement.ts
#	packages/jsts/src/rules/helpers/table.ts
#	packages/jsts/src/rules/index.ts
#	packages/jsts/src/rules/original.ts
#	packages/jsts/src/rules/plugin.ts
#	packages/jsts/src/rules/typescript-eslint/index.ts
#	packages/jsts/tests/rules/index.test.ts
#	tools/check-distribution-filepath-length.cjs
#	tools/generate-meta.ts
# Conflicts:
#	packages/jsts/src/rules/README.md
#	packages/jsts/src/rules/S2068/meta.ts
#	packages/jsts/src/rules/original.ts
#	packages/jsts/src/rules/plugin.ts
# Conflicts:
#	packages/jsts/src/rules/README.md
#	packages/jsts/src/rules/S2068/meta.ts
#	packages/jsts/src/rules/original.ts
#	packages/jsts/src/rules/plugin.ts
@vdiez vdiez changed the base branch from master to remove-decorated-eslint November 27, 2024 10:28
@kebetsi
Copy link
Contributor Author

kebetsi commented Nov 27, 2024

@vdiez Can you include rule parameters in the java check template, as I did create the corresponding test file?
Also, could you handle the issue of generate-meta updating all metas with double quotes instead of single?

@vdiez
Copy link
Contributor

vdiez commented Nov 27, 2024

yes, I was planning to update the java template. single-quotes is already done in the base of this PR

vdiez and others added 2 commits November 28, 2024 11:28
Co-authored-by: zglicz <michal.zgliczynski@sonarsource.com>
Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com>
vdiez and others added 2 commits November 28, 2024 11:50
Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com>
@vdiez
Copy link
Contributor

vdiez commented Nov 28, 2024

seems the code coverage is not working very well, I don't think that can be improved if it counts the class declaration

@ericmorand-sonarsource
Copy link
Contributor

Do we want to track generated files? I assumed that the point was to not track them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vdiez Could you consider rewriting the git history of this pull request? It would really help to have a single commit for each aspect, as reviewing the entire pr is challenging (my web browser is struggling to keep up).

On another note, we now have the following list of tools:

  • count-rules.js
  • external-rules-metadata.js
  • generate-external-rules-docs.ts
  • generate-meta.ts
  • generate-rule-indexes.ts
  • generate-rules-list.js
  • new-rule.mts
  • prepare-ruling.js

While the name of a tool provides an idea of its purpose, most of them are missing a brief introductory comment at the top of each script. More importantly, it's not easy to tell what is the expected outcome, output, or side effects. Ideally, creating a README.md file in this folder could help provide more context about the general workflow of how rule creation works.

Overall, I feel like we are lacking comments on both older and new scripts, and there is too much tribal knowledge within these scripts.

@vdiez
Copy link
Contributor

vdiez commented Nov 29, 2024

@yassin-kammoun-sonarsource , I agree, but this PR was originally about the new-rule and it expanded well above its scope, refactoring and improving other scripts as well. I can take care of all the rest as you propose and add documentation.

About git history, I'll do that as well.

@ericmorand-sonarsource good point, I will ignore all generated-meta.ts files as well and add it to scripts/prepare

@vdiez
Copy link
Contributor

vdiez commented Nov 29, 2024

Cleaned up git history and added generated-meta.ts to git ignore

I will remove unused scripts in another PR:

  • external-rules-metadata.js
  • generate-rules-list.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good on my side. Thank you for the comments.
This will really make easy getting rid of the Java classes.

Base automatically changed from remove-decorated-eslint to master November 29, 2024 14:17
Copy link
Contributor

@zglicz zglicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some random comments from me

@@ -29,7 +29,7 @@
"plugin:build:fast": "mvn install -DskipTests && npm run update-ruling-data",
"pbf": "npm run plugin:build:fast",
"td": "npm --prefix typedoc/searchable-parameters-plugin run setup && npx typedoc --options typedoc/typedoc.js",
"prepare": "husky install && npm run create-rule-indexes",
"prepare": "husky install && npm run generate-meta",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems this is not based on latest master, husky shouldn't have install

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #4969

Comment on lines +25 to +26
for (const file of await listRulesDir()) {
await generateMetaForRule(file);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what the proper art is, but usually you shouldn't have await in a for loop. Better to hand it off to the language to manage these promises. As in:

Suggested change
for (const file of await listRulesDir()) {
await generateMetaForRule(file);
Promise.all((await listRulesDir()).map( async (file) => await generateMetaForRule(file)));

Come to think of it, we didn't have many rules/lints in PHP/Hack, but not having await's in loops was one of them. Usually as you were looping though friends lists or photos to retrieve some data, as its a slow operation (DB reads), having it in an abstract map was one of the rules.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree here... i prefer to do sequential to not launch 1k+ read IO at the same time.

* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
* Java index:
* sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/AllChecks.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! forgetting updating this was then always failing the test AllChecksTest. Can we then remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's on gitignore now

Comment on lines +29 to +43
export const METADATA_FOLDER = join(
DIRNAME,
'..',
'sonar-plugin',
'javascript-checks',
'src',
'main',
'resources',
'org',
'sonar',
'l10n',
'javascript',
'rules',
'javascript',
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙄

@@ -0,0 +1,16 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this have a .ts extension? Not sure what other extension would be better, but .ts isn't good at all. If someone starts writing Typescript code in there, wouldn't be good ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want that the maven license update script updates the header in this file, so that the autogenerated scripts get the new header out of the box

/**
* Inflate string template with given dictionary
* @param text template string
* @param dictionary object with the keys to replace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keys are regexp expressions?

*/
export function inflateTemplate(text: string, dictionary: { [x: string]: string }): string {
for (const tok in dictionary) {
text = text.replace(new RegExp(escapeRegExp(tok), 'g'), dictionary[tok]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to conform to a regexp? Would this work without the wrapping in regex?

Copy link
Contributor

@vdiez vdiez Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, placeholders are just normal strings like ___HEADER___

/**
* From the RSPEC json file, creates a generated-meta.ts file with ESLint formatted metadata
*
* @param sonarKey rule ID for which we need to create the generated-meta.ts file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sonarKey is the SXXX format? Might be nice to add an example in the code

Suggested change
* @param sonarKey rule ID for which we need to create the generated-meta.ts file
* @param sonarKey rule ID ("SXXX") for which we need to create the generated-meta.ts file

Comment on lines +147 to +151
if (await exists(schemaFile)) {
try {
schema = `\nimport type { JSONSchema4 } from '@typescript-eslint/utils/json-schema';\nexport const schema = ( ${await readFile(schemaFile, 'utf-8')} ) as const satisfies JSONSchema4;`;
} catch {}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, impressive one can do an await in `` (backticks) throwing an exception that you swallow..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean it in a good impressive or bad impressive?

const files = await readdir(javaChecksPath('main'), { withFileTypes: true });
return files
.filter(file => ruleRegex.test(file.name) && !file.isDirectory())
.map(file => file.name.slice(0, -5)) // remove .java extension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, -5, nice that that works

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
80.1% Coverage on New Code (required ≥ 90%)

See analysis details on SonarQube

@vdiez vdiez closed this Nov 29, 2024
@vdiez vdiez deleted the fix-new-rule branch November 29, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants