Is it possible to define custom naming conventions for resharper? - resharper

I'm using Resharper (with the StyleCop plugin, although I don't think that's relevant to the question/answer) to enforce naming conventions amongst other things in our code base. Pretty much everywhere this works brilliantly, with one exception.
For test method names I prefer the following convention:
ThingOrBehaviourUnderTest_Action_ExpectedOutcome
Currently this results in an inconsistent naming warning and to-date I've just ignored it (I know I can disable the warning in that file, but then it disables the warning for all any other naming inconsistencies). In the list of styles I can assign Resharper offers camel case, which would result in:
ThingOrBehaviourUnderTestActionExpectedOutcome
or underscore separated words:
Thing_or_behaviour_under_test_action_expected_outcome
Both are close to what I want, but not quite there. I guess I'm after a way of allowing underscores as valid characters in camel cased test method names, or a way of supporting a custom naming convention. Is this possible?

I know this question is pretty old, but ReSharper 7 now finally supports the definition of extended naming rules. Those make it possible to have separate name styles for test methods.

The AgentSmith plugin for ReSharper should meet your needs through its regex rule support.

Related

Can I Append Custom Highlights to an Existing Syntax Without Forking It?

I'm looking to add a few custom syntax highlights to an existing one, but I don't want to maintain a copy of the base one I'm using in its entirety. Is there a way to extend an existing syntax (and continue to do so through updating, if possible) and just append a few new rules to it?
I've tried using extends: Packages/HTML/HTML.sublime-syntax in my own .sublime-syntax file, but I get a console error for "syntax inheritance does not allow for mixed versions" and I have no idea what that means. I don't see it mentioned in the documentation either. Help?
The Documentation on Syntax Definitions has a section on inheritance and how you do it; there a section on Limitations:
A syntax may extend a syntax that itself extends another syntax. There are no enforced limits on extending, other than that all syntaxes must share the same version.
version is a new concept in recent versions of Syntaxes; it's listed under compatibility. The general gist is that there are various things about syntaxes which are either bugs or unexpected/undesirable behaviour, but since there are so many syntaxes already available that would be broken if that behaviour was changed, the concept of version was added so that newer syntaxes can avail themselves of fixes.
As a result, as mentioned above all syntaxes must be the same version, ostensibly so that their behaviour is consistent. Syntaxes that are newly rewritten/revamped in Sublime Text 4 use the new version, and the HTML syntax is one of them.
Hence, you need to include version: 2 in your syntax to be able to extend the HTML syntax.

Sublime 3 - Highlight variable in Perl/PHP string

I am turning to use Sublime3 instead of Notepad++. I have some concern when working with Perl/PHP or any kind of languages that use dollar sign for declare variable.
Here is an example, in Notepad ++:
As can be seen, "HELO $name" was displayed with different colors.
By that way, we can easily recognize there is a variable in the string.
In Sublime 3 , it looked like this:
So you can see there are no different between text and variable. It would caused confusion in some case.
May I know is there are any solution for this ?
Thank you and best regards.
Alex
This is self-promoting, but it will actually solve the problem
You may want to check out my Neon Color Scheme, available via Package Control. Its goal is to make as many languages as possible look as good as possible, and has hundreds of selectors that are specific for many different syntaxes, including Perl and PHP. Specifically, both languages support highlighting for string interpolation. Here is your code using Sublime's Perl syntax from dev build 3118, which should be very similar to the latest public build, which you should be using if you're not registered yet:
And here is the equivalent code in PHP:
Please note that these images were taken using a work-in-progress version of Neon, which I'm planning on releasing in the next day or so. The current version should look the same, as I don't think I've edited any of these scopes, but if not just let me know and I'll point you to the dev version.

How to change a variable name automatically across the project in VIM?

In eclipse, if you change a variable name, eclipse will automatically change this variable's name in whole project.
Can vim do that too?
Vim is a text editor, not an IDE. Though it has some notion of a filetype's syntax, it does not fully parse nor understand the language's full syntax. Refactorings, even simple ones like Rename identifier, do require such full understanding (to be 100% correct).
There are attempts at refactoring support in Vim, most language-specific, some also generic. But I'd advise to keep using a real IDE for this (for its comfort, safety, and correctness), and instead use Vim only for simple, text-based replacements, using :bufdo substitute/... or macros, as described here.
Sort of.
Because it is not an IDE and thus doesn't understand anything about your code, Vim only sees text where you see a variable name. It can't infer anything from the scope or whatever. Without the use of some external program, renaming a variable in Vim is usually done with a buffer-wide or project-wide search/replace.
Since you didn't tell us what language you are working with we can't tell you if there is a language-specific solution for your needs.
try this plugin -> Clighter, for c-family rename-refactoring. It's based on clang, but there are limitations. Still in development

VIM: hack ctags or tweak tagbar for better PHP support

Recently, i gave up Taglist for Tagbar. Tagbar works as expected for all languages except PHP.
It lists class, methods and variables into their respective categories instead of displaying methods and variables into their respective scope.
I came to know that ctags has poor support for PHP.
Is there any way to improve ctags and Tagbar's support for PHP? I am hopping for some kind of hack or tweak, or any other way around.
I have just using PHP_Parser as syntax parsing backend written a tool called phpctags to generate ctags compatiable index file and an addon plugin for tagbar called tagbar-phpctags to enhance the PHP suport for tagbar.
Methods and properties even local variables assigned in functions could be listed in their own scope now as well as their access information.
Maybe these could help.
Unfortunately there is no easy answer to this. The ctags PHP parser just uses regular expressions, and the result -- as you noticed -- is that support for scopes is missing.
There would be two ways to get proper scope support working: someone has to write either an actual recursive parser module for ctags, or some other program that can output tags in a ctags compatible format. That could theoretically even be written in PHP, which might make it easier -- maybe there already is some functionality available that allows access to the AST, which would then just need to be printed out in the correct format. But until someone does that I'm afraid there's no real way to properly display PHP scopes in Tagbar, since it has to rely on the information that ctags hands to it.

Is There Any Way To Make More Custom Naming Style For ReSharper 6?

My project have a coding convention that:
For local variables (inside methods): Use the format [prefix][variable name]
[Prefix] will be the first character of the data type if variables are of primitive type such as Integer, Byte, String...
Example:
Dim sCompanyName As String
Dim iArrayIndex As Integer
Dim bContactStatus As Boolean
Is there any way for Resharper to create custom naming rule for this case?
Thanks.
Strictly speaking, ReSharper isn't set up to handle Hungarian notation because the a la mode way of naming variables in .Net doesn't require it. Thus, if you really need to have this, you would need to implement the naming system yourself by creating a ReSharper plug-in to suppress R#'s own naming suggestion system and implement one of your own.
That said, it a very difficult, and possibly unfeasible, task.
While I totally agree with Piers on the "dated" nature of Hungarian notation, I do realize that sometimes one may get stuck maintaining legacy code or dated company standards.
It may be helpful for your to know that CodeIt.Right includes set of rules that help enforce Hungarian notation style, as well as set of rules that help to move from Hungarian notation to MS .NET conventions. And finally if you are not totally happy, you can customize existing rules or quickly develop own custom ones.

Resources