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

Reducing complexity of optionConverter #2677

Merged
merged 10 commits into from
Oct 25, 2022
Merged

Reducing complexity of optionConverter #2677

merged 10 commits into from
Oct 25, 2022

Conversation

m-gallesio
Copy link
Contributor

@m-gallesio m-gallesio commented Oct 1, 2022

Please check if the PR fulfills these requirements

  • The PR is against the development branch
  • Tests for the changes have been added (for bug fixes / features)
    There is no test infrastructure ready, I ran some manual checks and they were successful.
  • Docs have been added / updated (for bug fixes / features)
    Not applicable, these are internal refactorings.
  • Does NOT modify files under the "dist" folder.

What kind of change does this PR introduce?

This restructures the option validation code to reduce its complexity.
The single switch statement was split to separate properties of an object.
Some of its branches were almost identical; they have been unified by extracting their common behaviour in parametrized helpers.
A small bug was also fixed where 24 would be considered valid in enabled/disabledHours despite not doing anything.

What is the current behavior?

See this project item which I mentioned here.

Does this PR introduce a breaking change?

As of now, it does not: since the methods I split off from optionConverter were public I kept them, redirecting to the split implementations.
I think this could be reconsidered, depending on how important they are to expose.
Due to these doubts, I have NOT updated the type definition files yet.

Other information

See these blog posts for the file splitting procedure I used:

@m-gallesio m-gallesio marked this pull request as draft October 4, 2022 19:54
@m-gallesio
Copy link
Contributor Author

m-gallesio commented Oct 4, 2022

@Eonasdan This should be substantially done, but I am moving this to draft due to the lack of tests.
I have noticed there is only one file with extremely limited coverage, and I guess something more structured would be welcome.
Before I start trying anything, do you have any preferences for potential test frameworks / tools?

If possible I would also appreciate a preliminary feedback on my chosen solution, since I have seen other points of the code which would benefit from a similar refactoring.

@Eonasdan
Copy link
Owner

Wow. Thanks for this.

As far as tests go, no. It's been on my todo list as well. I wanted to reach 6.0 release before bothering with that. The one "test" is just to make sure I don't break the TS imports lol.

@Eonasdan Eonasdan marked this pull request as ready for review October 24, 2022 19:20
@m-gallesio
Copy link
Contributor Author

We all know testing is not easy.
I will work on finalizing this, then.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    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

@m-gallesio
Copy link
Contributor Author

m-gallesio commented Oct 25, 2022

I ran some option checks and it seems to work. @Eonasdan This should be ready.
EDIT: I just noticed my note about 24 being an invalid hour value seems to be related to this issue: #2600

@Eonasdan Eonasdan merged commit 9651361 into Eonasdan:development Oct 25, 2022
@Eonasdan
Copy link
Owner

Thanks again.

Do you have a good TS testing framework?

@m-gallesio
Copy link
Contributor Author

Unfortunately no and I acknowledge this is a problem. I would rather have someone more knowledgeable chime in.

@Eonasdan
Copy link
Owner

Eonasdan commented Nov 5, 2022

@m-gallesio I added vitest and built tests around the DateTime object! It's pretty easy to use. I'm hoping to start building tests around the rest as I can

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.

2 participants