-
Notifications
You must be signed in to change notification settings - Fork 4
fix: if json variable, use stringified value for reco #551
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
Conversation
There was a problem hiding this 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 fixes handling of JSON-type variables in the stale variable recommendation system by stringifying JSON values before displaying them in code comments.
Key changes:
- Added JSON stringification for recommended values when variable type is 'JSON'
- Fixed a bug where falsy values (false, 0, "") were incorrectly replaced with defaultValue by changing
||to??operator
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
414d35d to
559dd35
Compare
559dd35 to
d971171
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const indentation = indent ? ' ' : '' | ||
| const jsonString = JSON.stringify(parsed, null, 4) | ||
| return ( | ||
| '\n' + | ||
| jsonString | ||
| .split('\n') | ||
| .map((line) => | ||
| line ? indentation + line : line, | ||
| ) | ||
| .join('\n') + | ||
| '\n' | ||
| ) |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation logic doesn't add the comment prefix (' * ') that's required for block comments. The blockComment function expects staleWarning to be formatted as a single line with the comment prefix already applied (see line 41 in blockComment). The current implementation adds indentation but not the ' * ' prefix needed for multi-line comment content. This will result in malformed JSDoc comments when the recommended value is a JSON object.
| '\n' | ||
| ) | ||
| } | ||
| } catch { |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty catch block silently ignores JSON parsing errors. While this might be intentional as a fallback mechanism, it would be better to add a comment explaining why parsing errors are being ignored, or at minimum add an empty comment to make it clear the empty block is intentional.
| } catch { | |
| } catch { | |
| // If JSON parsing fails, fall back to using the raw recommendedValue. |
| const value = | ||
| releaseVariation?.variables?.[variable.key] ?? | ||
| variable.defaultValue |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from the logical OR operator (||) to the nullish coalescing operator (??) changes the behavior. The || operator would use defaultValue for any falsy value (0, false, '', null, undefined), while ?? only uses it for null or undefined. This means if releaseVariation?.variables?.[variable.key] is 0, false, or '', the old code would have used defaultValue but the new code will use the falsy value. Ensure this behavioral change is intentional.
Changes