ReSharper post clean-up object initializers violate StyleCop rules - resharper

After updating Resharper and StyleCop, post clean-up object initializers now look like this:
var foo = new Foo {
Bar = 1,
Baz = 2
}
How I want them to look, and how StyleCop expects them to look is:
var foo = new Foo
{
Bar = 1,
Baz = 2
}
I've been playing with the line brake and brace settings, but am not having any luck so far.

The issue was that I had line wrapping turned off, but had the chop always setting enabled for object initializers. Evidently, the chop always setting for line wrapping ignores the braces setting for object initializers.

Double check some of your settings and maybe post what you have them set to. Under:
ReSharper Settings > Code Editing > C# > Formatting Style > Braces Layout
You should check that
Array and object initializer
is set to
At next line (BSD style)
Also check your Visual Studio Settings so that
Text Editor > C# > Formatting > New Lines > New Line options for braces > Place open brace on new line for object initializers
is checked

Related

How to apply indentations settings for comment line (IntelliJ IDEA / Android Studio)

I certainly know how to use the line comment shortcut, ctrl + /, but for some reason the comment starts at the end of line.
If I start with this code:
if (something) {
return 5;
}
And use the shortcut from IntelliJ, I end up with:
if (something) {
// return 5;
}
But I expect things to look like this:
if (something)
// return 5;
}
Is there any way to configure this in IntelliJ? I tried changing the code syntax rules for my target language, but it didn't change anything.
This setting can be changed in (Settings / Preferences -> Editor -> Code Style -> Java -> Code Generation)
Options:
Line comment at first column.
Block comment at first column.
It should work both for Android Studio and IntelliJ IDEA.

Can Resharper ignore spaces in declaration statements?

I prefer using Align Assignments
Aligns assignment statements by typing Ctrl+Alt+]. For example, typing Ctrl-Alt-] when the following is selected:
MaxMultiplier = bonusMathModel.MaxMultiplier;
MaxFreeGames = bonusMathModel.MaxFreeGames;
MultiplierQueueMode = MultiplierQueueMode.OVERLAPPED;
OverlappedMultiplierOperator = OverlappedMultiplierOperator.ADDED;
Transforms it into this:
MaxMultiplier = bonusMathModel.MaxMultiplier;
MaxFreeGames = bonusMathModel.MaxFreeGames;
MultiplierQueueMode = MultiplierQueueMode.OVERLAPPED;
OverlappedMultiplierOperator = OverlappedMultiplierOperator.ADDED;
However, Resharper ctrl-alt-f cleanup will undo the align assignments. How can I change Resharper's behavior so that it preserves Align assignments?
I think you'll have to create a new Clean-up profile with Reformat Code set to No and use that instead.
You can't mix and match the convenience of automatic reformatting with custom spacing. Resharper isn't to know which additional spaces are deliberate and which are accidental.

How to Access a Class through "Ctrl+Click" in Sublime Text 3

I've got this class as an example:
Which plugin do I use to be able to click on:
PHPUnit_Framework_TestCase
And get to the class?
class PracticeTest extends PHPUnit_Framework_TestCase {
public function testHelloWorld() {
$greeting = 'Hello, World.';
$this->assertTrue($greeting === 'Hello, World.');
}
}
Right now I have to manually search for it. I know PHPStorm has this functionality and I believe Sublime must have a plugin for it.
Thanks a lot.
Click on class name that you want to jump and press f12.
Avalance pointed in the comments to a threat that hinted to SublimeCodeIntel.
And indeed SublimeCodeIntel allows for the behaviour I needed:
See here:
https://github.com/SublimeCodeIntel/SublimeCodeIntel#using
The solution to jump to definition is this:
For Mac OS X:
Jump to definition = Control+Click
Jump to definition = Control+Command+Alt+Up
Go back = Control+Command+Alt+Left
Manual Code Intelligence = Control+Shift+space
For Linux:
Jump to definition = Super+Click
Jump to definition = Control+Super+Alt+Up
Go back = Control+Super+Alt+Left
Manual Code Intelligence = Control+Shift+space
For Windows:
Jump to definition = Alt+Click
Jump to definition = Control+Windows+Alt+Up
Go back = Control+Windows+Alt+Left
Manual Code Intelligence = Control+Shift+space

Line Breaks and Wrapping

In my Resharper options the Right Margin was set to a low value which made my code wrapped into something like this
new Employee {
Name = "John",
Id =
(int)
EmployeeIDs.John,
Cost = 8,
Level = 0,
Type =
EmployeeType.Type1
}
However, now as i set the Right Margin "# Options -> Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping" to a high value of 300 and reformatted the code i didn't get Resharper to fix the cropped lines for me as i expected the result to be something like this
new Employee {
Name = "John",
Id = (int)EmployeeIDs.John,
Cost = 8,
Level = 0,
Type = EmployeeType.Type1
}
How could i get the above desired result ?
Please uncheck following checkbox:
ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Preserve Existing Formatting | Keep existing line breaks
Then start code cleanup once again.

Textmate 2 scope: Increase font size for section in latex document

Q: When editing a .tex file in Textmate 2: How can you print latex sections in a bigger font size?
I added following grammar to the Latex bundle:
{ patterns = (
{ begin = 'section\{';
end = '\}';
name = 'markup.heading.1.latex';
},
);
}
And additionally I added following Setting that is applied to the newly defined markup.heading.1.latex scope:
{ fontName = 'Baskerville';
fontSize = '2.25em';
}
The problem: it only matches sections without a leading :
... and when I change the scope definition to the following (adding \\ in front of "section"):
{ patterns = (
{ begin = '\\section\{';
end = '\}';
name = 'markup.heading.1.latex';
},
);
}
.. the scope is not applied.
Any ideas?
The answer to your question is to edit the theme bundle.
The procedure to change the appearance of section in Texmate 2 is the following:
In the Bundle editor menu, select Edit bundles ....
Then select the bundle Themes.
From menu File, select New, and when prompted select Setting
Give a name to the setting.
In the Scope Selector field use meta.function.section.latex
Then you can edit the setting, for example:
{
fontName = 'Courier';
fontSize = 36;
}
Then save (in the usual way, e.g, command-s).
You can repeat for other sectioning command (to identify the scope, move the cursor on the appropriate place and then use the following key combination control-shift-P)
answer taken from here Please give the original author credit.

Resources