format-source-add-rule

$npx mdskill add liferay/liferay-portal/format-source-add-rule

Add a new formatting rule from a Git commit.

  • Encodes a formatting convention observed in a commit as a reusable rule.
  • Depends on Git commit SHA and optional hint for narrowing scope.
  • Inspects commit diff, checks for duplicates, and asks for clarification when needed.
  • Writes the new rule to the format-source skill's SKILL.md file.

SKILL.md

.github/skills/format-source-add-ruleView on GitHub ↗
---

description: Add a new rule to the format-source skill, derived from a Git commit.
name: format-source-add-rule

---

# Format Source: Add Rule

Add a new rule to the `format-source` skill, derived from a Git commit. Anyone can use this to encode a convention they spotted in someone's commit. Rules can apply to any file type the source formatter handles — Java, `.properties`, XML, JSP, Markdown, Gradle, `.gitignore`, YAML, and so on. Do not bias toward Java.

## Inputs

- A Git commit SHA.

- Optional: a hint about which aspect of the commit to encode. Commits often touch multiple things; a hint narrows the scope.

## Workflow

### Inspect the Commit

Inspect the commit's full diff. Identify a single, learnable formatting pattern — something a future reviewer could apply mechanically to other code. Stop and ask the user to clarify when:

- Multiple distinct rules are present. Ask the user to pick one, or run the skill once per rule.

- The commit mixes formatting changes with logic or refactoring changes that cannot be separated.

- The pattern is not generalizable beyond the specific file or context.

### Check for Duplicates

Read the existing rules in `.claude/skills/format-source/SKILL.md` and compare against the pattern from the previous step. If the pattern duplicates or substantially overlaps an existing rule, flag it to the user and ask whether to skip, refine the existing rule, or proceed anyway.

### Write the Rule

Find the next rule number in `.claude/skills/format-source/SKILL.md`, then append the new rule at the end of the file using this exact markdown template:

````markdown
### Rule <next-number>: <Title Case name, for example "Method Parameter Ordering">

**Why:** <one-sentence explanation of what consistency the rule buys, not what the rule does>

**Examples:**

```diff

- <one or more before lines demonstrating the rule, using abstract identifiers — not the commit's literal code>
+ <matching after lines>

```
````

Use abstract identifiers in the diff rather than the verbatim names from the commit — for example `methodA`, `fieldB`, `Foo` for Java; `some.property`, `myTag`, `someKey` for properties, XML, YAML, or Markdown. The examples should illustrate the general pattern; reproducing the commit's exact text overfits the rule to one case and makes future readers match on names rather than the underlying pattern.

For rules with nuance, use several diff blocks for each additional case. Add a single line of prose before the diff block when a diff alone is unclear.

### Self-Test the Rule

Validate that the appended rule reproduces the input commit when applied to the commit's parent state. To do this, create a new branch at the commit's parent and run `/format-source` scoped to only the files touched by the commit, applying only the manual rules (skip the automatic formatter). Compare the result with the commit. If the rule does not produce an equivalent change, revise the rule and repeat until it does.

### Commit the Rule

After the self-test passes, stage only `.claude/skills/format-source/SKILL.md` and commit with this commit message format:

```
<ticket> Add rule derived from <sha>
```

More from liferay/liferay-portal

SkillDescription
format-sourceFormat source files to align with Liferay's coding standards.
jira-bugCreate a Jira bug ticket in the LPD project through the REST API. Use when the user asks to create or file a Jira bug or LPD ticket.
jira-taskCreate a Jira task in the LPD project through the REST API. Use when the user asks to create a Jira task or LPD task ticket.
markdown-formatFormat a Markdown file to match Liferay conventions — frontmatter order, Title Case headings, braced shell variables, long-form CLI flags, and professional prose. Use when the user asks to format, clean up, polish, or copy-edit a Markdown file destined for the Liferay repository.
poshi-migrateMigrate a Liferay Poshi .testcase file to its modern test layer (Playwright, Jest, JUnit unit, Java integration). Routes each test to the right layer, consolidates compatible tests at write time, and follows existing Playwright patterns from a configurable reference folder. Use when the user asks to migrate, port, or convert a Poshi .testcase to Playwright, Jest, or JUnit.
poshi-shrinkShrink a Liferay component's Poshi test suite by merging overlapping tests. Use when the user asks to reduce, merge, or clean up Poshi tests for a @component-name.
prCreate a GitHub PR for the current branch. Use when the user asks to create a PR, send a PR, or invokes /pr.
pr-checkCheck that a PR is ready to be sent for review.
pr-check-publishComment a pr-check run on an existing GitHub PR with a marker the webhook parses to apply the commit status and label. Use after rerunning pr-check on an open PR.
test-fixResolve a single Liferay test failure end-to-end.