Closed christopher-hof closed 4 years ago
The rule supports an included
key (not excluded
)
implicit_return:
included:
- closure
- getter
also doesn't seem to work.
// This still triggers a violation
private func trimValue(_ value: String?) -> String {
return (value ?? "").trimmingCharacters(in: CharacterSet.whitespaces)
}
I have the same problem and did some more research, but don't really understand the problem.
I checked out Yams and added a new unit test:
let string = try String(contentsOfFile: "/tmp/swiftlint.yml")
guard let yaml = try Yams.load(yaml: string) as? [String: Any],
let ruleConfig = yaml["implicit_return"] as? [String: Any] else {
throw NSError()
}
var rule = ImplicitReturnConfiguration()
try rule.apply(configuration: ruleConfig)
XCTAssertTrue(rule.includedKinds.contains(.getter))
XCTAssertTrue(rule.includedKinds.contains(.closure))
XCTAssertFalse(rule.includedKinds.contains(.function))
XCTAssertTrue(rule.severityConfiguration.severity == .warning)
Config file:
implicit_return:
severity: warning
included:
- getter
- closure
or with default severity:
implicit_return:
included:
- getter
- closure
the unit test passed for both inputs. However, swiftlint rules
only works for the first config file, otherwise it outputs
Loading configuration from '.swiftlint.yml'
Invalid configuration for 'implicit_return'. Falling back to default.
However, no matter what you put in the config file, the implicit_return
rule doesn't seem to care much about the config anyway. In swiftlint rules
it always reports: | warning |
but according to the source code it should also tell you what ReturnKind
s are currently active the default
I'm using the configuration:
implicit_return:
included:
- closure
Most of the time, the rule behaves as expected, but occasionally, I'll get warnings for function and getter returns. I haven't yet been able to figure out if there's some environmental change that's causing some of the lint runs to obey the configuration and some to not, or if it's truly nondeterministic.
I'm not sure if it's relevant, but swiftlint rules
always shows the configuration as
warning, included: [SwiftLintFramework.ImplicitReturnConfiguration.ReturnKind.closure, SwiftLintFramework.ImplicitReturnConfiguration.ReturnKind.function, SwiftLintFramework.ImplicitReturnConfiguration.ReturnKind.getter]
Looks like after changing implicit_return
configuration in yaml file we should run once swiftlint --no-cache
Still not working
Release 0.40.0 fixed this issue.
implicit_return:
included:
- closure
- getter
now works as intended.
Using a config still doesn't work for me in 0.42.0
It looks like ImplicitReturnConfiguration
is initialized without passing any config and just uses the default arguments?
@cprovatas all rules are initialized with some default configuration, and then that configuration is mutated with the overrides from your configuration file so that's expected.
I got it working now. Thanks
New Issue Checklist
Describe the bug
I'm trying to configure the 'implicit_return' so it does not trigger for functions (only for 'getter' and 'closures'). But the following configuration does not seem to work.
Environment
swiftlint version
to be sure)? 0.38.2xcodebuild -version
)? 11.3 (11C29)