cljfmt support / stand-alone code-style checker

349 views
Skip to first unread message

dennis....@uni-heidelberg.de

unread,
Mar 24, 2017, 6:05:55 AM3/24/17
to Cursive
Hello!

Cursive has a built in code formatter, but to be able to check correct code-style on our project from within our code-review system, I need to run a stand-alone tool. For that I use cljfmt [1], which uses a different style than what Cursive has built-in.

Would it be possible to, either:
1. Support cljfmt as a code-styler within Cursive, or
2. Provide the cljfmt code-style as a preset within Cursive, or
3. Provide the Cursive built-in code-style as a cljfmt setting, or
4. Provide Cursive's code-styler as a stand-alone tool?

cljfmt uses a settings format to define the code-style [2]. Maybe Cursive could learn to import code-styles in format (just like it currently imports "IntelliJ IDEA code style XML" and "Eclipse XML Profile"), so that I could import the cljfmt default style [3] into Cursive?

Best regards,
Dennis

[1]: https://github.com/weavejester/cljfmt
[2]: https://github.com/weavejester/cljfmt#indentation-rules
[3]: https://github.com/weavejester/cljfmt/tree/master/cljfmt/resources/cljfmt/indents

Colin Fleming

unread,
Mar 26, 2017, 7:48:17 PM3/26/17
to cur...@googlegroups.com
Hi Dennis,

Yes, I would definitely like to support one or more of these options, but I haven’t investigated them yet. In the meantime, do you have a particular case that you’re trying to fix? It’s possible we could come up with a Cursive equivalent format set by hand, and that’s something I’d be very interested in helping with.

Cheers,
Colin

--
You received this message because you are subscribed to the Google Groups "Cursive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cursive+u...@googlegroups.com.
To post to this group, send email to cur...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cursive/fabc6abd-a3e1-4789-ac7f-c2d3c2f43154%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Nelson

unread,
Mar 26, 2017, 8:50:49 PM3/26/17
to cur...@googlegroups.com
I'd be very interested in extracting Cursive's formatting rules (including codeStyleSettings.xml) into an external tool for integration with git pre-commit hooks/CI formatting checker.

Colin, is there any chance of you seeding a github project, or is your code too coupled to the IntelliJ AST?


For more options, visit https://groups.google.com/d/optout.
--
Stephen Nelson | Platform Lead Developer | Montoux
e.      ste...@montoux.com
t.      @montoux
w.      montoux.com

Colin Fleming

unread,
Mar 26, 2017, 9:56:10 PM3/26/17
to cur...@googlegroups.com
So… I’m not sure. The code is very intimately tied to the IntelliJ AST and formatting engine. However there is a way to use the formatting from the command line using a standalone tool, but I’ve never tried it. There’s some doc here: https://confluence.jetbrains.com/display/IDEADEV/Command-Line+Source+Code+Formatter. It requires an IntelliJ install, but I don’t know if it requires a UI - that might make it a non-starter for a CI environment. 

However I suspect that this may not work correctly with Cursive. Cursive is unusual because it requires symbol resolution to do the formatting, since the formatting for a particular form is driven by symbol resolution on the head form - normally languages with more syntax don’t have this requirement because once you’ve parsed the program source you have an AST, but with Clojure you just have a bunch of data structures. You need either a static analysis to do proper symbol resolution (Cursive’s approach) or you have to eval code. Anyway, the upshot is that the symbol resolution that Cursive requires for formatting generally requires a project context, which it sounds like the offline tool doesn’t provide. Experience reports very welcome :-)

The other option, which is probably more tractable and might be more generally useful, would be for Cursive to be able to produce a cljfmt config doc based on the current IntelliJ settings. I’m not familiar enough with cljfmt to know if that’s possible yet. I suspect it’s not 100% possible, since Cursive supports some features (map value alignment, for example) which a cursory look over the cljfmt repo suggests it doesn’t support. I don’t know how difficult it would be to make it support those features, I suspect it’s quite hard. It really requires a general constraint solving algorithm, which is what IntelliJ uses for its formatting.


Dennis Schridde

unread,
Mar 27, 2017, 5:10:46 AM3/27/17
to cur...@googlegroups.com, Colin Fleming
Hi!

On Montag, 27. März 2017 03:56:05 CEST Colin Fleming wrote:
> The other option, which is probably more tractable and might be more
> generally useful, would be for Cursive to be able to produce a cljfmt
> config doc based on the current IntelliJ settings. I’m not familiar enough
> with cljfmt to know if that’s possible yet. I suspect it’s not 100%
> possible, since Cursive supports some features (map value alignment, for
> example) which a cursory look over the cljfmt repo suggests it doesn’t
> support. I don’t know how difficult it would be to make it support those
> features, I suspect it’s quite hard. It really requires a general
> constraint solving algorithm, which is what IntelliJ uses for its
> formatting.

Would it be possible, as a starter, to just export those rules that cljfmt
understands? I.e. start with basic indention of forms and integrate more
complex rules later, possibly after they have been implemented in cljfmt?

--Dennis
signature.asc
Reply all
Reply to author
Forward
0 new messages