nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 640 forks source link

Unused argument warning is too eager #1017

Closed juri closed 3 years ago

juri commented 3 years ago

I noticed this with 0.48.12, and I guess I was upgrading from 0.48.11, but I don't think Homebrew can confirm that for me.

I'm getting too eager triggering of unusedArguments. I'm using this config (which could use a bit of updating…):

--rules anyObjectProtocol, blankLinesAroundMark, blankLinesAtEndOfScope, blankLinesAtStartOfScope, blankLinesBetweenScopes, braces, consecutiveBlankLines, consecutiveSpaces, duplicateImports, elseOnSameLine, emptyBraces, hoistPatternLet, indent, isEmpty, leadingDelimiters, linebreakAtEndOfFile, modifierOrder, numberFormatting, preferKeyPath, redundantBackticks, redundantBreak, redundantExtensionACL, redundantFileprivate, redundantGet, redundantInit, redundantLet, redundantLetError,redundantNilInit, redundantObjc, redundantParens, redundantPattern, redundantRawValues, redundantReturn, redundantSelf, redundantVoidReturnType, semicolons, sortedImports, spaceAroundBraces, spaceAroundBrackets, spaceAroundComments, spaceAroundGenerics, spaceAroundOperators, spaceAroundParens, spaceInsideBraces, spaceInsideBrackets, spaceInsideComments, spaceInsideGenerics, spaceInsideParens, strongOutlets, strongifiedSelf, todos, trailingClosures, trailingCommas, trailingSpace, typeSugar,unusedArguments, void, wrap, wrapArguments, wrapAttributes, wrapMultilineStatementBraces, yodaConditions

--binarygrouping 4,8
--closingparen balanced
--commas always
--comments indent
--decimalgrouping 3,6
--elseposition same-line
--hexgrouping 4,8
--ifdef no-indent
--indent 4
--octalgrouping 4,8
--self insert
--stripunusedargs closure-only
--swiftversion 5.1
--wraparguments before-first 
--wrapcollections before-first

And this minimized Swift file:

import Foundation

struct Parser<Input, Output> {
    let run: (inout Input) -> Result<Output, Error>
}

extension Parser {
    func runOn(_ input: Input) -> (match: Result<Output, Error>, rest: Input) {
        var input = input
        let match = self.run(&input)
        return (match, input)
    }

    static func always(_ output: Output) -> Self {
        Self { _ in .success(output) }
    }
}

extension Parser where Output == String {
    func asURL() -> Parser<Input, URL> {
        .always(URL(string: "http://example.com")!)
    }
}

enum Foo {
    static let urlParser = Parser<String, URL> { input in
        let parser = Parser<String, String>.always(input).asURL()
        return parser.runOn(input).match
    }
}

I get this warning when running SwiftFormat:

$ swiftformat --lint --verbose .
Running SwiftFormat...
(lint mode - no files will be changed.)
Reading config file at /Users/juri/Projects/SwiftFormat-unused-broken/.swiftformat
Linting /Users/juri/Projects/SwiftFormat-unused-broken/Example.swift
/Users/juri/Projects/SwiftFormat-unused-broken/Example.swift:26:1: warning: (unusedArguments) Mark unused function arguments with _.
-- rules applied: unusedArguments
SwiftFormat completed in 0.16s.
Source input did not pass lint check.
1/1 files require formatting.

The argument is not unused, though.

nicklockwood commented 3 years ago

Thanks for reporting, I'll get that fixed asap.

nicklockwood commented 3 years ago

@juri fixed in 0.48.13