返回 Skills 目錄
jetbrains/go-modern-guidelines已通過檢查

SKILL DETAIL

use-modern-go

jetbrains/go-modern-guidelines/use-modern-go

This skill instructs you to use the Modern Go Guidelines CLI to write modern, idiomatic Go code. The CLI serves as the authoritative source for modern Go idioms that may be newer than your knowledge cutoff. Before editing Go code, call the wrapper's `list` subcommand with the relevant file path or target Go version. The CLI resolves the applicable Go version from go.mod, go.work, the local Go toolchain, or an explicit override. Read the complete list output, as older supported guidelines may still apply. If a guideline seems relevant but you need more context, use the `explain` subcommand with the specific guideline IDs.

安裝量 · 137查看來源

Installation

npx skills add https://github.com/jetbrains/go-modern-guidelines --skill use-modern-go

技能檔案

SKILL.md

最近同步 · 2026年8月28日

scripts/run-tool.ps1
$ErrorActionPreference = "Stop"

$cliVersion = (Get-Content -LiteralPath (Join-Path $PSScriptRoot "VERSION") -TotalCount 1).Trim()
$modulePath = "github.com/JetBrains/go-modern-guidelines"
$binaryName = "go-modern-guidelines.exe"

if ($env:LOCALAPPDATA) {
    $cacheRoot = Join-Path $env:LOCALAPPDATA "go-modern-guidelines"
} else {
    Write-Error "go-modern-guidelines: LOCALAPPDATA must be set"
    exit 1
}

# GO_MODERN_GUIDELINES_DEV runs the binary built by dev-install.
if ($env:GO_MODERN_GUIDELINES_DEV) {
    $devBinary = Join-Path (Join-Path $cacheRoot "dev") $binaryName
    if (-not (Test-Path -LiteralPath $devBinary -PathType Leaf)) {
        Write-Error "go-modern-guidelines: GO_MODERN_GUIDELINES_DEV is set but no dev build found; run dev-install"
        exit 1
    }
    & $devBinary @args
    exit $LASTEXITCODE
}

$installDir = Join-Path $cacheRoot $cliVersion
$binaryPath = Join-Path $installDir $binaryName

if (-not (Test-Path -LiteralPath $binaryPath -PathType Leaf)) {
    if (-not (Get-Command go -ErrorAction SilentlyContinue)) {
        Write-Error "go-modern-guidelines: Go toolchain is required to install $modulePath@$cliVersion"
        exit 1
    }

    $tmpDir = "$installDir.tmp.$PID"
    Remove-Item -LiteralPath $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
    New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null

    Write-Host "go-modern-guidelines: installing $modulePath@$cliVersion into $installDir" -ForegroundColor DarkGray

    try {
        $previousGoBin = $env:GOBIN
        $previousGoFlags = $env:GOFLAGS
        $previousGoWork = $env:GOWORK
        $previousCgoEnabled = $env:CGO_ENABLED
        $env:GOBIN = $tmpDir
        $env:GOFLAGS = ""
        $env:GOWORK = "off"
        $env:CGO_ENABLED = "0"
        Push-Location -LiteralPath $tmpDir
        try {
            go install "$modulePath@$cliVersion"
        } finally {
            Pop-Location
            $env:GOBIN = $previousGoBin
            $env:GOFLAGS = $previousGoFlags
            $env:GOWORK = $previousGoWork
            $env:CGO_ENABLED = $previousCgoEnabled
        }

        $tmpBinary = Join-Path $tmpDir $binaryName
        if (-not (Test-Path -LiteralPath $tmpBinary -PathType Leaf)) {
            Write-Error "go-modern-guidelines: go install did not produce $binaryName"
            exit 1
        }

        $actualVersion = ""
        try {
            $actualVersion = (& $tmpBinary --version 2>$null)
        } catch {
            $actualVersion = ""
        }
        if ($actualVersion -ne $cliVersion) {
            if (-not $actualVersion) {
                $actualVersion = "unknown version"
            }
            Write-Error "go-modern-guidelines: installed $actualVersion, want $cliVersion"
            exit 1
        }

        New-Item -ItemType Directory -Path $installDir -Force | Out-Null
        $stagedBinary = "$binaryPath.tmp.$PID"
        Move-Item -LiteralPath $tmpBinary -Destination $stagedBinary -Force
        Move-Item -LiteralPath $stagedBinary -Destination $binaryPath -Force
        Remove-Item -LiteralPath $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
    } finally {
        Remove-Item -LiteralPath $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
    }
}

& $binaryPath @args
exit $LASTEXITCODE
scripts/run-tool.sh
#!/usr/bin/env sh
set -eu

script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"

cli_version="$(cat "${script_dir}/VERSION")"
module_path="github.com/JetBrains/go-modern-guidelines"
binary_name="go-modern-guidelines"

if [ -n "${XDG_CACHE_HOME:-}" ]; then
	cache_root="${XDG_CACHE_HOME}/go-modern-guidelines"
elif [ -n "${HOME:-}" ]; then
	cache_root="${HOME}/.cache/go-modern-guidelines"
else
	echo "go-modern-guidelines: HOME or XDG_CACHE_HOME must be set" >&2
	exit 1
fi

# GO_MODERN_GUIDELINES_DEV runs the binary built by make dev-install.
if [ -n "${GO_MODERN_GUIDELINES_DEV:-}" ]; then
	dev_binary="${cache_root}/dev/${binary_name}"
	if [ ! -x "${dev_binary}" ]; then
		echo "go-modern-guidelines: GO_MODERN_GUIDELINES_DEV is set but no dev build found; run make dev-install" >&2
		exit 1
	fi
	exec "${dev_binary}" "$@"
fi

install_dir="${cache_root}/${cli_version}"
binary_path="${install_dir}/${binary_name}"

if [ ! -x "${binary_path}" ]; then
	if ! command -v go >/dev/null 2>&1; then
		echo "go-modern-guidelines: Go toolchain is required to install ${module_path}@${cli_version}" >&2
		exit 1
	fi

	tmp_dir="${install_dir}.tmp.$$"
	rm -rf "${tmp_dir}"
	mkdir -p "${tmp_dir}"
	trap 'rm -rf "${tmp_dir}"' EXIT HUP INT TERM

	echo "go-modern-guidelines: installing ${module_path}@${cli_version} into ${install_dir}" >&2

	(
		cd "${tmp_dir}"
		GOFLAGS= GOWORK=off CGO_ENABLED=0 GOBIN="${tmp_dir}" go install "${module_path}@${cli_version}"
	)

	tmp_binary="${tmp_dir}/${binary_name}"
	if [ ! -x "${tmp_binary}" ]; then
		echo "go-modern-guidelines: go install did not produce ${binary_name}" >&2
		exit 1
	fi

	actual_version="$("${tmp_binary}" --version 2>/dev/null || true)"
	if [ "${actual_version}" != "${cli_version}" ]; then
		echo "go-modern-guidelines: installed ${actual_version:-unknown version}, want ${cli_version}" >&2
		exit 1
	fi

	mkdir -p "${install_dir}"
	mv "${tmp_binary}" "${binary_path}.tmp.$$"
	mv "${binary_path}.tmp.$$" "${binary_path}"
	rm -rf "${tmp_dir}"
fi

exec "${binary_path}" "$@"
scripts/VERSION
v0.1.1
SKILL.md
---
name: use-modern-go
description: Use the Modern Go Guidelines CLI whenever writing, modifying, fixing, or refactoring Go code. Apply its version-specific guidance to generated changes.
---

# Modern Go Guidelines CLI

Always write modern, idiomatic Go code. Use the Modern Go Guidelines CLI as the source of truth for modern Go idioms that may be newer than your knowledge cutoff.

Command:

- Linux or macOS: `sh "<skill-dir>/scripts/run-tool.sh"`
- Windows PowerShell: `'<skill-dir>\scripts\run-tool.ps1'`

First run and approvals:

On first use, the wrapper installs the Modern Go Guidelines CLI in a local cache directory.

Subcommands:

- `list`
- `explain`

Before editing Go code:

1. Call the wrapper's `list` subcommand for the relevant Go file.

   Prefer passing the file you are about to edit:

   ```sh
   sh "<skill-dir>/scripts/run-tool.sh" list --file-path path/to/file.go
   ```

   On Windows, use the PowerShell wrapper with the same arguments.

   The CLI resolves the applicable Go version from go.mod, go.work, the local Go toolchain, or an explicit override.

2. If the target Go version is already known, you may pass it directly:

   ```sh
   sh "<skill-dir>/scripts/run-tool.sh" list --go-version 1.24
   ```

3. Read the complete list output before deciding which guidelines apply.

   The list output is ordered newest first. Read the full output because older supported guidelines may still apply.

   Do not pipe the output through head, tail, grep, sed, or any other truncating/filtering command. Important guidelines may otherwise be missed.

4. Treat returned guidelines as authoritative for modern Go style choices in code you are editing.

   If a guideline applies, follow it even when nearby code or repository convention uses an older pattern. Skip it only when it would not compile, would change behavior, or clearly does not match the edited code. Before skipping a returned guideline that seems relevant, call the wrapper's `explain` subcommand for that guideline ID.

Call `explain` only when a specific guideline may apply and you need the detailed explanation or examples. Request only the guideline IDs you intend to evaluate or apply:

```sh
sh "<skill-dir>/scripts/run-tool.sh" explain sync_waitgroup_go
```

Multiple guideline IDs may be requested as positional arguments:

```sh
sh "<skill-dir>/scripts/run-tool.sh" explain atomic_types errors_as_type
```

Do not call `explain` without guideline IDs. Use `list` first to discover the short guideline list for the target Go version, then call `explain` for the specific returned IDs that need more context.