Comments (7)
@rogerluan this was actually a known issue with the rule, which was fixed in a later version by limiting it to only anonymous closure arguments (from the known issues section of the README):
The trailingClosures rule can generate ambiguous code if a function has multiple optional closure arguments, or if multiple functions have signatures differing only by the name of the closure argument. For this reason, the rule is limited to anonymous closure arguments by default. You can use the --trailingclosures and --nevertrailing arguments to explicitly opt in or out of trailing closure support for specific functions.
So I think it should be safe to re-enable it for your project now.
from swiftformat.
Does the redundantParens rule not already do this?
from swiftformat.
Nope @nicklockwood 😢 it's not a covered use case/example in the docs, and I also tested and it doesn't modify my code
from swiftformat.
@rogerluan oh sorry you're right - I was actually thinking of the trailingClosures rule.
I just tested it with all your examples and it seems to work (it's also enabled by default).
from swiftformat.
Oooh. I've explicitly disable trailing closures for some reason, I can't remember why now. I'll test it and try to remember why I disabled it as it might've been some bug 😅 I'll report back. Thanks for the help!
from swiftformat.
Ah, I remembered. In one of the projects I worked on, there was a overloaded function that used to cause issues, so I disabled this rule. It was weird, but an overview of the issue would be:
- When using the trailing closure with parenthesis and explicit argument name, it would use Overloaded Function A, which was OK
- When omitting the trailing closure parenthesis (and thus removing the explicit argument name of the closure), it would pick up Overloaded Function B, which crashed (as it had a
preconditionFailure()
inside of it, intentionally).
The issue was that due to some poor API design those two overloaded functions were only differing in the name of the closure argument IIRC (can't remember the details or give concrete examples tbh).
I don't think that is an issue that SwiftFormat should resolve haha and I see no reason to not enable this rule in all other projects :) Thanks for pointing this to me! We can close this issue 🚀
from swiftformat.
That's great to hear!! 🤩 It was indeed a long time ago and I didn't realize this has been fixed since then 😁
Thank you once again!
from swiftformat.
Related Issues (20)
- Question: Wrap function calls HOT 7
- `hoistAwait` removes necessary `await` for operators/functions with async autoclosures. HOT 5
- opaqueGenericParameters cannot be disabled? HOT 8
- `Alman = false` in combination with long char count in line breaks the `{` into a new row HOT 7
- redundantReturn removes return statements of consecutive if statements HOT 4
- conditionalAssignment matches expression within try block HOT 11
- conditionalAssignment rule HOT 4
- doesn't recognize both --disable all and // swiftformat:disable all HOT 1
- Make blankLinesAroundMark prioritized over blankLinesAtStartOfScope
- Compile error with conditionalAssignment and Swift version 5.9 HOT 5
- App doesn't manage non-rule config file options HOT 1
- Compiler error with 5.9 conversion to switch expression HOT 1
- Swift warning: BuildTools should be located under 'Sources/BuildTools' HOT 1
- How do I use the `--funcattributes prev-line` rule in the config file? HOT 2
- Outputted code doesn't build HOT 3
- error: 'switch' may only be used as expression in return, throw, or as the source of an assignment HOT 3
- error: Failed to write file <File Location> HOT 11
- Wrapping nested calls HOT 1
- docComments removes macro documentation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftformat.