Code Monkey home page Code Monkey logo

Comments (7)

nicklockwood avatar nicklockwood commented on June 18, 2024 3

@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.

nicklockwood avatar nicklockwood commented on June 18, 2024

Does the redundantParens rule not already do this?

from swiftformat.

rogerluan avatar rogerluan commented on June 18, 2024

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.

nicklockwood avatar nicklockwood commented on June 18, 2024

@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.

rogerluan avatar rogerluan commented on June 18, 2024

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.

rogerluan avatar rogerluan commented on June 18, 2024

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.

rogerluan avatar rogerluan commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.