Skip to content

Add --parent-config command-line option#6768

Open
tsushanth wants to merge 2 commits into
realm:mainfrom
tsushanth:feat/issue-5421-parent-config-cli
Open

Add --parent-config command-line option#6768
tsushanth wants to merge 2 commits into
realm:mainfrom
tsushanth:feat/issue-5421-parent-config-cli

Conversation

@tsushanth

Copy link
Copy Markdown

Why

Closes #5421.

The `parent_config:` entry inside a SwiftLint configuration file lets a project chain a parent ruleset, but the path has to be baked into the child config file at authoring time. The issue describes the case where the parent config lives in a temporary directory whose path is only known at lint time — pulled from a remote, generated by a script, etc. — and the child config can't reasonably hard-code it.

What

Adds `--parent-config ` to both `lint` and `analyze`. Equivalent to declaring `parent_config:` inside the resolved config, but supplied at the command line so the parent path can be passed in dynamically. Can be repeated to layer multiple parent configurations.

```bash
swiftlint --parent-config /tmp/pulled/shared.yml --config .swiftlint.yml
```

In the file graph, each `--parent-config` vertex becomes a parent of the first `--config` vertex (or of the default `.swiftlint.yml` when no `--config` is provided). Existing `parent_config:` resolution inside YAML configs is unchanged.

The option threads through:

  • `LintOrAnalyzeArguments.parentConfig` (`[URL]`)
  • `LintOrAnalyzeOptions.parentConfigurationFiles`
  • `Configuration.init(configurationFiles:parentConfigurationFiles:...)` (default `[]` to preserve all existing call sites)
  • `Configuration.FileGraph.init(commandLineChildConfigs:commandLineParentConfigs:...)` (default `[]` for the same reason)

8 files, ~57 LOC. Cache identifier now includes the parent-config list so configurations with different parent paths don't collide.

Compat

  • `Configuration.init(configurationFiles:...)` gains an optional `parentConfigurationFiles` parameter with a `[]` default. All existing call sites compile unchanged.
  • `FileGraph.init` gains an optional `commandLineParentConfigs` parameter with a `[]` default. Internal-only initializer; no public consumers.
  • `LintOrAnalyzeOptions.init` gains a `parentConfigurationFiles` parameter with a `[]` default. `package` access, only `Lint.swift` / `Analyze.swift` call it directly.
  • No deprecation needed.

Tests

`swift build` is clean. Happy to add a fixture-based test exercising the parent-config injection (likely in `Tests/SwiftLintFrameworkTests/ConfigurationTests/`) if you'd like — pointing me at the right existing test as the template would help.

Closes realm#5421.

Adds a `--parent-config` option to the `lint` and `analyze` commands
that injects parent configuration paths at the command line, equivalent
to declaring `parent_config:` inside the resolved config. This lets the
parent path be supplied dynamically (e.g. when it lives in a temporary
directory whose location isn't known when the child config is authored)
without forcing the child config to be rewritten.

The new option threads through:

- `LintOrAnalyzeArguments.parentConfig` ([URL])
- `LintOrAnalyzeOptions.parentConfigurationFiles`
- `Configuration.init(configurationFiles:parentConfigurationFiles:...)`
- `Configuration.FileGraph.init(commandLineChildConfigs:commandLineParentConfigs:...)`

In the file graph, each `--parent-config` vertex becomes a parent of the
first `--config` vertex (or of the default `.swiftlint.yml` when no
`--config` is provided). Existing `parent_config:` resolution inside YAML
configs is unchanged.
@SwiftLintBot

SwiftLintBot commented Jun 9, 2026

Copy link
Copy Markdown
19 Messages
📖 Building this branch resulted in a binary size of 27554.99 KiB vs 27554.6 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.64 s vs 0.66 s on main (3% faster).
📖 Linting Alamofire with this PR took 0.93 s vs 0.96 s on main (3% faster).
📖 Linting Brave with this PR took 6.01 s vs 6.01 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 24.7 s vs 24.75 s on main (0% faster).
📖 Linting Firefox with this PR took 10.27 s vs 10.25 s on main (0% slower).
📖 Linting Kickstarter with this PR took 7.32 s vs 7.29 s on main (0% slower).
📖 Linting Moya with this PR took 0.36 s vs 0.37 s on main (2% faster).
📖 Linting NetNewsWire with this PR took 2.33 s vs 2.36 s on main (1% faster).
📖 Linting Nimble with this PR took 0.59 s vs 0.56 s on main (5% slower).
📖 Linting PocketCasts with this PR took 6.9 s vs 6.96 s on main (0% faster).
📖 Linting Quick with this PR took 0.36 s vs 0.34 s on main (5% slower).
📖 Linting Realm with this PR took 2.48 s vs 2.47 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.46 s vs 1.5 s on main (2% faster).
📖 Linting Swift with this PR took 4.26 s vs 4.27 s on main (0% faster).
📖 Linting SwiftLintPerformanceTests with this PR took 0.16 s vs 0.16 s on main (0% slower).
📖 Linting VLC with this PR took 1.07 s vs 1.05 s on main (1% slower).
📖 Linting Wire with this PR took 15.13 s vs 15.12 s on main (0% slower).
📖 Linting WordPress with this PR took 10.48 s vs 10.44 s on main (0% slower).

Generated by 🚫 Danger

Covers the new `parentConfigurationFiles` argument plumbed through
`Configuration.init` and `FileGraph.init`. Asserts that supplying the
parent config via the command line produces the same merged
configuration as declaring `parent_config:` inside the child config
itself, and that both equal the pre-merged expected output.

Fixture lives under
`Tests/FileSystemAccessTests/Resources/ProjectMock/ParentConfig/CommandLine/`
with `child.yml`, `parent.yml`, `main_with_inline_parent.yml`, and
`expected.yml`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow parent config as an argument

2 participants