realm / realm/SwiftLint

`--working-directory` has no effect since 0.65.0

Open Beginner friendly
#6,907 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
Bug Description

--working-directory no longer takes effect. The configuration file is still looked up in the directory SwiftLint was started from, so it is not found and SwiftLint silently falls back to the default configuration.

mkdir -p ~/a/b
printf 'disabled_rules:\n  - identifier_name\n' > ~/a/.swiftlint.yml
printf 'enum Size {\n    case m\n}\n' > ~/a/b/Bad.swift

cd ~/a/b
swiftlint lint --working-directory ~/a --no-cache --quiet ~/a/b/Bad.swift

~/a/.swiftlint.yml disables identifier_name, so 0.64.1 and earlier report nothing. 0.65.0, 0.65.1 and main report:

~/a/b/Bad.swift:2:10: error: Identifier Name Violation: Enum element name 'm' should be between 3 and 40 characters long (identifier_name)

The defer restoring the directory in LintOrAnalyzeCommand.run(_:) is scoped to the if let workingDirectory block, so it fires at that block's closing brace, before linting starts. It was added in #6048. Moving it to the function's scope, with the restore target held in an optional so that the directory is only restored when the option actually moved it, would fix it without changing anything when the option is not passed. I'm happy to open a PR.

This mainly hurts the SwiftPM plugins, which run from the package directory and need the option to reach a .swiftlint.yml above it.

Environment
  • SwiftLint version 0.65.1 (0.65.0 and main are also affected, 0.64.1 and earlier are not)
  • Xcode 26.5
  • Installation method used: official SwiftLintBinary.artifactbundle release
  • Configuration file:
disabled_rules:
  - identifier_name

No nested configurations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at LintOrAnalyzeCommand.run(_:) and reproduce the issue with the provided SwiftLint command and configuration. Inspect when the working directory is restored relative to linting, then verify that --working-directory finds ~/a/.swiftlint.yml and suppresses the identifier_name violation without changing behavior when the option is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.