Skip to content

Extract the shared runner-setup pipeline - #2555

Merged
bendrucker merged 1 commit into
masterfrom
refactor-inspection
Jun 8, 2026
Merged

Extract the shared runner-setup pipeline#2555
bendrucker merged 1 commit into
masterfrom
refactor-inspection

Conversation

@bendrucker

Copy link
Copy Markdown
Member

Extracts the load→annotate→vars→build→runners pipeline into a single tflint.BuildRunners function and routes both callers through it. The same sequence (LoadRootModuleLoadConfigDirFilesNewAnnotationsLoadValuesFilesParseVariableValuesBuildConfigNewRunnerNewModuleRunners) had emerged twice, near-verbatim, in cmd/inspect.go (setupRunners) and langserver/handler.go (inspect).

Scope is limited to runner setup. The plugin config-apply loop, ruleset.Check, the autofix loop, parallelism, and diagnostics stay in their callers because they differ in real ways (version-constraint checks, the Fix flag, parallel module runners, plugin lifecycle, LSP diagnostic conversion). Unifying those is out of scope and would force a different package home to avoid a tflint → plugin → tflint import cycle.

Changes

  • Adds tflint.BuildRunners(loader, config, workingDir, dir) in the new tflint/runner_set.go, lifted from cmd's setupRunners body.
  • Routes cmd/inspect.go and langserver/handler.go through it; deletes setupRunners and the langserver inline block.
  • Keeps terraform.NewLoader construction in the callers. cmd needs the loader before setup for the worker-mode IsConfigDir check and after for Files()/Sources(); langserver builds it from its in-memory afero.Fs overlay and reuses it for Files() in the Check loop. Passing the loader in keeps the OS-fs vs. CopyOnWriteFs difference at the caller.

I standardized the diagnostic wording on cmd's semicolon form ("Failed to load the root module; %w"), where langserver previously used a colon.

Testing

Adds tflint/runner_set_test.go: a table test that builds a terraform.Loader over an in-memory afero fixture and asserts module-runner count, variable resolution (auto-loaded and explicit varfiles), and annotation attachment. This pipeline could previously only be exercised through the CLI binary or the LSP integration harness.

@bendrucker
bendrucker marked this pull request as ready for review June 5, 2026 04:32
@bendrucker
bendrucker requested a review from Copilot June 5, 2026 04:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extracts the common “load → annotate → vars → build → runners” setup logic into a shared tflint.BuildRunners helper, and updates both the CLI inspector and the language server to use that single implementation. This reduces duplication while keeping higher-level inspection/check loops (plugin lifecycle, parallel module checks, diagnostics conversion, autofix behavior) in their respective callers.

Changes:

  • Added tflint.BuildRunners(loader, config, workingDir, dir) in tflint/runner_set.go to centralize runner setup.
  • Routed cmd/inspect.go and langserver/handler.go through BuildRunners, removing duplicate setup code.
  • Added tflint/runner_set_test.go to exercise the runner-setup pipeline (varfiles, variable resolution, annotations, module runners).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tflint/runner_set.go Introduces shared runner setup function that encapsulates the previously duplicated pipeline.
tflint/runner_set_test.go Adds coverage for the extracted setup, including varfile loading, annotation extraction, and child module runner creation.
langserver/handler.go Replaces inline runner setup with a call to tflint.BuildRunners and keeps the langserver’s single-slice iteration behavior.
cmd/inspect.go Removes setupRunners method and uses tflint.BuildRunners for CLI inspection runner initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bendrucker
bendrucker requested a review from wata727 June 5, 2026 04:43

@wata727 wata727 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bendrucker
bendrucker merged commit 64654ca into master Jun 8, 2026
20 checks passed
@bendrucker
bendrucker deleted the refactor-inspection branch June 8, 2026 18:15
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jul 21, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [tflint](https://github.com/terraform-linters/tflint) | minor | `0.63.1` → `0.64.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>terraform-linters/tflint (tflint)</summary>

### [`v0.64.0`](https://github.com/terraform-linters/tflint/releases/tag/v0.64.0)

[Compare Source](terraform-linters/tflint@v0.63.1...v0.64.0)

#### What's Changed

##### Enhancements

- cmd: include worker dir for no-range recursive issues by [@&#8203;Zakharden](https://github.com/Zakharden) in [#&#8203;2524](terraform-linters/tflint#2524)
- config: add ignorable rule setting by [@&#8203;Zakharden](https://github.com/Zakharden) in [#&#8203;2525](terraform-linters/tflint#2525)
- formatter(junit): include range in testcase name by [@&#8203;Zakharden](https://github.com/Zakharden) in [#&#8203;2538](terraform-linters/tflint#2538)

##### Bug Fixes

- plugin: fetch attestation bundles from bundle\_url by [@&#8203;Kunalbehbud](https://github.com/Kunalbehbud) in [#&#8203;2593](terraform-linters/tflint#2593)
  - Merged as [#&#8203;2600](terraform-linters/tflint#2600)

##### Chores

- Refactor formatter dispatch into format adapters by [@&#8203;bendrucker](https://github.com/bendrucker) in [#&#8203;2556](terraform-linters/tflint#2556)
- Inline per-format print methods into their adapters by [@&#8203;bendrucker](https://github.com/bendrucker) in [#&#8203;2557](terraform-linters/tflint#2557)
- build(deps): Bump docker/setup-buildx-action from 4.0.0 to 4.1.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2559](terraform-linters/tflint#2559)
- build(deps): Bump github.com/mattn/go-colorable from 0.1.14 to 0.1.15 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2560](terraform-linters/tflint#2560)
- build(deps): Bump golang from 1.26.3-alpine3.23 to 1.26.4-alpine3.23 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2558](terraform-linters/tflint#2558)
- release: Set branch name for Homebrew tap by [@&#8203;wata727](https://github.com/wata727) in [#&#8203;2561](terraform-linters/tflint#2561)
- Extract the shared runner-setup pipeline by [@&#8203;bendrucker](https://github.com/bendrucker) in [#&#8203;2555](terraform-linters/tflint#2555)
- formatter: guard diagnostics with no source range by [@&#8203;bendrucker](https://github.com/bendrucker) in [#&#8203;2562](terraform-linters/tflint#2562)
- docs: add Go install instructions to README by [@&#8203;RoseSecurity](https://github.com/RoseSecurity) in [#&#8203;2563](terraform-linters/tflint#2563)
- build(deps): Bump actions/checkout from 6.0.2 to 6.0.3 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2565](terraform-linters/tflint#2565)
- build(deps): Bump alpine from 3.23.4 to 3.24.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2566](terraform-linters/tflint#2566)
- build(deps): Bump the go-x group with 2 updates by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2567](terraform-linters/tflint#2567)
- build(deps): Bump github.com/sigstore/sigstore-go from 1.1.4 to 1.2.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2568](terraform-linters/tflint#2568)
- fix(install): close download and zip readers by [@&#8203;RoseSecurity](https://github.com/RoseSecurity) in [#&#8203;2564](terraform-linters/tflint#2564)
- build(deps): Bump alpine from 3.24.0 to 3.24.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2570](terraform-linters/tflint#2570)
- build(deps): Bump golang.org/x/net from 0.55.0 to 0.56.0 in the go-x group by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2571](terraform-linters/tflint#2571)
- build(deps): Bump github.com/sigstore/sigstore-go from 1.2.0 to 1.2.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2572](terraform-linters/tflint#2572)
- build(deps): Bump actions/checkout from 6.0.3 to 7.0.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2579](terraform-linters/tflint#2579)
- build(deps): Bump actions/setup-go from 6.4.0 to 6.5.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2580](terraform-linters/tflint#2580)
- build(deps): Bump golangci/golangci-lint-action from 9.2.1 to 9.3.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2583](terraform-linters/tflint#2583)
- build(deps): Bump goreleaser/goreleaser-action from 7.2.2 to 7.2.3 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2582](terraform-linters/tflint#2582)
- build(deps): Bump actions/attest from 4.1.0 to 4.1.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2581](terraform-linters/tflint#2581)
- build(deps): Bump docker/build-push-action from 7.2.0 to 7.3.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2584](terraform-linters/tflint#2584)
- build(deps): Bump golang.org/x/text from 0.38.0 to 0.39.0 in the go-x group by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2585](terraform-linters/tflint#2585)
- build(deps): Bump github.com/sigstore/sigstore-go from 1.2.1 to 1.2.2 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2588](terraform-linters/tflint#2588)
- build(deps): Bump google.golang.org/grpc from 1.81.1 to 1.82.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2587](terraform-linters/tflint#2587)

#### New Contributors

- [@&#8203;Zakharden](https://github.com/Zakharden) made their first contribution in [#&#8203;2524](terraform-linters/tflint#2524)
- [@&#8203;RoseSecurity](https://github.com/RoseSecurity) made their first contribution in [#&#8203;2563](terraform-linters/tflint#2563)
- [@&#8203;Kunalbehbud](https://github.com/Kunalbehbud) made their first contribution in [#&#8203;2593](terraform-linters/tflint#2593)

**Full Changelog**: <terraform-linters/tflint@v0.63.1...v0.64.0>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNzIuNiIsInVwZGF0ZWRJblZlciI6IjQzLjI3Mi42IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants