<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Separate from compiler-enforced policies, I’d *love* to see someone tackle implementing a "go fmt” analog that reformats Swift code into a standard style, as well as a “clang format” tool that could be used by IDEs for on-the-fly editing of code, as well as a “linter” / static analysis tool which can flag potential issues while having a higher tolerance for false positives. These should be separate from the “always on” compiler diagnostics though.</blockquote><div><br></div><div>I agree that a compiler cannot be too stylistically opinionated, and that an opt-in, standalone linter/formatter is preferable.</div><div><br></div><div>As others have mentioned, there's a community-built tool called <a href="https://github.com/realm/SwiftLint">SwiftLint</a> that does much of this today. It's an AST-assisted tool to enforce code style conventions & automatically correct certain violations. Rules can be enabled/disabled and parameterized either inline in the source or via a YAML configuration file.</div><div><br></div><div>One of the tool's main limitations so far is that the Swift AST it operates on is obtained from a reverse-engineered SourceKit interface and is incomplete.</div><div><br></div><div>Myself and other SwiftLint contributors intend to replace the reverse-engineered SourceKit backend with more official tooling that was just open sourced, which will enable SwiftLint to do things like an opinionated go-fmt/clang-format style formatting (source->AST-source) and some types of static analysis like identifying cyclomatic complexity.</div><div><br></div><div>One thing I'd like to discuss with relevant Swift project owners (notably Argyrios and Chris) is the possibility of moving SwiftLint development into <a href="http://github.com/apple">github.com/apple</a>, which would increase the tool's exposure and pace of development. I hope to make a more official proposal for how that transition could happen in the upcoming week, probably in swift-dev.</div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Sun, Dec 6, 2015 at 9:07 AM, Erica Sadun via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Dec 5, 2015, at 11:15 PM, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
> Separate from compiler-enforced policies, I’d *love* to see someone tackle implementing a "go fmt” analog that reformats Swift code into a standard style, as well as a “clang format” tool that could be used by IDEs for on-the-fly editing of code, as well as a “linter” / static analysis tool which can flag potential issues while having a higher tolerance for false positives. These should be separate from the “always on” compiler diagnostics though.<br>
><br>
> -Chris<br>
<br>
</span>I have a fairly minimal held-together-by-bandaids linter I put together:<br>
<br>
<a href="https://github.com/erica/testlint" rel="noreferrer" target="_blank">https://github.com/erica/testlint</a><br>
<br>
I have hesitated to develop it much further because I didn't want to be committed to inter-process SourceKit hacking and did not yet have access to a reliable parse tree. In its current state, it's a regex-based line-by-line scan.<br>
<br>
The rules it follows are here: <a href="https://github.com/erica/testlint/blob/master/testlint/sources/Linter.m" rel="noreferrer" target="_blank">https://github.com/erica/testlint/blob/master/testlint/sources/Linter.m</a><br>
with fairly copious commenting<br>
<br>
<br>
-- Erica<br>
<div class=""><div class="h5"><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div></div>