Setup PhpStorm's to reformat code based on phpcs (codesniffer-rules from Squizlabs) - coding-style

I've taken over a code base, where most of the code is following the codesniffer settings from squizlabs/PHP_CodeSniffer.
How do I setup PhpStorm to automatically reformat the code upon saving files; so I always follow those standards. Ideally I would only reformat files that I save (and not unchanged files).
I'm imagining that I'm looking for a 'Import code style from phpcs.xml.dist' or something like that. But I'm not sure.
I'm trying to avoid having going to through all the code styles line for line, figuring out if it should be if ( $blah ) { or if($blah){, and adjusting the values in Settings one setting at the time.
And bonus points, if one can point out how to do this is VSCode, while I'm at it (to help my colleagues).
Attempt 1: Read online ressources
Reformat and rearrange code
Configuring code style
EditorConfig for PhpStorm
Copy code style settings
Attempt 2: Read around 'Settings'
I went to 'Settings' >> 'Editor' >> 'Code Style' (and also >> 'PHP'). I found the 'Set from'-button, so I could set it to follow Symfony2's code style. But I'm not sure if that follows squidlabs conventions.
I also read around, to see if I could find a 'Generate code styles from code'.
Attempt 3: Generate code style from code
I know that it's a tall order, but I would have been cool, if I could have pointed PhpStorm to a couple of correctly formatted files - and then get PhpStorm to automatically generate the code style from those files. I couldn't find this.
I tried this by trying to copy some of the well-formatted code from the project into the editor in the settings-box, to see if a 'Adjust values based on example code'. But I couldn't find this.

I found the answer by carefully reading this post here: PHP_CodeSniffer.
There are several steps to it - and it's highly customizable:
Only 'flag' editted lines
Only 'flag' editted files
Which standards to use
Should it show it as a warning or an error.
Etc...
That combined with: The 'reformat on save' I found in 'Settings' >> 'Actions on save'.

Related

How to toggle line coverage in Xcode

I don't know how to turn on and off the side bar which shows code coverage in a given file.
I've googled a bunch of terms but they all turn up how to enable code coverage in the scheme. I am specifically referring to the coverage the shows up in the code inspector like such:
If you know how to toggle this on/off please advise. Bonus points if you can tell me the name of this column.
Editor > Show Code Coverage
Note though that this is not a per-file setting.
Also, there is a setting for toggling iteration counts in Preferences > Text Editing > Editing (if you only want red/green status indicators)
Now, regarding the bonus part, it seems that there is no reference for this 'column' so I guess the best chance is to either ask the folks at Apple in the dev forums or crawl through wwdc transcriptions hoping to find a reference on some demo of the feature.

How to change multiple entries in config files

I notice in VS2013 that if I highlight text with a view to making a change, the same text is highlighted elsewhere in the file. However, I can't seem to find the option to reflect the change in multiple places when I start typing.
Is this feature just for information only or can I actually do multiple replacements by typing the change once?
This is not supported out of the box.
But there is a nice plugin you can use to enable this, called MultiEditing.
H/T to Scott Hanselman :)
Also note that even in standard VS2013, you can edit multiple lines by "box-highlighting".
This is where you create a "box-selection" either by holding down Alt and dragging a box around the text, or by Alt+Shift+ArrowKeys. Then start typing and the same text will appear on multiple lines.
e.g. with the following text:
Some text to demonstrate
Some info to demonstrate
Some more to demonstrate
...if you Alt+drag a box-selection around all 3 occurrences of the word to, and then type which, it will look like this:
Some text which demonstrate
Some info which demonstrate
Some more which demonstrate
This also works with copy/paste - the pasted text gets applied to all lines within the box-selection.
It's pretty hard for me to describe here, so try it yourself!

How do I add features to a syntax definition in Sublime Text without editing it?

For example, I would like to highlight #param, #type, and #return (i.e. epytext declarations) in my Python docstrings. I have figured out how to do this by simply editing Python/Python.tmLanguage; however, I would really like to put this in its own file, for a couple of reasons:
I don't always want to apply this highlighting. It's only for projects that use epydoc as their documentation tool; in other projects, I would want to highlight reStructuredText instead.
When Sublime Text updates, I'd like to have my own syntax as an overlay onto the included features. there are several features of Python that Sublime's author may choose to include in future versions and I don't want to have to manually figure out what I changed each time an update modifies the base Python syntax definition.
I keep my own editor configuration in version control, but I want that to be my own original stuff; I don't want to be burdened with having to carry copies (possibly proprietary? I don't know, it doesn't seem to have an independent license) of syntax definitions that come with Sublime.
Is there a way to put highlighting rules into a separate file, perhaps to only be applied to a particular scope?
Sounds to me like you want to create your own syntax file, inherit from the Python syntax file (source.python), and make your changes and customizations there. Sublime Text 2 uses the .tmLanguage format for syntax files, which is a bit complex, but fortunately most of the work has already been done for you, just by inheriting from source.python.
What you want to do is set up a regex pattern to match the substrings that you want to highlight, and give that pattern a name; something like punctuation.definition.comment.epydoc, to follow the convention set in Java/JavaDoc.tmLanguage. Then, check your color scheme file (ending in .tmTheme) and make sure there are settings for the scope that you've chosen -- or for one of its parents, since ST2 should use proper scoping rules for this sort of thing.
To use the syntax file you've created, stick it in Packages/User (so that ST2 doesn't overwrite it on upgrades), open a Python file in the editor, and then select your new syntax from the dropdown list in the bottom right corner of the window. If you've set up everything correctly, the epydoc strings should change to be whatever color you've set in your color scheme.
Good luck! And post a link somewhere when you've got a syntax file that works, so others can see and use it, as well!

How can I change the template CodeRush uses when it extracts a method?

When I extract a method in CodeRush, it has some default formatting. I'd like to change it. Specifically, when I choose the location of the extracted method, CodeRush smashes it in, directly above the method I put the location marker at.
So:
When I choose to drop the extracted method, like this:
It ends up looking like this:
What I want is for it to have some control over how the method looks, at the moment I want to add some blank lines between it and the next method. How can I do that?
Open the DevExpress -> Options dialog;
Go to the Editor | Code Formatting | Blank Lines option page;
Toggle the 'After multi-line members' option.
I requested this here: http://www.devexpress.com/Support/Center/p/S130722.aspx
It got implemented here: http://www.devexpress.com/Support/Center/p/S19229.aspx
There's now a massive formatting subsystem I spent 3 hours fighting that tries to outdo ReSharper's massive formatting subsystem which both need to be able to survive VS Autoformat (CtrlK D) and don't always.
Now you know it's there, I'd appreciate a quick summary from you as to whether you were able to make it do what you wanted!

Is there a plugin for GEdit that allows me to add inline commments - like to-dos - to my code? Specialities described below

I'd like to add comments to my code (NOT commenting out lines), specifically for the period of programming and not for later use as a documentation. I just want to chalk up some task for myself inline in the code, which should automagically disappear if I distribute only the source code file.
Aside from normal "comments" while these comment appear in the source code, I don't want them to take up any line numbers, and they should be collapsible with a single click of a button. You can think of it as a meta-document to the real document (stored in a separate text file).
The idea is from Github, where you can add comments to any line of code.

Resources