Loading...
Loading...
Guide for writing inline comments and JSDoc in the codebase. Use when generating code for bug fixes, new components, refactoring, or feature implementation.
npx skill4agent add rakaadi/agent-kit art-of-comment/** ... */// (1) Calculate chart segments based on priority: verified > registered > rejected
const getChartSegments = (): {
value: number
color: string
backgroundColor?: string
badgeLabel?: string
}[] => {
const verified = data?.verified ?? 0
const registered = data?.registered ?? 0
const rejected = data?.rejected ?? 0
const total = verified + registered + rejected
// (2) If all values are 0, show full gray circle
if (total === 0) {
return [{ value: 1, color: colors.palette.lightGray }]
}
// (3) Filter out zero values to prevent empty segments
const segments = []
// (4) Priority order: verified > registered > rejected
if (verified > 0) {
segments.push({
value: verified,
color: '#01C58A',
backgroundColor: '#D6F6EC',
badgeLabel: `${verified} Aset Terdata`,
})
}
if (registered > 0) {
segments.push({
value: registered,
color: '#FF9E00',
backgroundColor: '#FFF1DB',
badgeLabel: `${registered} Belum Diverif`,
})
}
if (rejected > 0) {
segments.push({
value: rejected <= 2 ? 2 : rejected, // (5) Minimum visible segment size of 2
color: '#FF5264',
backgroundColor: '#FFECEC',
badgeLabel: `${rejected} Ditolak`,
})
}| # | Verdict | Why |
|---|---|---|
| 1 | Good intent, wrong syntax. Clearly summarizes purpose and priority order — but should use | |
| 2 | Remove. The condition and return value are self-explanatory; the comment adds nothing. | |
| 3 | Borderline. States the obvious, but may be acceptable as a signpost when debugging segment logic — acceptable only if it conveys intent the code cannot. | |
| 4 | Remove — duplicates (1). The priority order is already documented above; repeating it creates a maintenance burden. Reference the earlier comment if needed. | |
| 5 | Good. Concisely explains a non-obvious workaround and its effect. |