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

Clean code attributes and better descriptions complying with Sonar Coding rule guidelines #349

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

pbaumard
Copy link

@pbaumard pbaumard commented Aug 9, 2024

Ensures the Sonar Coding rule guidelines for rule specifications are followed with tests. This should avoid most of the comments made by Sonar reviewers, e.g. in ecocode plugin request or ecocode js plugin request:

It will improve the user experience when using Creedengo plugins. All the differences from the standard Sonar rules are still stricking me when I use the rules: the wrong Clean Code attributes, the weird rule titles format, non standard sections in descriptions, etc.
This may give a bad first impression to many Creedengo users and may discourage the use of Creedengo plugins.
SonarQube is a code quality solution so its users typically care a lot about consistency.

To be honest I am quite suprised that Sonar does not ensure that the Community plugins comply with the Sonar Coding rule guidelines. Maybe plugins will have to comply in the future.

@dedece35
Copy link
Member

dedece35 commented Aug 11, 2024

pbaumard

Hi @pbaumard ,

thank you for this PR ... very interesting but a lot of modifications.
Can you give us your reference documentation to prove or support your proposition ?

Furthermore, your build is not ok on github action ... please make a correction for it.
In my local machine (Mac OS), when I launch your unit test, I have a different error :

[INFO] Running fr.greencodeinitiative.RulesTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.506 s <<< FAILURE! -- in fr.greencodeinitiative.RulesTest
[ERROR] fr.greencodeinitiative.RulesTest.testRules -- Time elapsed: 0.018 s <<< FAILURE!
org.opentest4j.AssertionFailedError: array contents differ at index [0], expected: <csharp> but was: <python>

please check it in your local machine.

Last question : why is your PR in Draft mode ? Do you still want to work on it ?

@dedece35 dedece35 added 🗒️ documentation Improvements or additions to documentation 🚀 enhancement New feature or request 🏗️ refactoring refactoring for best practices 🔥 in progress 🔥 👀 👀 waiting commiter 👀 👀 labels Aug 11, 2024
@pbaumard pbaumard marked this pull request as ready for review September 4, 2024 08:01
@pbaumard
Copy link
Author

pbaumard commented Sep 4, 2024

This PR is now ready for review.

@pbaumard
Copy link
Author

@dedece35 Any chance to get this PR reviewed?

It would then be necessary to update all plugins.
Android plugin would neeed to migrate to ecoCode rule specifications: green-code-initiative/ecoCode-android#79

@dedece35
Copy link
Member

@dedece35 Any chance to get this PR reviewed?

It would then be necessary to update all plugins. Android plugin would neeed to migrate to ecoCode rule specifications: green-code-initiative/ecoCode-android#79

hello ... thank you for the work ... review in progress !

Copy link
Member

@utarwyn utarwyn left a comment

Choose a reason for hiding this comment

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

Thank you for this huge work!
I did a quick tour on HTML/JavaScript rules changes, it seems good overall 👍

But I'm wondering if this PR isn't too large... it's really huge and I can't see myself going through all the changes without spending half a day on it..

----

=== Compliant solution

We recommend using the following formats:
Copy link
Member

Choose a reason for hiding this comment

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

Why this section is now in "Compliant solution"?

Copy link
Author

Choose a reason for hiding this comment

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

The section change was reverted.

"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
]
}
}
Copy link
Member

Choose a reason for hiding this comment

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

There must be an empty line at the end of the file

Copy link
Member

Choose a reason for hiding this comment

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

@utarwyn, why is an empty line mandatory ? if not present, the system doesn't work ?
if yes, @pbaumard, please make the correction for all empty lines deleted at the end of this kind of files.

Copy link
Author

@pbaumard pbaumard Sep 25, 2024

Choose a reason for hiding this comment

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

I added the spotless plugin to check newlines for all json files. This is just a matter of consistency.

@@ -11,25 +11,33 @@ However, even without autoplay, segments of video or audio files might still dow
This leads to unnecessary data usage, especially if users don't commence playback.
To mitigate this, it's crucial to prevent browsers from preloading any content by configuring the appropriate settings.

Video:
== How to fix it in video
Copy link
Member

Choose a reason for hiding this comment

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

I think both section names are wrong here, we do not provide a video to explain how to fix the problem

Suggested change
== How to fix it in video
== How to fix a video element

Copy link
Author

Choose a reason for hiding this comment

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

Those section titles were changed in latests commits.

@@ -63,6 +69,11 @@ Location.requestPermissionsAsync(); // Compliant

== Resources

=== Best practises

- https://github.com/cnumr/best-practices-mobile[Mobile-specific Best Practices] by https://collectif.greenit.fr/index_en.html[CNumR]
Copy link
Member

Choose a reason for hiding this comment

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

Do you have a more precise source?

Copy link
Author

Choose a reason for hiding this comment

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

This is the same source as the java version of EC523. Do you have a better source?

@dedece35
Copy link
Member

HI @zippy1978 and @olegoaer,
could you please make a review on all modifications done for EC5XX et and EC6XX, please ?

@@ -1,11 +1,16 @@
{
"title": "Sobriety: Thrifty Geolocation (minTime)",
Copy link
Member

Choose a reason for hiding this comment

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

why do you delete the title ? maybe refactor it like done in another updates of this PR, no ?

Copy link
Author

Choose a reason for hiding this comment

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

The title seems useless since it is redefined in the JSON of all EC523 subdirectories, so this title would always be overriden, right?

"tags": [
"sobriety",
Copy link
Member

Choose a reason for hiding this comment

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

why do you delete "sobriety" ?

Copy link
Author

Choose a reason for hiding this comment

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

At first I thought sobriety was too close to existing eco-design or performance tags. I later changed my mind to include all tags from https://github.com/cnumr/best-practices-mobile

sobriety tag removal was reverted in latests commits.

"tags": [
"sobriety",
Copy link
Member

Choose a reason for hiding this comment

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

why do you delete "sobriety" tag on several updates ?

Copy link
Author

Choose a reason for hiding this comment

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

See above reply in #349 (comment)


SWITCH statement solution + refactor solution
With a `switch`:
Copy link
Member

Choose a reason for hiding this comment

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

here, please add the explanation like done in python and PHP files

Copy link
Author

Choose a reason for hiding this comment

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

Done in latest commits.


== Resources

Reference/Validation is unknown.
Copy link
Member

Choose a reason for hiding this comment

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

maybe move above link to here

Copy link
Author

Choose a reason for hiding this comment

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

Done in latest commits.


SWITCH statement solution + refactor solution
With a `switch`:
Copy link
Member

Choose a reason for hiding this comment

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

here, please add the explanation like done in python and PHP files

Copy link
Author

Choose a reason for hiding this comment

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

Done in latest commits.

@@ -1,5 +1,5 @@
{
"title": "Do not call a function when declaring a for-type loop",
"title": "Functions should not be called when declaring a for-type loop",
Copy link
Member

Choose a reason for hiding this comment

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

please update title description to be clearer : please, replace “when declaring a for-loop type” by “inside a for-loop condition”

Copy link
Author

Choose a reason for hiding this comment

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

Done in latest commit.

"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
]
}
}
Copy link
Member

Choose a reason for hiding this comment

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

@utarwyn, why is an empty line mandatory ? if not present, the system doesn't work ?
if yes, @pbaumard, please make the correction for all empty lines deleted at the end of this kind of files.

@@ -94,13 +94,56 @@
</issueManagement>

<properties>
<java.version>11</java.version>
Copy link
Member

Choose a reason for hiding this comment

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

all these pom.xml modifications must be in the ecocode-rules-specifications pom.x instead and the current parent pom.xml

all other plugins work with java 17. why do you put java 11 ?

Copy link
Author

Choose a reason for hiding this comment

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

POM changes have been moved to ecocode-rules-specifications.

Some of the configuration, including java 11 is coming from
https://github.com/green-code-initiative/ecoCode-java/blob/main/pom.xml

Java version could be changed.

@@ -0,0 +1,263 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

I'm ok to create a new Test class to check all files and all rules. but I think we can do it simplier, maybe.
I will run your test class and give my feedback soon.

Copy link
Author

Choose a reason for hiding this comment

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

@dedece35 Did you have time to review the test class?

@@ -3,15 +3,10 @@
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
Copy link
Member

Choose a reason for hiding this comment

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

did you test your modification in a local SonarQube to check if the description is well displayed ?

Copy link
Author

Choose a reason for hiding this comment

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

Those func attribute changes were reverted.

@pbaumard
Copy link
Author

review in progress !

@dedece35 Any progress on the review?

I don't see any point waiting for me.
Please remove the label "waiting commiter" to clarify this PR status.

@pbaumard
Copy link
Author

@dedece35 It seems all the PR builds are failing because of a "401 Unauthorized" error on the Sonar server:

Error: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:5.0.0.4389:sonar (default-cli) on project creedengo-rules-specifications: Error status returned by url [https://api.sonarcloud.io/analysis/jres?os=linux&arch=x86_64]: 401

Note that PRs are also failing for the same reason on other repositories, e.g. on creedengo-java:
https://github.com/green-code-initiative/creedengo-java/actions/runs/12127895160/job/33813144041

pom.xml Outdated
@@ -1,470 +1,594 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
Copy link
Member

Choose a reason for hiding this comment

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

sorry, but why do you want to modify XML formatting ? we use default XML formatting from IntelliJ : tabulation = 4 spaces

pom.xml Outdated
<scm>
<connection>scm:git:https://github.com/green-code-initiative/creedengo-rules-specifications</connection>
<developerConnection>scm:git:https://github.com/green-code-initiative/creedengo-rules-specifications</developerConnection>
<tag>HEAD</tag>
Copy link
Member

Choose a reason for hiding this comment

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

why do you want these minor modifications ?

pom.xml Outdated
-->
<revision>current-SNAPSHOT</revision>
<properties>
<!-- Default version when disabling Maven `maven-git-versioning-extension`
Copy link
Member

Choose a reason for hiding this comment

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

why not ... but if you do these kind of modifications, we will have a lot of modifications ... I remain doubtful about these modifications.
for me, it's more readable with old comment mode.

pom.xml Outdated
<executions>
<execution>
<id>convert-to-html</id>
<goals>
Copy link
Member

Choose a reason for hiding this comment

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

why do you want to change the order ?

pom.xml Outdated
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
Copy link
Member

Choose a reason for hiding this comment

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

why this move ?

pom.xml Outdated
</plugins>
</build>
</profile>
</profiles>
</project>
Copy link
Member

Choose a reason for hiding this comment

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

sorry, but pom.xml modifications are too important and disparate ...
for me, first, please make minimum modifications (adding dependencies test for example)
and secondly (in another PR, formating modifications ... on which we will discuss about veracity)

Copy link
Author

Choose a reason for hiding this comment

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

This project was not using any Java code previously so there will be anyway many changes in the POM.

The formatting changes related to Spotless sortPom are very small compared to changes related to the introduction of Java code.

@@ -1,5 +1,5 @@
{
"title": "Avoid Spring repository call in loop or stream operations",
"title": "Spring repository should not be called in loop or stream operations",
Copy link
Member

Choose a reason for hiding this comment

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

in my point of view, I prefer a turn of phrase without negation, thus, I prefer "avoid" than "should not be" ... but I can ask for the point of view of core team

Copy link
Author

@pbaumard pbaumard Jan 6, 2025

Choose a reason for hiding this comment

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

From Sonar Coding rule guidelines:

The title of the rule should match the pattern "X should [ not ] Y" for most rules. Note that the "should [ not ]" pattern is too strong for Finding rules, which are about observations on the code. Finding titles should be neutral, such as "Track x".

And as a developer I like the "X should [ not ] Y" pattern, because the expected fix is clear.
With "Avoid X" pattern sometimes it is not clear whether the code is avoiding X and it should not or the opposite, that is the code is using X and it should avoid it.

@dedece35
Copy link
Member

dedece35 commented Jan 3, 2025

Hi @pbaumard ,

as @utarwyn, sorry, but for me also, this PR is so huge ...
I have just added some comments on pom.xml ... I'm not ok with formatting modifications for example.

Sorry, to say it, but for me, I can't accept this PR with all these modifications ... mainly because there too important modifications on many files and I have so many questions / review feedbacks.
As we can see in your top description of current PR, this one deals with 5 points ... and as best practice, we should create one PR per point : like this, we can discuss more accurately inside each PR.

What do you think about it @utarwyn , @olegoaer , @glalloue, @zippy1978 , @Djoums ?

@Djoums
Copy link
Contributor

Djoums commented Jan 3, 2025

Hi @pbaumard ,

as @utarwyn, sorry, but for me also, this PR is so huge ... I have just added some comments on pom.xml ... I'm not ok with formatting modifications for example.

Sorry, to say it, but for me, I can't accept this PR with all these modifications ... mainly because there too important modifications on many files and I have so many questions / review feedbacks. As we can see in your top description of current PR, this one deals with 5 points ... and as best practice, we should create one PR per point : like this, we can discuss more accurately inside each PR.

What do you think about it @utarwyn , @olegoaer , @glalloue, @zippy1978 , @Djoums ?

I agree this PR should not be commited as is. As I can see there's a mix of issues :

  • Too many changed files at once, reviews become shallow in those cases
  • Some changes may require discussion, for ex the title wording style
  • Some changes come for the author's preference/settings

I'd split this PR by files and/or by change types (titles, tags, layout, etc).

@pbaumard
Copy link
Author

pbaumard commented Jan 6, 2025

* Too many changed files at once, reviews become shallow in those cases

The many files change are mainly just a consequence of the testing added which make the JSON complying with Sonar Coding rule guidelines. It would be quite artificial to limit the tests to a subset of files. And it would be also artificial to create many PRs all modifying many files just adre

* Some changes may require discussion, for ex the title wording style

Title wording style is coming from Sonar Coding rule guidelines

* Some changes come for the author's preference/settings

Formatting changes have been reverted and are addressed in #366

* Too many changed files at once, reviews become shallow in those cases

The many files change are mainly just a consequence of the testing added which make the JSON complying with Sonar Coding rule guidelines. It would be quite artificial to limit the tests a a subset of files.

* Some changes may require discussion, for ex the title wording style

Title wording style is coming from Sonar Coding rule guidelines

I'd split this PR by files and/or by change types (titles, tags, layout, etc).

Layout split is done in #366

Splitting by file is hard since the tests are applied to all files.

If this is split by change type, the number of files in PRs will not change.

A split would require even more work and would not limit the amount of review required.

If there is one area you think should be excluded from this PR, I could try to split it.

This PR is really just a test-driven PR applying the Sonar Coding rule guidelines.
I edited this PR description above to explain why I think this PR is important.

@pbaumard pbaumard changed the title Rule specifications normalization Complying with Sonar Coding rule guidelines Jan 7, 2025
@dedece35 dedece35 marked this pull request as draft January 12, 2025 21:48
@pbaumard pbaumard changed the title Complying with Sonar Coding rule guidelines Clean code attributes and better descriptions complying with Sonar Coding rule guidelines Jan 13, 2025
@pbaumard pbaumard marked this pull request as ready for review January 13, 2025 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏗️ refactoring refactoring for best practices 🔥 in progress 🔥 🚀 enhancement New feature or request 🗒️ documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants