Fixed code smell in src/posts/topics.js: Function with many parameters (count = 5): getPostsFromSet#327
Fixed code smell in src/posts/topics.js: Function with many parameters (count = 5): getPostsFromSet#327
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors a Posts helper in src/posts/topics.js to address static-analysis code smell warnings by reducing parameter count and removing a shadowed variable in post path generation.
Changes:
- Refactored
Posts.getPostsFromSetto take a destructured options object (and defaultreversetofalse). - Renamed an inner
indexvariable inPosts.generatePostPathsto avoid shadowing the map callback parameter.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| Posts.getPostsFromSet = async function ({ set, start, stop, uid, reverse = false }) { | ||
| const pids = await Posts.getPidsFromSet(set, start, stop, reverse); | ||
| const posts = await Posts.getPostsByPids(pids, uid); | ||
| return await user.blocks.filter(uid, posts); |
There was a problem hiding this comment.
Changing Posts.getPostsFromSet from positional args to a destructured options object is a breaking API change for any external consumers (e.g. plugins importing src/posts). It can also fail silently if a caller still passes the old (set, start, stop, uid, reverse) signature, because destructuring will yield undefined for set/start/... and then query the wrong sorted set. Consider keeping backwards compatibility by accepting both calling conventions (detect object vs non-object), or introducing a new method name for the options-object signature and leaving the existing one intact (with a deprecation path).
Fix Code Smells in topics.js
Problem
Static analysis (
qlty smells) flagged two code quality issues in topics.js:getPostsFromSethad 5 positional parameters (set,start,stop,uid,reverse), making call sites fragile and argument order easy to mix up.generatePostPaths, the innerconst indexshadowed the outer.map()callback parameterindex, creating a subtle readability hazard and potential source of confusion.Solution
getPostsFromSetto accept a single destructured options object, reducing the parameter count from 5 to 1 and making call sites self-documenting. Added a safe default offalsefor the optionalreverseparameter.generatePostPathsfromindextopostIndexSuffixto eliminate the ambiguity.Changes Made
getPostsFromSet— parameter refactor:generatePostPaths— variable shadowing fix:Files Changed
Implementation Notes
getPostsFromSetexist in the codebase (confirmed via full repo search), so there are no downstream call sites to update.getPostsFromSetis unchanged — destructuring extracts the same named variables, so internal behaviour is identical.reverse = falsedefault matches the logical expectation: callers that omitreverseget forward (non-reversed) ordering, consistent with the original intent.generatePostPathsfix is purely a rename — no logic change.Testing