Skip to content

Conversation

@minichma
Copy link
Collaborator

@minichma minichma commented May 2, 2025

Modernize some code in RecurrencePatternEvaluator, including

  • Avoid .ToList() in favor of simpler generator based patterns
  • Use Linq where appropriate
  • Split up complex methods
  • Make methods static where possible

As a result the code gets simpler, more readable and we achieve the same functionality with less code and execution branches.

… pattern evaluation by making more use of the generator pattern.
@codecov
Copy link

codecov bot commented May 2, 2025

Codecov Report

Attention: Patch coverage is 89.39394% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
Ical.Net/Evaluation/RecurrencePatternEvaluator.cs 91% 3 Missing and 9 partials ⚠️
Ical.Net/Evaluation/EvaluationException.cs 33% 2 Missing ⚠️

❌ Your project status has failed because the head coverage (66%) is below the target coverage (80%). You can increase the head coverage or adjust the target coverage.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #783   +/-   ##
===================================
- Coverage    66%    66%   -0%     
===================================
  Files       104    105    +1     
  Lines      4495   4438   -57     
  Branches   1140   1115   -25     
===================================
- Hits       2969   2912   -57     
- Misses     1061   1062    +1     
+ Partials    465    464    -1     
Files with missing lines Coverage Δ
Ical.Net/Evaluation/EvaluationException.cs 33% <33%> (ø)
Ical.Net/Evaluation/RecurrencePatternEvaluator.cs 91% <91%> (-1%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@minichma minichma force-pushed the work/minichma/feature/eval_generator_improvements branch from f257d4e to 8869f89 Compare May 2, 2025 14:01
@minichma minichma force-pushed the work/minichma/feature/eval_generator_improvements branch from 8869f89 to 38727d8 Compare May 2, 2025 14:26
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 2, 2025

@minichma minichma marked this pull request as ready for review May 2, 2025 14:50
@minichma minichma requested a review from Copilot May 2, 2025 14:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modernizes the evaluation code in RecurrencePatternEvaluator by simplifying code patterns and reducing complexity. The changes improve clarity and reduce unnecessary code branches.

  • Removed unneeded .ToList() calls in favor of generator-based patterns
  • Refactored methods using LINQ and separated complex logic into simpler static methods

if (r.ByHour?.Count > 0) r.ByHour = r.ByHour.OrderBy(x => x).ToList();
if (r.ByMonth?.Count > 0) r.ByMonth = r.ByMonth.OrderBy(x => x).ToList();

return r;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


foreach (var d in monthDayDates)
yield return d;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@axunonb axunonb left a comment

Choose a reason for hiding this comment

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

Very nice, tnx!

@minichma minichma merged commit 1771d99 into main May 6, 2025
8 of 9 checks passed
@minichma minichma deleted the work/minichma/feature/eval_generator_improvements branch May 6, 2025 09:54
@minichma
Copy link
Collaborator Author

minichma commented May 6, 2025

Thanks for the review!

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.

3 participants