Support for coding styles and "swift-format" tool


(Daniel Martín) #1

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


(Shawn Erickson) #2

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Jeremy Pereira) #3

+1,000,000

I hate the K&R brace style. :slight_smile:

What I would really like is something similar to Eclipse’s system that pretty much allows you to customise almost every aspect of the Java formatting style to your own preferences and also export them in a handy XML file.

···

On 16 May 2016, at 22:42, Daniel Martín via swift-evolution <swift-evolution@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Jacob Bandes-Storch) #4

It would be awesome if Xcode exposed per-file or per-project formatting
settings, and could enforce them in the editor. I hope someone from the dev
tools group will be able to comment (and help guide the implementation of
this) if there are plans for such a feature.

Jacob

···

On Tue, May 17, 2016 at 7:17 PM, Shawn Erickson via swift-evolution < swift-evolution@swift.org> wrote:

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Adrian Zubarev) #5

+ 1. There are only a few things I wanted to change in my source-code.

e.g.

if … {
}
else {
}

OR

closure() {
…. in
}

MonoDevelop has a really nice customization menu for almost everything. Would be handy if Xcode had something like this too.

···

--
Adrian Zubarev
Sent with Airmail

Am 18. Mai 2016 bei 17:18:49, Jeremy Pereira via swift-evolution (swift-evolution@swift.org) schrieb:

+1,000,000

I hate the K&R brace style. :slight_smile:

What I would really like is something similar to Eclipse’s system that pretty much allows you to customise almost every aspect of the Java formatting style to your own preferences and also export them in a handy XML file.

On 16 May 2016, at 22:42, Daniel Martín via swift-evolution <swift-evolution@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Michael Peternell) #6

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 :wink:
(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@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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution