Comments

From LedgerHQ/ledger-live · View interactive version

Comments is an AI agent skill from the GitHub repository LedgerHQ/ledger-live. Replace code comments with clearer names, explainer variables and test names, and keep the rare necessary comment to one short line or a link. Read before adding, editing or reviewing a comment in any file type — `//`, `/* */` or JSDoc in code, `#` in YAML, shell, Dockerfile or config (including `.g

How to use this skill

Skill file

Comments in code

🧀 Avoid comments

Comments are _code smells_ because they go out-of-date, bloat context, and lead to confusion.

Don't reference existing comments in the codebase – follow these rules

💡 Treatments

When code isn't clear, make it clearer:

Use test names to explain non-obvious details

❌ Bad

it("diffs the current value against resolved when targeted", () => {
  const { result } = renderHook(() => useJsonEditor(makeProps()));
  act(() => result.current.setDiffTarget("resolved"));
  // Current equals resolved → every line is unchanged.
  expect(result.current.diffJson.every((l) => l.state === "none")).toBe(true);
});

✅ Good

it("resets the state of every line when the diff is resolved", () => {
  const { result } = renderHook(() => useJsonEditor(makeProps()));
  act(() => result.current.setDiffTarget("resolved"));
  expect(result.current.diffJson.every((l) => l.state === "none")).toBe(true);
});

Let code speak for itself

❌ Bad

/* Whether the filter trigger should be displayed */
showFilter: boolean;

✅ Good

showFilter: boolean;

Replace comments with explainer variables

Move the comment into a variable name:

Before

// NB `app.trustchain` is an encrypted db path: while the app is password-locked it reads back
// as the ciphertext string. Importing it would regenerate member credentials and null the
// trustchain (LIVE-36130). IsUnlocked re-runs this thunk once the encryption key is set.
// `undefined` must still go through: that is the legitimate "nothing persisted" case.
if (typeof data === "string") return;

After

const dataIsEncrypted = typeof data === "string";
if (dataIsEncrypted) return;

☝️ When comments are necessary

Comments are only for vital information that can't go anywhere else. Always prefer not adding comments. If a comment is the only way, follow these guidelines:

❌ Bad

# pnpm patches add 'patch_hash=HASH' to virtual store paths, which prefab 2.1.0
# (introduced via AGP 8.11) misparses as an option flag due to a clikt bug that splits
# positional path arguments at '='. Pinning prefab to 2.0.0 in gradle.properties avoids
# this; keeping path segments ≤ 80 chars shortens virtual-store paths to reduce the
# likelihood of triggering prefab path-parsing issues as an additional safeguard.
android.prefab.version=2.0.0
virtual-store-dir-max-length=80

✅ Better

# Workaround for Prefab 2.1.0/Clikt bug
# See: https://github.com/google/prefab/issues/187
android.prefab.version=2.0.0
virtual-store-dir-max-length=80
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.