Skip to content
Back to skills

Format Source

ASecurity

Format source files to align with Liferay's coding standards.

  • 2,268 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added August 31, 2026
toolsjavascriptgojavashellbashdockergit

Security analysis

A100/100

Scanned November 9, 2026

npx -y skills add liferay/liferay-portal --skill format-source --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Format Source?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Format Source
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/liferay-format-source/badge)](https://www.skillsdirectory.com/skills/liferay-format-source)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---

description: Format source files to align with Liferay's coding standards.
name: format-source

---

# 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:

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

Run across the entire codebase:

```bash
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:

- `@generated` — Service Builder, REST Builder, taglib generator (Java, by far the most common; ~18k files)

- `$ANTLR` — ANTLR-generated lexers and parsers

- `# This is a generated file.` — generated scripts

- `## Autogenerated` — generated Markdown and config

- `// Code generated ... DO NOT EDIT.` — `go generate` output, such as the controller-gen deepcopy and kubebuilder scaffolding under `cloud/`

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:

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

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

```bash
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.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.