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

Create rule S6354: Testable date/time provider should be used #285

Merged
merged 9 commits into from
Feb 25, 2022

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 30, 2021

You can preview this rule here (updated a few minutes after each push).

This rule has been suggested by Corniel on SonarSource/sonar-dotnet#4207

@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Create rule S6354 Create rule S6354: Testable date/time provider should be used. Sep 2, 2021
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Create rule S6354: Testable date/time provider should be used. Create rule S6354: Testable date/time provider should be used Sep 2, 2021
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Create rule S6354: Testable date/time provider should be used Create rule S6354: Testable date/time providers should be used Sep 2, 2021
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Create rule S6354: Testable date/time providers should be used Create rule S6354: Testable date/time provider should be used Sep 2, 2021
Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a comment

Choose a reason for hiding this comment

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

Please take a look at my comments. Maybe they make sense and maybe not :)

@@ -0,0 +1,20 @@
FIXME: add a description
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional to cover apex, go, java, kotlin, PHP, python, ruby, scala, and swift ? Do you plan to add rule descriptions for all these languages?

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK whenever we create a rule, we should add all languages for which it applies. This way everyone can look at which rules are already specified for a particular language.

The downside of this is needing to create rule descriptions to all languages at once.

I will try to find a generic description, however I won't be able to create code snippets for all.

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 think you need to add all languages the rule applies to from the first PR. You can always extend the existing rule later.
Merging this PR, in addition to the useful rspec for .Net languages, will bring multiple unfinished rspecs to master. These unfinished rspecs will have no value, so they will dilute the valuable rules in this PR with irrelevant code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with you and if we consider how JIRA was used :

  1. you had an RSPEC which was applicable to N languages.
  2. When you wanted to add new rules for a language, you would look into the existing, already specified rules applicable to language X.
  3. You would then create a JIRA sub-task for language X where you would customize the rule - usually with the Noncompliant and Compliant cases.

So I added all the tags to be able to keep the same workflow as before - I didn't know of a different option.

I can remove the files from the repo to avoid noise, however I need to be able to search for all the rules which are not_covered but are applicable to language X. I imagine I can do this via github labels, but this is frail and not reflected in the versioning system. Also, it is not searchable locally (which is one of the benefits of having the rspec as github repo).

Do we have any option to keep the same workflow? We'd need another piece of metadata to allow to search which rules are applicable to language X (but not yet implemented, nor specified for language X).

LE: I guess just keeping the github labels is good enough for now.

Later LE: But wait - when this PR gets merged, we lose this information.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was not aware of a workflow for searching for "applicable but not specified / underspecified for a language" rules. In CFamily bubble we keep a backlog of tickets with rule ideas that wait for a specification sprint.

If you think rspec should be able to help with this use case, then you need some kind of a marker (a metadata field?) that designates incomplete rspecs. I believe this issue needs a deeper thought and an explicit policy.
AFAIK, right now not everyone would preallocate a rspec for every language it is applicable to when specifying a rule for one particular language. Hence, your search for "applicable but underspecified" rules will be incomplete.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The conclusion was that the Languages Team doesn't need this usecase.

I will keep only C# and VB .NET

Public Function UtcNow() As Date
End Function

Public Function SetTimeForCurrentThread(ByVal time As Func(Of Date)) As IDisposable
Copy link
Contributor

Choose a reason for hiding this comment

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

ByVal is an optional keyword that is advised not to use.

We've discussed and in codebases where this approach was not adopted from the beginning, there may be reluctancy to change it and it may be considered as noise.
Copy link
Contributor

@Corniel Corniel left a comment

Choose a reason for hiding this comment

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

Taking the small remark I made aside, this LGTM.

@andrei-epure-sonarsource
Copy link
Contributor

should not be merged before SonarSource/sonar-dotnet#4207

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-frontend'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-tools'

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants