-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editorconfig : Can't exclude const fields #23391
Comments
This comment has been minimized.
This comment has been minimized.
@dpoeschl for fact checking... I do not believe we have the concept of rule hierarchy anymore in the naming style engine even if there was a way to express it in the parser. In the snippet below private const string CLIENT_PROPERTYKEY_REQUIRED_AD_GROUPS = "RequiredADGroups"; To fix this we will first need to implement the concept of rule hierarchies and then pass them through to the editorconfig format |
There are two rules: one that applies to private fields and one that applies to const fields. The rule engine does not have a way for one rule to completely override another. Instead it applies them in order. The behavior is by-design right @dpoeschl? or is there something I'm missing? |
This comment has been minimized.
This comment has been minimized.
The user is asking for
No, but the underlying implementation adds items to the |
The idea was that they would be applied in order, similar to how they are when configured from the UI. If that were working (or if it's working by coincidence somehow), then the original post should place the rule for constant fields above the rule for other fields (most specific first). |
Ignoring .editorconfig for a second, the super original implementation of this had a full tree of rules, with sub-rules and overrides and etc. We decided it was an easier mental model to just have a flat list that applies in order. You can put your more specific rules first and "mimic" overriding that way. We couldn't think of any scenarios that wouldn't work in this new, flat, paradigm. Now, @sharwell does point out that the dictionary used in the .editorconfig parsing doesn't guarantee order, I also think @jmarolf might be right that the order is preserved by implementation. If this is all true, then reversing the order of the rules in the original post (more specific first) should fix the problem. |
Alright, I discussed this scenario with @dpoeschl and I was wrong. This scenario will work today if you reverse the ordering of naming style declarations such that |
@jmarolf Just read the documentation, second paragraph. It's there since 2017-08-04. |
@jmarolf @dpoeschl It looks like the implementation of As for applying items in a top-down manner (first match wins), this appears to be the case users would expect most of the time. However, there are two areas where this applies:
|
I agree this is depending on implementation specific behavior and therefore is bad. It is, however, extremely unlikely that corefx will ever make a change in behavior here. @sharwell 1 and 2 describe the behavior of the feature today. Since (as @chm-tm points out) this behavior is already documented behavior I think this is by design. |
I'm running into a similar issue. Perhaps you could add in the ability to say "dotnet_naming_symbols.constant_fields.required_modifiers = !const" or !readonly in my case. I want a rule to apply to any private member that ISN'T a readonly, (which would be _camelCase) and then for public or private readonly just apply a different rule, which would be (PascalCase) I have the rules in order of most specific to least specific as suggested. However if I start by saying private int _myInt = 2, and then immediately edit that to include private readonly int _myInt = 2, the readonly inclusion won't be picked up because the first rule already sufficed. If I were to just start off typing private readonly int _myInt = 2, my readonly rule would correctly be applied and appropriately give a warning. So the rules work, unless you start with just int and add in readonly after the rule was picked up....then it stops caring. |
I see the PR has now been merged - great! |
Ah - I should have looked at the PR 😢 |
You'd have to start with: public interface ICodingConventionsSnapshot
{
IUniversalCodingConventions UniversalConventions { get; }
IReadOnlyDictionary<string, object> AllRawConventions { get; } AllRawConventions is how the data flows into roslyn. You'd need to track down how this flows everywhere, specifically into the NamingPreference code. That code will have to enumerate this dictionary looking for the first item that matches (instead of whatever it is doing now). Note: this will be us taking a strong dependency on that Dictionary enumerating things in an order we want. that's not really safe, but the only alternative is to get VS (the owners of that interface above) to give us the data in ordered form. For example, an |
@olegtk Would it be hard to get ICodingConventionsSnapshot to expose the raw conventions in an ordered fashion? Right now we're in the unpleasant state where we're going to need to take a dependency on how standard .net Dictionary iterates values, and that's... not a happy place to be in. Thanks! |
@CyrusNajmabadi hmm, so you need to preserve original order? In general it makes sense, but we need to decide how do we deal with merging, for example .editorconfig in a repo root declares How show we order resulting properties for files in that project? .editorconfigs are merged top to bottom so I guess: Or maybe we should provide an extensibility point for you to customize the merging strategy? Or plainly expose pre-merged hierarchy? |
This might be the most ideal. I think the roslyn strategy would then be to just examine the pre-merged hierarchy, walking upwards trying to find the first match in each each set. Note: i really haven't thought this through. I could see confusion with any sort of strategy taken. @sharwell , thoughts? |
tagging @agocke as well who is porting hte editor code down to the compiler layer. If that work gets done, roslyn probably won't need the editor to do anything. however, any decisions we make should at least be applied to the CodeAnalysis implementation. |
Basically copying my post from #26253 (comment) EditorConfig files are imported and parsed from root downward (to the current directory). The standard behavior according to the editorconfig "spec" is last definition wins. My opinion is we should ensure that we follow this ordering, both to remain inline with the spec, but also to match what users familiar with
|
And my followup:
|
@aditya-kadam FYI - a feature request |
If a editorconfig with naming rules which defines that all privat fields should begin with an underscore and casing should be camel case.
I also define constants have to be uppercase.
The problem is, that VS shows me a warning because my private const does not begin with an underscore.
EditorConfig:
const to test:
This issue has been moved from https://developercommunity.visualstudio.com/content/problem/152288/editorconfig-cant-exclude-const-fields.html
VSTS ticketId: 526669
These are the original issue comments:
Jinu Joseph [MSFT] on 11/27/2017, 03:55 AM (78 min ago):
We appreciate you taking the time to report this problem. We are currently prioritizing problems that are impacting a broad set of our customers, so we may not be able to investigate this one immediately. We know this problem is important to you, so we will continue to monitor it.
These are the original issue solutions:
(no solutions)
The text was updated successfully, but these errors were encountered: