Skip to content

ReplaceWeekYearWithYear should not replace valid week-year usages#801

Merged
timtebeek merged 3 commits intoopenrewrite:mainfrom
tginsberg:fix-800-replaceweekyearwithyear-should-ignore-some-cases
Jan 3, 2026
Merged

ReplaceWeekYearWithYear should not replace valid week-year usages#801
timtebeek merged 3 commits intoopenrewrite:mainfrom
tginsberg:fix-800-replaceweekyearwithyear-should-ignore-some-cases

Conversation

@tginsberg
Copy link
Contributor

@tginsberg tginsberg commented Jan 2, 2026

What's changed?

This is a failing test case against issue #800

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

- Failing test case for ReplaceWeekYearWithYear when used with week-year
  and week of year
- When `w` (week in year) is detected and we are not inside quotes, abandon replacement and return the original `input`.
- Also simplified `replaceY`, which had a redundant else-if branch.
@timtebeek timtebeek self-requested a review January 3, 2026 11:14
@timtebeek
Copy link
Member

Great to see, thanks! Sharing the notes you left on the commit here as well to make those easier to find:

  • When w (week in year) is detected and we are not inside quotes, abandon replacement and return the original input.
  • Also simplified replaceY, which had a redundant else-if branch.

@timtebeek timtebeek added the bug Something isn't working label Jan 3, 2026
@timtebeek timtebeek changed the title 800: Failing test case ReplaceWeekYearWithYear should not replace valid week-year usages Jan 3, 2026
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Jan 3, 2026
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the help here @tginsberg ; Nice simplification & bug fix. Guess this was the best week of the year for discovery & fix. All the best there!

@timtebeek timtebeek marked this pull request as ready for review January 3, 2026 12:23
@timtebeek timtebeek merged commit 2a88748 into openrewrite:main Jan 3, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Jan 3, 2026
@tginsberg
Copy link
Contributor Author

Thanks for making contributing so easy @timtebeek! I was writing a blog post on week year and was covering how to fix it and noticed this aspect of the rule. I figured it was a good chance to contribute, in a small way, to a project I admire so much. Thanks for accepting my fix! :)

@tginsberg tginsberg deleted the fix-800-replaceweekyearwithyear-should-ignore-some-cases branch January 3, 2026 13:42
@timtebeek
Copy link
Member

timtebeek commented Jan 3, 2026

Thanks for the kind words & help! Linking your post here for others interested as well:

We'll put out a new release in the coming days that contains your fix.

mergify bot added a commit to robfrank/linklift that referenced this pull request Jan 9, 2026
… 2.24.0 to 2.25.0 [skip ci]

Bumps [org.openrewrite.recipe:rewrite-static-analysis](https://github.com/openrewrite/rewrite-static-analysis) from 2.24.0 to 2.25.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-static-analysis's releases](https://github.com/openrewrite/rewrite-static-analysis/releases).*

> 2.25.0
> ------
>
> What's Changed
> --------------
>
> * `ReplaceWeekYearWithYear` should not replace valid week-year usages by [`@​tginsberg`](https://github.com/tginsberg) in [openrewrite/rewrite-static-analysis#801](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/801)
>
> New Contributors
> ----------------
>
> * [`@​tginsberg`](https://github.com/tginsberg) made their first contribution in [openrewrite/rewrite-static-analysis#801](https://redirect.github.com/openrewrite/rewrite-static-analysis/pull/801)
>
> **Full Changelog**: <openrewrite/rewrite-static-analysis@v2.24.0...v2.25.0>


Commits

* [`f51717c`](openrewrite/rewrite-static-analysis@f51717c) Extract documentation examples from tests
* [`57ea9bb`](openrewrite/rewrite-static-analysis@57ea9bb) Update documentation examples
* [`736160d`](openrewrite/rewrite-static-analysis@736160d) Minimize duplicate logic & traversal in `NestedEnumsAreNotStatic`
* [`2a88748`](openrewrite/rewrite-static-analysis@2a88748) `ReplaceWeekYearWithYear` should not replace valid week-year usages ([#801](https://redirect.github.com/openrewrite/rewrite-static-analysis/issues/801))
* [`e552501`](openrewrite/rewrite-static-analysis@e552501) Update recipe documentation examples
* [`7529320`](openrewrite/rewrite-static-analysis@7529320) Generate a recipes.csv for the recipes defined in this repository
* See full diff in [compare view](openrewrite/rewrite-static-analysis@v2.24.0...v2.25.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-static-analysis&package-manager=maven&previous-version=2.24.0&new-version=2.25.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

ReplaceWeekYearWithYear incorrectly replaces valid week-year usages

2 participants