feat(core/formatters): support variable resolution in replace() first argument#793
feat(core/formatters): support variable resolution in replace() first argument#793Viren070 merged 6 commits intoViren070:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis change makes replace(...) resolve inner Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/formatters/base.ts`:
- Around line 899-917: The dynamic replace path can resolve a formatter variable
to an empty string and then call variable.replaceAll('', replaceKey), which
inserts replaceKey between every character; in the replace handling in base.ts
(the branch using shouldBeUndefined, key, replaceKey and
parseModifiedVariable/parseValue) add a guard after resolving resolvedKey: if
resolvedKey is an empty string, short-circuit and return the original variable
(no-op) instead of calling variable.replaceAll; keep existing behavior for
non-empty resolvedKey and preserve use of parseModifiedVariable/parseValue.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2c7bdc5b-b11e-4a3b-905c-54003377c1ea
📒 Files selected for processing (1)
packages/core/src/formatters/base.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/formatters/base.ts`:
- Around line 899-920: The code currently falls back to using the literal
"{...}" placeholder as the search key when parseModifiedVariable resolution
fails, which can silently become a no-op or corrupt strings; inside the branch
that handles key.startsWith('{') && key.endsWith('}') replace the current
swallowing logic with an explicit guard: after calling
this.parseModifiedVariable(innerVar, fullStringModifiers) and invoking
resolvedFn(parseValue), if resolved.error is present OR resolved.result == null
then return variable immediately (do not proceed to replaceAll); only set
resolvedKey = String(resolved.result) and continue if resolved.result is
non-null and non-empty, otherwise return variable to avoid empty-string
replacement. Ensure this change is applied where resolvedKey, resolved,
parseModifiedVariable, and variable.replaceAll are referenced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 47256978-f181-41b0-84c7-838f30e83fc1
📒 Files selected for processing (1)
packages/core/src/formatters/base.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/formatters/base.ts`:
- Around line 899-921: The guard allowing malformed splits should be tightened:
in the replace-argument handling (the block using variables key, replaceKey,
shouldBeUndefined inside the formatter method that calls
this.parseModifiedVariable and ultimately does variable.replaceAll), change the
condition from if (!shouldBeUndefined && key && replaceKey !== undefined) to
require shouldBeUndefined === undefined (or implement a small top-level scanner
to parse the two arguments instead of content.split), so that quoted/nested
commas (e.g., replace('{stream.title::replace('.', ' ')}', '')) do not slip
through and produce broken key/replaceKey fragments; ensure the rest of the
logic (resolving {var} via this.parseModifiedVariable, checking
resolved.error/result, and using resolvedKey.length check before
variable.replaceAll) remains the same.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 04e2e25d-f68a-4530-a7c6-055e8b10d840
📒 Files selected for processing (1)
packages/core/src/formatters/base.ts
|
Hi @Viren070! I've addressed all the CodeRabbit suggestions. Could you take a look when you have a chance? Thanks! |
This feature makes the replace method work with any formatter variable, such as {stream.title}, {addon.name} etc...
This might be useful for any person who wants to take their custom formatter any step forward.
AS IS
filename: Movie.Title.2023.2160p.BluRay.HEVC.DV.TrueHD.Atmos.7.1.iTA.ENG-GROUP.mkv{stream.filename::replace('.', ' ')::replace('{stream.title}', '')}replaces all the dots with a whitespace but it doesn't replace the stream title (Movie Title in this case) with an empty stringTO BE
filename: Movie.Title.2023.2160p.BluRay.HEVC.DV.TrueHD.Atmos.7.1.iTA.ENG-GROUP.mkv{stream.filename::replace('.', ' ')::replace('{stream.title}', '')}replaces all the dots with a whitespace and it does replace the stream title (Movie Title in this case) with an empty string.So it will result in
2023 2160p BluRay HEVC DV TrueHD Atmos 7 1 iTA ENG-GROUP mkvResolves #790
Summary by CodeRabbit