[swift-evolution] Support for coding styles and "swift-format" tool

Michael Peternell michael.peternell at gmx.at
Wed May 18 16:46:41 CDT 2016


What I would like even more is editor support with this stuff. And I think the "swift-format" tool could probably help here too.

I remember a time when we had problems with LF vs. CR vs. CRLF line endings. How did Sublime Text Edit (or any other sane editor) solve this issue? Do we all have to agree on the line ending? Do I open a file with CRLF line endings, the editor supports it, and my line endings are added as LF? No... it opens the file, sees that the line endings are CRLF and whenever I add a line ending somewhere in the file, it adds CRLF characters there. Since a few years, programmers have no problems with line endings anymore (unless you're writing text editor software maybe.)

Why is the same not possible for formatting styles? It can open the file, detect the indentation level (4 spaces, 5 spaces, a TAB, ...), brace style (Egyptian brackets, K&R, Linux kernel style, one true brace style, ...) and then display it to me as being in Linux kernel style. When I press "Save", it converts the lines that I added to the prominent format that was already present in the file. My co-workers will be happy that I finally abide to their coding style. I will be happy because I can finally use the one and only real coding style ;)
(of course you'll have to think about the details. e.g. what happens to commented-out code blocks? what happens to line numbers? There is value in having agreed-upon line numbers in the code view. all of this is solvable though.)

-Michael

(if you are stealing my idea, you'll have to send me a free copy of the editor you've built :-o )

> Am 18.05.2016 um 04:17 schrieb Shawn Erickson via swift-evolution <swift-evolution at swift.org>:
> 
> I would love to see flexible formatting styles be more easily available like this.
> 
> -Shawn
> 
> On Tue, May 17, 2016 at 10:33 AM Daniel Martín <swift-evolution at swift.org> wrote:
> As Swift is getting traction in more and more platforms outside of
> Apple, we can expect that many coding styles different from what Apple
> imposes with SourceKit's indenting rules will emerge. According to
> https://bugs.swift.org/browse/SR-146, we now have decoupled indenting
> logic from SourceKit into its own library, and a "swift-format" tool is
> in the making.
> 
> I am working on adding support for different coding styles to libIDE.
> For example, with my changes you could decide how a case label should be
> indented with respect to its parent switch context, among other things.
> The current, hard coded indenting decisions in libIDE could be named the
> "Apple" style, just like Clang supports Google, LLVM, Mozilla, coding
> styles for C++. Also, this is something that can be supported by
> external tools like Xcode quite easily.
> 
> Do you think this is a good feature to have?
> 
> --
> Daniel Martín
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list