Referring to my previous question: How can I format boolean operators with perltidy? wondering if it's possible to make a perltidy plugin with my own finer formatting rules? Does perltidy allow this?
Related
Prettier (VSCode) does a great job beautifying my code on save.
There is one feature that I consider important in code formatting which I can't find in Prettier.
I want to align chars =, :, =>, etc., in multiple lines like this VSCode plugin does.
The universal answer to questions like "How can I make Prettier format my code in such a way that ...?" is "You can't."
Prettier's purpose is to facilitate collaboration in projects and teams by taking care of code style, not to be a customizable code formatter that does whatever the user wants. In other words, the formatting it produces isn't really customizable, and this is intentional. Read more here. If you need that degree of control over formatting, you're likely not the target audience for Prettier.
This specific code style (alignment) that you want to have is considered diff-unfriendly (e.g., see here or here). Prettier's line breaking algorithm by itself has similar problems (e.g, adding one argument to a call might lead to a multiline diff if the line becomes too long), but they're inevitable, so Prettier's strategy is to compensate for that by avoiding other diff-unfriendly things.
You could always utilise the Alt key or Code Maid to clean up.
If you hold the Alt Key and drag down then you can highlight the spacing to either remove or align your code.
We would like to sort use statements alphabetically in the beginning of our classes automatically via perltidy or maybe other tool if available. We already use Test::PerlTidy to test if the code is formatted before committing.
I found that Perl::Tidy has the options prefilter and postfilter.
prefilter looks like the better approach, because I can sort the statements as I wish in any logical for me order, then leave it to perltidy to format it.
Would you recommend sorting use statements? The used classes do not depend on using one before the other.
Would you recommend using these Perl::Tidy features?
Is there a better approach?
Has anyone maybe used Intelij as the default merge/diff tool in Eclipse?
I don't know what parameters should be used in the highlighted fields below.
EDIT:
See https://www.jetbrains.com/help/idea/2016.2/running-intellij-idea-as-a-diff-or-merge-command-line-tool.html about what kind of command-line parameters IntelliJ expects for the diff/merge: it seems like you have to add a diff argument first and then use the ${file1Path} and other placeholders separated with spaces, without using any comma nor and.
I want to know if there is a standardized way to declare your prefer diff tool (as for file or directory comparison).
For preferred editor there is the EDITOR environment variable, but I wasn't able to find one for diff.
If not maybe someone wrote a script that can reconfigure most used tools to do this.
EDITOR is usually used by various shells that provide line-editing functionality on certain things like your command history. For example, pressing v in vi-edit mode within bash will bring up the command for editing in your preferred editor.
I'm unaware of any aspects of the shell that do diff processing so the need for a DIFF variable seems unnecessary. If you want to diff some files, just use diff or your preferred one if not diff.
However, nothing is stopping you from writing a program of your own which does use a DIFF variable to perform difference analysis on files.
So I have some formatting rule to follow, such as :
Space on each side of operator (*, =, +, %, etc)
No space at the end of a line
No more than 80 chars per line
Is there a way to highlight in red line containing formating error?
The eclipse auto-formating tool is no good because either :
It will change to many line (old code not written by me)
or it won't (only my code)
Because I must follow some "colorfull" guideline :
You must change formating error relative to operators in old code but nothing else
Your code must be correctly formated.
Any ideas?
Thanks
You can select which lines of code you want to format. The Eclipse formatting tool doesn't have to run across the entire file. To do this: select the lines you want to format, then press Ctrl-Shift-F.
You could try using the Eclipse Checkstyle Plugin.
You'll need to configure it with just the rules that you need (the default configuration is very strict, so create a new one with just the rules you care about).
This will highlight all lines with formatting issues. I don't think it's possible to ignore old code using the plugin.
Talk to whoever created that coding guideline. It does not make sense in the long run, because editing code in Eclipse will always apply all current formatting rules (which violates that guideline) or none, if you disable the formatter (which leads to you writing bad code).
If there is really no way around that guideline, then you should split your workflow into 2 phases: Reformat all existing code one time to fulfill that operator guideline. You may use any tool you like, even just a regular expression search and replace might be fine.
After that has been done, configure Eclipse to auto-format only changed lines, but always apply all formattings to each changed line. There is no good reason to not re-format the other 75 characters in an existing line of code, if you already touched 5 characters of it.