StyleCop 4.7 rules SA1210 and SA1211 require the using directives to be sorted alphabetically. I've run into a conflict between StyleCop's rule and Resharper's applied sort: case-sensitivity.
Resharper 8.2 performs a case insensitive sort of the directives, while StyleCop's rule requires a case sensitive sort. So, I ran into an odd case with the following directives because of poor namespace choices (not my own):
using AB.Common;
using ab.Utility;
Pressing ctrl-E-F sorts common first; but the rule requires utility to be first because of the difference between AB and ab. I've gotten past it by removing the StyleCop rule and just letting Resharper's reformat reign. Of course the namespace itself should be refactored, but I don't have that option.
Any other opinions about how to deal with this other than turning off the StyleCop rule?
Turning the StyleCop rule off seems like the best answer, there is no need for both ReSharper and StyleCop to check the ordering.
But if you want to have them both on, you could alias the namespaces to something like:
using Common=AB.Common;
using Utility=ab.Utility;
Related
I am new to Linux. I am trying to compile and execute a c++ file. When I read the gcc manual, I found something in the manual that I don't understand:
Many options have long names starting with -f or with -W---for
example, -fmove-loop-invariants, -Wformat and so on. Most of these
have both positive and negative forms; the negative form of -ffoo is
-fno-foo. This manual documents only one of these two forms, whichever one is not the default.
Can someone please explain what are the positive and negative forms of a command line option?
The positive form of the option enables some feature of the compiler, the negative form disables that feature.
For instance, -fmove-loop-invariants enables this optimization setting. To disable it, use -fno-move-loop-invariants.
Having both forms is useful so that you can override an option that might have been set using a default set of options in a build script or makefile. Also, some options enable or disable groups of settings at once, you can then use a later, more specific option to undo parts of this.
And sometimes you might use an option that's the same as the default, just to make your intentions explicit.
I have a cmake project. I want to do the following easily
search the declaration, definition and references of any variable, function, etc. under the cursor, which may be declared in an external header file whose path is added using INCLUDE_DIRECTORIES in CMakeLists.txt
rename a variable, function, etc. that is declared in the project
How can I set this up?
You can try to use vim plugin cmake4vim in order to integrate CMake to Vim.
This plugin helps to work with cmake targets and allows to generate compilation database file (compile_commands.json). A lot of plugins use this file for code completion, jump to definition and etc. (for example YCM)
Also you can use vim lsp plugins (for example vim-lsp) these plugins use language servers for code completion, refactoring and another good features.
But CMake project integration (cmake cache generation, project compilation, etc.) and search the declaration, definition and etc are different tasks. And different plugins and tools solve these tasks.
You can tell Vim where to look for includes by adding entries to the path option. I don't have enough experience with Cmake to know how to pull paths from CMakeLists.txt, though.
See :help 'path'.
Assuming a properly set path, it is possible to use the built-in :dsearch and related commands to search for definitions across includes.
The define option has a prescriptive name but it could be used to find any specific pattern so you could alter it to match declarations, too, or really anything.
See :help include-search and :help 'define'.
Vim has no built-in concept of "reference". :isearch and friends should work for that but they will probably be too noisy.
Renaming is usually done with something like:
:grep foo paths
:cwindow
:cdo s/foo/bar/gc
YouCompleteMe will help you. It uses compilation_database.json, witch can be generated by cmake.
This plugin also provides autocompetion for many languages.
I use functions in vim and assign them to a hotkey.
https://developer.ibm.com/tutorials/l-vim-script-2/
it gives you more an IDE feel. but at the end of the day you get a bit more control.
I'm forced to comply with StyleCop rule 1201. StyleCopAnalyzers is stating that conversion operators must appear before other operators. I use ReSharper code cleanup to organize the files which has worked great until I needed to define operator + and a conversion operator for the same class.
How can I get ReSharper file layout to differentiate between conversion operators and other operators so that I may have them sorted according to StyleCop?
[edit]
I will also accept a way to change the ordering rule for StyleCop.Analyzers, but according to issue 2541 there doesn't appear to be a way currently.
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.
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.