Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/detect-golangci-lint-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@taskless/cli": patch
---

golangci-lint now has its own `create-legacy-rule` recipe and a paragraph in `route`, naming `forbidigo` and `depguard` as the catch-alls to check first and saying where settings go in a v1 and a v2 config. Detection itself was already in place; an agent in a Go repository previously got only the generic recipe for it.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Why

taskless/cli#712 reports that `detect --json` found no linter in a Go repository configured with golangci-lint v2, so the legacy ladder was skipped and had to be re-derived by hand. The detection half does not reproduce: `LINTER_SIGNALS` has carried a `golangci-lint` entry (all four config spellings, the `go.mod` dependency, and the `golangci-lint` invocation) since v0.10.0, and both v0.13.7 and HEAD report it for the issue's exact repository.

What does reproduce is the second half. `route` names golangci-lint only on its "also detected, with no guide of their own" line and sends the agent to the generic `create-legacy-rule` recipe, which names catch-all rules for ESLint, Ruff, Biome and pylint, and none for Go. An agent following it has to work out for itself that `forbidigo` and `depguard` are golangci-lint's catch-alls, and that settings live in different places in a v1 and a v2 config. That is the "re-derived by hand" in the report.

## What Changes

- A `create-legacy-rule.golangci-lint.md` recipe: check `forbidigo` and `depguard` first, then find a bundled linter with `golangci-lint help linters`, confirm with `golangci-lint linters`, write settings in the config's own version (`linters.settings` for v2, `linters-settings` for v1) without migrating it, and verify with `golangci-lint config verify`. `detect` counts no golangci-lint custom rules, so the recipe never authors a `ruleguard` rule or a module plugin.
- A golangci-lint paragraph in `route`'s per-linter passage, naming both catch-alls.
- Detection tests for each config spelling, for the issue's v2 config and its v1 form, and for a Go repository with no golangci-lint config.

Every claim in the recipe was checked against golangci-lint's own documentation (configuration file, CLI, linter settings, migration guide). Two corrected an assumption: `forbidigo` has a default pattern list, and `depguard` with no rules allows only the standard library, so the recipe says neither is a no-op when left unconfigured.

Nothing here is **BREAKING**. Pre-1.0, a new recipe variant is a `patch`.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `cli-legacy-rule-recipes`: "Legacy recipes use what a tool ships before anything is written" gains the golangci-lint check and two scenarios.
- `cli-rule-routing`: "Route describes each detected linter" gains a scenario for the golangci-lint paragraph.

## Impact

- `packages/cli/src/agent/create-legacy-rule.golangci-lint.md`: new.
- `packages/cli/src/prompts/recipes.ts`: one `LEGACY_LINTER_GUIDE` entry.
- `packages/cli/test/{detect,prompts,legacy-ladder,agent-extensions}.test.ts`: new cases.
- `packages/cli/src/detect/scan.ts`: untouched; the catalog entry already existed.

## Delivery shape

**Single PR.** One recipe, one paragraph, their tests, the spec deltas and the archive fit one reviewable diff.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## MODIFIED Requirements

### Requirement: Legacy recipes use what a tool ships before anything is written

Every `create-legacy-rule` recipe, generic or per-tool, SHALL direct the agent to first establish whether a rule the tool already ships solves the request, including the tool's configurable catch-all rules. A recipe SHALL name the catch-all rules for its tool explicitly, because a search for the request's subject does not surface a catch-all rule.

A per-tool recipe SHALL state the check its tool always performs first:

- Ruff: whether `banned-api` (TID251) covers the request.
- ESLint: whether a core rule covers it, with `no-restricted-syntax` and `no-restricted-imports` (and their `@typescript-eslint/` counterparts) named as the catch-alls, before any plugin.
- Biome: whether an existing rule makes the problem go away, with `noRestrictedImports` and `noRestrictedGlobals` named as the catch-alls.
- Oxlint: whether an existing rule makes the problem go away, with `no-restricted-imports` and `no-restricted-globals` named as the catch-alls. The recipe SHALL state that Oxlint has no `no-restricted-syntax`.
- pylint: whether a shipped message or the `deprecated-modules`, `preferred-modules`, or `bad-functions` options cover it.
- flake8: whether `banned-modules` from `flake8-tidy-imports` covers it. The flake8 recipe SHALL NOT include a discovery step.
- golangci-lint: whether `forbidigo` or `depguard` covers it. The recipe SHALL state that neither is a no-op when unconfigured, and SHALL direct the agent to write settings in the config version the file already uses: `linters.settings` for a `version: "2"` config, `linters-settings` otherwise.

#### Scenario: Ruff tries banned-api first

- **WHEN** the agent follows the Ruff recipe for a request to forbid an API
- **THEN** the recipe SHALL direct it to check `banned-api` before any other step

#### Scenario: ESLint tries a core rule before a plugin

- **WHEN** the agent follows the ESLint recipe
- **THEN** it SHALL check core rules and the named catch-alls before considering any plugin from the curated list

#### Scenario: flake8 goes straight to its catch-all

- **WHEN** the agent follows the flake8 recipe
- **THEN** it SHALL be directed to `banned-modules` without a rule-discovery step

#### Scenario: golangci-lint tries its catch-alls first

- **WHEN** the agent follows the golangci-lint recipe
- **THEN** it SHALL check `forbidigo` and `depguard` before searching the bundled linters for one that fits

#### Scenario: A golangci-lint config keeps its version

- **WHEN** the repository's golangci-lint config has no `version: "2"` key
- **THEN** the agent SHALL write the linter's settings under `linters-settings`
- **AND** SHALL NOT migrate the config to v2 as a side effect
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## MODIFIED Requirements

### Requirement: Route describes each detected linter

The `route` recipe SHALL include, for each linter `detect` reports that can host a legacy rule, one paragraph saying what the tool is for, what the agent always checks first in it, and the recipe command to fetch for it. The paragraphs SHALL be rendered when the recipe is served, and SHALL appear only for linters detected in the repository.

A detected tool that can host a legacy rule and has no paragraph SHALL be named in the recipe with the command to fetch the generic recipe for it, and the recipe SHALL state that steps 1 and 2 of the legacy ladder still apply to it. `route` SHALL NOT state or imply that a linter `detect` reported is absent. Formatters and Taskless's own engines are not legacy hosts and SHALL NOT be named this way.

When the recipe is rendered from a scan, it SHALL state that `detect` recognizes a fixed list of tools, so the repository may run others.

#### Scenario: Only detected linters are described

- **WHEN** `detect` reports Ruff and no other linter
- **THEN** the served `route` recipe SHALL contain the Ruff paragraph
- **AND** SHALL NOT contain a paragraph for any other linter

#### Scenario: A tool with no legacy recipe gets no paragraph

- **WHEN** `detect` reports only `prettier`
- **THEN** the served `route` recipe SHALL contain no linter paragraph

#### Scenario: Oxlint is described when detected

- **WHEN** `detect` reports `oxlint` and no other linter
- **THEN** the served `route` recipe SHALL contain the Oxlint paragraph
- **AND** SHALL NOT say that no linter was found

#### Scenario: A detected linter with no paragraph is still named

- **WHEN** `detect` reports `eslint` and `stylelint`
- **THEN** the served `route` recipe SHALL contain the ESLint paragraph
- **AND** SHALL name `stylelint` with the command to fetch `create-legacy-rule` for it

#### Scenario: A formatter is not offered as a legacy destination

- **WHEN** `detect` reports `eslint` and `prettier`
- **THEN** the served `route` recipe SHALL NOT name `prettier` as a linter to fetch a recipe for

#### Scenario: golangci-lint is described when detected

- **WHEN** `detect` reports `golangci-lint` and no other linter
- **THEN** the served `route` recipe SHALL contain the golangci-lint paragraph, naming `forbidigo` and `depguard` as its catch-alls
- **AND** SHALL NOT list golangci-lint among the tools with no guide of their own
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## 1. Implementation

- [x] 1.1 Reproduce #712 with the built CLI against the issue's repository, and confirm the `golangci-lint` catalog entry exists in v0.13.7 and HEAD.
- [x] 1.2 Confirm the recipe's golangci-lint claims against golangci-lint's documentation.
- [x] 1.3 Add `packages/cli/src/agent/create-legacy-rule.golangci-lint.md`.
- [x] 1.4 Add the golangci-lint entry to `LEGACY_LINTER_GUIDE` in `packages/cli/src/prompts/recipes.ts`.
- [x] 1.5 Add tests: each config spelling, v2 and v1 configs, a Go repository with no config, the `route` paragraph, and the recipe's catch-all order.
- [x] 1.6 Add a `patch` changeset.

## 2. Spec

- [x] 2.1 Write both deltas, restating each requirement in full with every existing scenario.
- [x] 2.2 `pnpm openspec validate --strict`, the dry-run archive scenario check, then archive.

## 3. Verification

- [x] 3.1 `pnpm typecheck`, `pnpm lint`, and the CLI test suite pass.
12 changes: 12 additions & 0 deletions openspec/specs/cli-legacy-rule-recipes/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A per-tool recipe SHALL state the check its tool always performs first:
- Oxlint: whether an existing rule makes the problem go away, with `no-restricted-imports` and `no-restricted-globals` named as the catch-alls. The recipe SHALL state that Oxlint has no `no-restricted-syntax`.
- pylint: whether a shipped message or the `deprecated-modules`, `preferred-modules`, or `bad-functions` options cover it.
- flake8: whether `banned-modules` from `flake8-tidy-imports` covers it. The flake8 recipe SHALL NOT include a discovery step.
- golangci-lint: whether `forbidigo` or `depguard` covers it. The recipe SHALL state that neither is a no-op when unconfigured, and SHALL direct the agent to write settings in the config version the file already uses: `linters.settings` for a `version: "2"` config, `linters-settings` otherwise.

#### Scenario: Ruff tries banned-api first

Expand All @@ -34,6 +35,17 @@ A per-tool recipe SHALL state the check its tool always performs first:
- **WHEN** the agent follows the flake8 recipe
- **THEN** it SHALL be directed to `banned-modules` without a rule-discovery step

#### Scenario: golangci-lint tries its catch-alls first

- **WHEN** the agent follows the golangci-lint recipe
- **THEN** it SHALL check `forbidigo` and `depguard` before searching the bundled linters for one that fits

#### Scenario: A golangci-lint config keeps its version

- **WHEN** the repository's golangci-lint config has no `version: "2"` key
- **THEN** the agent SHALL write the linter's settings under `linters-settings`
- **AND** SHALL NOT migrate the config to v2 as a side effect

### Requirement: Rule discovery is confirmed against the installed version

Where a tool's rule set is too large to match a request against locally, the recipe SHALL direct the agent to find candidate rules on the tool's rules page by web search or fetch, then confirm each candidate against the installed version with the tool's own command before enabling it. The Ruff recipe SHALL use `ruff rule <name or code>`, the Biome recipe `biome explain <rule>`, and the Oxlint recipe `oxlint --rules --format default`.
Expand Down
6 changes: 6 additions & 0 deletions openspec/specs/cli-rule-routing/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ When the recipe is rendered from a scan, it SHALL state that `detect` recognizes
- **WHEN** `detect` reports `eslint` and `prettier`
- **THEN** the served `route` recipe SHALL NOT name `prettier` as a linter to fetch a recipe for

#### Scenario: golangci-lint is described when detected

- **WHEN** `detect` reports `golangci-lint` and no other linter
- **THEN** the served `route` recipe SHALL contain the golangci-lint paragraph, naming `forbidigo` and `depguard` as its catch-alls
- **AND** SHALL NOT list golangci-lint among the tools with no guide of their own

### Requirement: Route asks the user only when the ladder does not decide

The `route` recipe SHALL present the viable options to the user with their
Expand Down
104 changes: 104 additions & 0 deletions packages/cli/src/agent/create-legacy-rule.golangci-lint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Topic: create-legacy-rule (golangci-lint) (CLI v%(CLI_VERSION)s / topic v1)

%(ONE_COMMAND_PER_CALL)s

## You are here
This is `create-legacy-rule` for golangci-lint. It solves a request by
enabling or configuring a linter golangci-lint already bundles. When
nothing here fits, re-run `%(TASKLESS_CLI)s agent route` and continue from
step 3 of its legacy ladder.

## Goal
Find the bundled linter that makes the problem go away, confirm it in the
installed version, and enable it in the repository's golangci-lint
configuration, in the config version that file already uses.

## Preconditions
- `%(TASKLESS_CLI)s detect --json` reports `golangci-lint`.
- No auth required.

## Steps

1. **Always check the catch-all linters first.** They take your own list,
and a search for the request's subject will not surface them:
- `forbidigo`: bans identifiers matched by a regular expression, each
with its own message, through `forbid` entries of `pattern` and
`msg`. With `analyze-types: true`, a `pkg` pattern matches the
import path, so `^v1\.Dump$` can mean one package's `Dump` and not
another's. It covers most "never call X" requests.
- `depguard`: bans imports, each with a reason, through named `rules`
whose `deny` entries are `pkg` and `desc`, scoped with `files`.
It covers "never import X" and "use Y instead of X".

Neither is a no-op when left unconfigured. `forbidigo`'s default list
bans `fmt.Print*`, `print` and `println`, so a repo that enables it with
no `forbid` list relies on that default: keep those patterns when you
add yours. `depguard` with no `rules` allows only the standard library,
so never enable it without writing the rule.

2. **Otherwise, find a bundled linter.** golangci-lint bundles many
linters, each with its own checks. `golangci-lint help linters` lists
every linter the installed build has, and the docs describe each one's
settings at https://golangci-lint.run/docs/linters/configuration/.
There is no `llms.txt` index for this site.

3. **Confirm against the installed version and config.** Run
`golangci-lint linters`, which lists the linters the current config
enables and disables. In a v2 config, read `linters.default` before
`linters.enable`: it sets the starting set (`standard`, `all`, `none`,
or `fast`), so a linter can already be on without being listed.

4. **Edit the config golangci-lint actually reads, in its own version.**
It reads `.golangci.yml`, `.golangci.yaml`, `.golangci.toml`, or
`.golangci.json`, searching from the directory of the first analyzed
path up to the root. `golangci-lint config path` prints the one in use.
- **`version: "2"`:** settings go under `linters.settings.<linter>`,
and the linter is named in `linters.enable`:
```yaml
version: "2"
linters:
enable:
- forbidigo
- depguard
settings:
forbidigo:
forbid:
- pattern: ^fmt\.Print.*$
msg: Use the logger in internal/log.
depguard:
rules:
main:
deny:
- pkg: github.com/pkg/errors
desc: Use the standard errors package.
```
- **No `version` key (a v1 config):** settings go under the top-level
`linters-settings.<linter>` instead, with the same keys below it.
Do not migrate the file to v2 as a side effect: `golangci-lint migrate`
rewrites the whole config and drops its comments, so it is the
user's decision.

Then run `golangci-lint config verify`, which checks the file against
golangci-lint's JSON schema.

5. **No bundled linter fits: return to `route`.** `detect` does not count
golangci-lint custom rules, so the repository's own rules can never
reach the threshold here. Do not write a `ruleguard` rule or build a
module plugin. Return to `%(TASKLESS_CLI)s agent route` and continue to
step 3 of its legacy ladder, a Taskless rule.

6. **Report, and say who runs it.** Show the file you changed and the
command that shows the linter firing, e.g. `golangci-lint run ./...`.
`%(TASKLESS_CLI)s check` does NOT run golangci-lint.

## Important Notes

- Do not invent linter settings from memory: confirm each key against the
linter's section of the configuration docs before writing it.
- A linter the installed build does not list is not available, however
current the docs are. Upgrading golangci-lint is the user's decision.

## See Also

- `%(TASKLESS_CLI)s agent route`: continue down the legacy ladder when no bundled linter fits
- `%(TASKLESS_CLI)s agent create-sg-rule`: ast-grep parses Go, for the Taskless rule
7 changes: 7 additions & 0 deletions packages/cli/src/prompts/recipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,13 @@ check them first, with the \`deprecated-modules\`,
from \`flake8-tidy-imports\` first, which bans a module with a message.
It is a plugin package, so the repo may need to add it.`,
],
[
"golangci-lint",
`**golangci-lint** runs a bundle of Go linters from one config. Always
check \`forbidigo\` (bans identifiers by pattern, each with a message)
and \`depguard\` (bans imports, each with a reason) first: they are the
catch-alls, and a search for the request's subject will not surface them.`,
],
];

/**
Expand Down
33 changes: 19 additions & 14 deletions packages/cli/test/agent-extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,20 +637,25 @@ describe("taskless agent --tool (variant lookup)", () => {
await rm(cwd, { recursive: true, force: true });
});

it.each(["ruff", "eslint", "biome", "oxlint", "pylint", "flake8"])(
"serves the %s variant of create-legacy-rule",
async (tool) => {
const result = await runCli([
"agent",
"create-legacy-rule",
`--tool=${tool}`,
"-d",
cwd,
]);
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain(`# Topic: create-legacy-rule (${tool})`);
}
);
it.each([
"ruff",
"eslint",
"biome",
"oxlint",
"pylint",
"flake8",
"golangci-lint",
])("serves the %s variant of create-legacy-rule", async (tool) => {
const result = await runCli([
"agent",
"create-legacy-rule",
`--tool=${tool}`,
"-d",
cwd,
]);
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain(`# Topic: create-legacy-rule (${tool})`);
});

it("takes the value as a separate argument, not as a second topic", async () => {
const result = await runCli([
Expand Down
Loading
Loading