Format source

From liferay/liferay-portal · View interactive version

Format source is an AI agent skill from the GitHub repository liferay/liferay-portal. Format source files to align with Liferay's coding standards.

How to use this skill

Skill file

Format Source

All the code is strictly formatted using the source formatter (Java, JavaScript, JSON, JSP, Markdown, properties, shell, XML, YAML, and others). This is how it works:

Run for a specific module:

cd <module-root> && <gradlew> formatSource

Run across the entire codebase:

git fetch --no-tags https://github.com/brianchandotcom/liferay-portal.git master

cd <repo-root>/portal-impl && ANT_OPTS="-Xmx2560m -Dgit.working.branch.name=$(git merge-base HEAD FETCH_HEAD)" ant format-source-current-branch

Pass git.working.branch.name in ANT_OPTS rather than on the command line, since the yarn formatter lists its files through a separate ant git-util call that inherits nothing else. When the fetch fails, leave out -Dgit.working.branch.name.

ant format-source-current-branch only inspects committed files, so run it after creating the commit, and amend any formatter changes or fixes into that commit.

In both cases, if there are issues to be fixed, the formatter will list them. Fix them.

Skip generated files. The automatic formatter already does this via BaseSourceProcessor.hasGeneratedTag; apply the same rule to any manual edit. A file is generated when it contains any of these unquoted markers:

These files are overwritten on the next build, so manual edits are lost and only pollute the diff.

Shell Scripts

Shell scripts (*.sh) follow a separate style guide maintained in the liferay-docker repository. Defer their formatting to the format-bash-source skill and the CODE_STYLE.md it depends on. Resolve both files in this order:

  1. Local Checkout — when liferay-docker sits beside this repository, read ../liferay-docker/.claude/skills/format-bash-source/SKILL.md and ../liferay-docker/.claude/CODE_STYLE.md.
  1. Remote Fallback — when the local checkout is absent, download both files from raw.githubusercontent.com and read them from there:

```bash

temp_dir=$(mktemp -d)

curl \

--fail \

--output "${temp_dir}/format-bash-source.md" \

--silent \

--url "https://raw.githubusercontent.com/liferay/liferay-docker/refs/heads/master/.claude/skills/format-bash-source/SKILL.md"

curl \

--fail \

--output "${temp_dir}/CODE_STYLE.md" \

--silent \

--url "https://raw.githubusercontent.com/liferay/liferay-docker/refs/heads/master/.claude/CODE_STYLE.md"

```

For any *.sh file in scope, read the resolved format-bash-source SKILL.md and the CODE_STYLE.md it points to, then apply those rules.

Go Code

Go files (*.go) are outside the portal source formatter's set of file types, so the automatic formatter gofmt is used instead. The conventions for Go live in .claude/rules/go-style.md, which is scoped to cloud/operator/**/*.go. Read that file and apply it.

The workflow mirrors the one above. Run gofmt across the Go module — the directory that holds go.mod — apply the rules from .claude/rules/go-style.md, then rerun gofmt to absorb any changes. Both the first pass and the rerun are the same command:

cd <go-module-root> && gofmt -w .

List the files that are not yet formatted without rewriting them:

cd <go-module-root> && gofmt -l .

When a rule and gofmt disagree, gofmt wins; leave the formatted code as it stands.

Skip generated Go files. Beyond the marker line listed above, a Go file whose name contains zz_generated is generated output that the next go generate rewrites.

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.