Joshua Gardner 10 Posted yesterday at 05:07 AM We're excited to share the first public release of pasfmt, a free and open-source code formatter for Delphi. It is a complete and opinionated formatting tool.  The latest release has support for: Complete line wrapping (and unwrapping) for all Delphi structures Configurable line length limit Removing trailing whitespace Change spacing around all tokens (e.g., operators and keywords) Parallel file formatting with directory traversal Removing repeated empty newlines Line ending normalisation  To get started, either try our web demo, or download the executable (this one for Windows) and follow the getting started guide.  Additionally, there is an IDE plugin with support for: In-editor formatting Format-on-save Cursor tracking  You may be wondering how this tool compares to the existing formatters (e.g., GExperts, JEDI, Formatter.exe). This tool goes a lot further than the alternatives by having a complete opinion on how every line should be wrapped or unwrapped; the original layout is (almost) ignored. By ignoring most of the input format, it produces consistently styled code across a whole codebase.  We hope that you enjoy pasfmt, let us know what you think! 6 2 Share this post Link to post
Der schöne Günther 323 Posted yesterday at 07:30 AM Haven't played around with it much yet. For my taste, turning it on or off via // pasfmt off is a bit to unobtrusive. I think it should stick a bit out more so you immediately see. Something like #[rustfmt::skip] somehow just catches your eye better. Maybe it could also be possible via {$DEFINE NO_FORMAT}? That would also give us syntax highlighting for these parts.     Share this post Link to post
Lars Fosdal 1806 Posted yesterday at 07:33 AM My formatting is so quirky that I prefer to hand-craft it. 1 Share this post Link to post
Attila Kovacs 640 Posted yesterday at 07:38 AM (edited) Multiline strings seem to be handled correctly. How about ignoring specific parts of the code? Is there a directive for that?  There is. Looks great! // pasfmt off Edited yesterday at 07:39 AM by Attila Kovacs 1 Share this post Link to post
Jonah Jeleniewski 17 Posted yesterday at 07:44 AM Just now, Attila Kovacs said: Multiline strings seem to be handled correctly. How about ignoring specific parts of the code? Is there a directive for that? Yes, you can disable formatting with special comments:Â // pasfmt (on/off) See Disabling formatting for more information. 1 Share this post Link to post
Zane 1 Posted yesterday at 09:09 AM 1 hour ago, Attila Kovacs said: Multiline strings seem to be handled correctly. How about ignoring specific parts of the code? Is there a directive for that?  There is. Looks great! // pasfmt off The handling for multiline strings and multiline comments is pretty minimal at the moment. It knows how to parse them and therefore can avoid mangling them (unlike some other Delphi formatters).  In a future release we would like to have the formatter rewrite the inside of multiline strings and comments such that they can be indented/deindented, and (in the case of comments) re-flowed. 1 Share this post Link to post
Sherlock 670 Posted yesterday at 09:42 AM 4 hours ago, Joshua Gardner said: It is a complete and opinionated formatting tool.  What does opinionated mean in this context? Share this post Link to post
dummzeuch 1561 Posted yesterday at 10:53 AM 5 hours ago, Joshua Gardner said: Additionally, there is an IDE plugin with support for: In-editor formatting Format-on-save Cursor tracking Am I right in assuming that the plugin calls the executable to do the formatting? Calling an executable is rather expensive (meaning: slow) in Windows, it would be really nice it you could also produce a DLL, that can be called from this plugin (and possibly other tools). 32 and 64 bits, if possible. 1 Share this post Link to post
pyscripter 715 Posted yesterday at 01:11 PM And incidentally, for whoever has not tried it, Delphilint from the same group, really rocks. 2 Share this post Link to post
timfrost 81 Posted yesterday at 02:58 PM 5 hours ago, Sherlock said: What does opinionated mean in this context? In England, at least, I understand the word as "holding to one's own opinions and ideas too strongly"; "obstinate"; "unwilling to be corrected"; "inflexible". In other words, not the most desirable qualities I need in a tool which will be adjusting and improving whatever I have carefully written. But I accept that this may just be an accident of translation which is not intended for this context. Share this post Link to post
Zane 1 Posted yesterday at 09:15 PM 10 hours ago, dummzeuch said: Am I right in assuming that the plugin calls the executable to do the formatting? Calling an executable is rather expensive (meaning: slow) in Windows, it would be really nice it you could also produce a DLL, that can be called from this plugin (and possibly other tools). 32 and 64 bits, if possible. You are right that the plugin calls the executable. I've addressed this comment over on the repository where an issue was raised. https://github.com/integrated-application-development/pasfmt/issues/159#issuecomment-2672690523 Share this post Link to post
Glenn Dufke 23 Posted 23 hours ago (edited) 17 hours ago, Joshua Gardner said: We hope that you enjoy pasfmt, let us know what you think! Great idea crumbled by rust. There are other languages which would have been more appropriate to use for the implementation and would make contributions easier. Sad. And to expand on that: When picking an implementation language, besides evaluating what solves the problem at hand, you also have to consider target community and who are going to deal with it down the line - especially for open source projects and that weighs higher than one's favorite language. Rust has a toxic community, an ecosystem mess akin to npm and overall just a poorly designed language with unnecessary complexity driven up by hype. (I know this from first hand experience of having to deal with rust projects before and digging inside the rust compiler) While some have drunk the rust kool-aid, I'd rather have seen Modern Object Pascal used or, if you want to be fancy, Zig. There are good reasons why many prominent projects are abandoning rust. Edited 22 hours ago by Glenn Dufke 3 Share this post Link to post
Joshua Gardner 10 Posted 22 hours ago 13 hours ago, Sherlock said: What does opinionated mean in this context?  It is a fair enough question. In the context of a code formatter, it means that it has a strong opinion on what the code should look like. Predominantly, this manifests in having few or no configuration options and a highly consistent style. Other formatters like prettier, biome, and google-java-format call themselves opinionated. 1 1 Share this post Link to post
pyscripter 715 Posted 22 hours ago (edited) Just now, Joshua Gardner said: Other formatters like prettier, biome, and google-java-format call themselves opinionated. As well as python's black.  Quote Black is a PEP 8 compliant opinionated formatter  Edited 22 hours ago by pyscripter Share this post Link to post
Stefan Glienke 2036 Posted 22 hours ago Looks great - as always: spring4d source for the real test and it seems to stumble at a few places where it then goes into "line breaks go to 11" mode - here for example:   or  Share this post Link to post
pyscripter 715 Posted 21 hours ago (edited) Talking about capitalization, the Delphi Style Guide: is quite clear about: using "Pascal casing" (e.g. MyData) across the board (variables, parameters etc..) fields starting with a capital F. avoiding prefixes such as lData for local variables or aFileName for parameters.  The Delphi RTL mostly complies with the above recommendations, but much of the Delphi code around does not. There is also a lot of variation regarding the use of prefixes in control names inside Forms.  Spring4D in particular uses camelCasing for parameters and local variables, small f for fields and uses Pascal casing for function/procedure names and properties.  @Stefan Glienke Is this just a matter of taste?  I can see some advantages in the following convention (a hybrid of the DSG and the spring4d conventions): Properties/function/procedure names use Pascal casing - Inside the class use the field name instead of the corresponding property name. Function/procedure parameters use camelCasing Fields start with F Local variables follow Pascal casing Global variables (just avoid using). In this way you could immediately tell if any variable is a parameter, a local variable or a field without littering the code with ugly prefixes and the like (except for the now established F for fields). And if you follow the rule about properties and avoid with statements, then you would almost always refer to properties using the dot notation.  I am not actually using this currently, trying to stick to the Delphi Style Guide.  Any thoughts? What is you preferred convention and why?  @Joshua Gardner Does the "opinionated" pasfmt take a view on capitalization? Edited 21 hours ago by pyscripter Share this post Link to post
Vincent Parrett 806 Posted 20 hours ago 48 minutes ago, pyscripter said: I can see some advantages in the following convention (a hybrid of the DSG and the spring4d conventions): I follow that except I also use camelCase for local variables.  An opinionated formatter that doesn't allow me to configure to my taste is unfortunately not going to cut it. I also do weird things like align assigments in constructors  constructor TMyClass.Create(x : integer; y : integer; const theName : string); begin Fx := x; Fy := y; FName := theName; end; and for constants const cMyConst = 'test'; cAnotherConst = 'foobar';  No formatter I have tried can cope with that. Share this post Link to post
Dave Nottage 580 Posted 20 hours ago 34 minutes ago, Vincent Parrett said: No formatter I have tried can cope with that. None of them have a: "Don't touch my assignment alignments" option? 🙂  1 Share this post Link to post
Vincent Parrett 806 Posted 19 hours ago Just now, Dave Nottage said: None of them have a: "Don't touch my assignment alignments" option? 🙂 Sadly not. I don't want to be littering my code with //formatting off/on etc. So I format by hand and it is what it is.  2 Share this post Link to post
Joshua Gardner 10 Posted 19 hours ago 19 minutes ago, pyscripter said: @Joshua Gardner Does the "opinionated" pasfmt take a view on capitalization?  A good question! At this point in time, we strive to not modify any tokens, for safety. We have tentative plans to implement keyword lowercasing in the future. For identifiers, we feel strongly that the identifier should match its declaration, however, this tool doesn't have any semantic information to be able to enforce this. Our other tools sonar-delphi in conjunction with delphilint are much better suited to that task. Share this post Link to post
Joshua Gardner 10 Posted 19 hours ago (edited) <deleted duplicate post> Edited 19 hours ago by Joshua Gardner Share this post Link to post
Glenn Dufke 23 Posted 19 hours ago 47 minutes ago, Vincent Parrett said: I don't want to be littering my code with //formatting off/on etc. What you want in a formatter is a simple DSL where you can express your desired formatting style and the formatter uses this as the basis.. I'm glad you asked... Share this post Link to post
Jonah Jeleniewski 17 Posted 18 hours ago (edited) 37 minutes ago, Glenn Dufke said: What you want in a formatter is a simple DSL where you can express your desired formatting style and the formatter uses this as the basis.. I'm glad you asked... While not aligned with the goals of this project, that's an interesting concept. Can't say I'm aware of any well-known formatting tools that operate in such a way, though. Edited 18 hours ago by Jonah Jeleniewski Share this post Link to post
Glenn Dufke 23 Posted 18 hours ago Just now, Jonah Jeleniewski said: While not aligned with the goals of this project, that's an interesting concept. Can't say I'm aware of any well-known formatting tools that operates in such a way, though. Well, it's an interesting concept because I created one in my formatter engine which is multi language and support mixed source documents among other cool features. - And it is high performance without using rust 🙃 Share this post Link to post
Jonah Jeleniewski 17 Posted 18 hours ago Just now, Glenn Dufke said: Well, it's an interesting concept because I created one in my formatter engine which is multi language and support mixed source documents among other cool features. - And it is high performance without using rust 🙃 Sounds cool. You should write a blog post on how you architected your tool. Differing philosophies aside, I'd be interested to read it. Share this post Link to post