From b2b75cbdffcd75119a7c645ee2c641525fac254d Mon Sep 17 00:00:00 2001 From: Denis Panfilov Date: Sun, 11 Jan 2026 23:14:24 +0100 Subject: [PATCH] Update docs and action with new flags --- CLAUDE.md | 3 ++- README.md | 49 ++++++++++++++++++++++++++++++++++++++++--------- action.yml | 30 +++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index fd29aee..9c0b879 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -80,7 +80,8 @@ testdata/src/ ├── generated/ # Generated file detection ├── internal/config # Internal package detection tests ├── unexported/ # Tests for -unexported flag -└── ignore/ # Tests for -ignore flag +├── ignore/ # Tests for -ignore flag +└── jsontest/ # Tests for -output=json flag ``` Test annotations use `// want "message"` comments to assert expected diagnostics: diff --git a/README.md b/README.md index c80e934..7c10558 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,20 @@ positionless ./... # Analyze specific package positionless ./pkg/mypackage +# Apply suggested fixes automatically +positionless -fix ./... + # Include generated files (excluded by default) positionless -generated ./... -# Apply suggested fixes automatically -positionless -fix ./... +# Fix structs with unexported fields in internal packages +positionless -fix -internal ./... + +# Skip specific struct types +positionless -ignore="ConfigTest,*Mock" ./... + +# JSON output for tooling integration +positionless -output=json ./... 2>&1 ``` ### With go vet @@ -186,8 +195,21 @@ jobs: | `path` | Path to analyze | `./...` | | `fix` | Apply suggested fixes automatically | `false` | | `include-generated` | Include generated files in analysis | `false` | +| `include-unexported` | Include structs with unexported fields in fixes | `false` | +| `include-internal` | Auto-allow unexported fields in `internal/` packages | `false` | +| `ignore` | Comma-separated patterns to skip (e.g., `ConfigTest,*Mock`) | `` | +| `output` | Output format: `text` or `json` | `text` | | `version` | Version of positionless to use | `latest` | +#### Action Outputs + +| Output | Description | +|--------|-------------| +| `findings-count` | Number of positional struct literals found | +| `fixed-count` | Number of fixes applied (when fix is enabled) | +| `exit-code` | Exit code from the analyzer (0=success, 3=findings) | +| `version` | Version of positionless used | + #### Example Output Here's what the GitHub Action output looks like when it detects positional struct literals: @@ -284,10 +306,11 @@ The analyzer: 1. Scans your Go code for struct literal initialization 2. Identifies positional initialization patterns -3. Suggests fixes that convert to named field initialization -4. Can automatically apply fixes with the `-fix` flag -5. Preserves your original values and formatting -6. Skips generated files by default (use `-generated` to include them) +3. Reports all positional struct literals as warnings +4. Suggests fixes that convert to named field initialization +5. Can automatically apply fixes with the `-fix` flag +6. Preserves your original values and formatting +7. Skips generated files by default (use `-generated` to include them) ### Flags @@ -297,12 +320,20 @@ The analyzer: | `-generated` | Include generated files in analysis | | `-unexported` | Include structs with unexported fields in fixes | | `-internal` | Auto-allow unexported fields in `internal/` packages | -| `-ignore=PATTERN` | Skip structs matching pattern (comma-separated) | -| `-output=FORMAT` | Output format: `text` (default) or `json` | +| `-ignore=PATTERN` | Skip structs matching pattern (comma-separated, supports globs) | +| `-output=FORMAT` | Output format: `text` (default) or `json` (golangci-lint compatible) | > [!TIP] > Use `-internal` when analyzing your own internal packages where you control all the code +### Exit codes + +| Code | Meaning | +|------|---------| +| 0 | No issues found | +| 1 | Error occurred | +| 3 | Issues found (useful for CI pipelines) | + ## Example Given this code: @@ -330,7 +361,7 @@ cfg := Config{ ``` > [!IMPORTANT] -> The analyzer only processes exported fields to respect Go's visibility rules +> By default, the analyzer reports all positional structs but only auto-fixes those with exported fields. Use `-unexported` or `-internal` to enable fixes for structs with unexported fields. ## License diff --git a/action.yml b/action.yml index 76a94e3..03f54d4 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,22 @@ inputs: description: 'Include generated files in analysis' required: false default: 'false' + include-unexported: + description: 'Include structs with unexported fields in fixes' + required: false + default: 'false' + include-internal: + description: 'Auto-allow unexported fields in internal/ packages' + required: false + default: 'false' + ignore: + description: 'Comma-separated patterns to skip (e.g., ConfigTest,*Mock)' + required: false + default: '' + output: + description: 'Output format: text or json' + required: false + default: 'text' version: description: 'Version of positionless to use (default: latest)' required: false @@ -94,7 +110,19 @@ runs: if [ "${{ inputs.include-generated }}" == "true" ]; then FLAGS="$FLAGS -generated" fi - + if [ "${{ inputs.include-unexported }}" == "true" ]; then + FLAGS="$FLAGS -unexported" + fi + if [ "${{ inputs.include-internal }}" == "true" ]; then + FLAGS="$FLAGS -internal" + fi + if [ -n "${{ inputs.ignore }}" ]; then + FLAGS="$FLAGS -ignore=${{ inputs.ignore }}" + fi + if [ "${{ inputs.output }}" != "text" ]; then + FLAGS="$FLAGS -output=${{ inputs.output }}" + fi + echo "Running: positionless $FLAGS ${{ inputs.path }}" # Run analyzer and capture output