You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow every setting in .editorconfig and document unified configuration - #4221
Makes .editorconfig/.globalconfig a complete location for all StyleCop settings (stylecop.json and rulesets keep working), and rewrites the configuration docs around it. This supersedes the intent of #3911 and #3197 (no template file; docs instead).
Fixes#3534 Fixes#2551 Fixes#3650 Fixes#3226
Part of #3092 (documents the SA0001 limitation and dotnet_diagnostic usage) Closes#3911 Closes#3197
Product changes
New .editorconfig keys (stylecop.json still takes precedence):
⚑ Reviewer decisions: key names; variables needs key enumeration, so AnalyzerConfigOptionsWrapper.GetKeys() light-up reads AnalyzerConfigOptions.Keys and returns empty on older compilers (variables then stay JSON-only there). EditorConfig lowercases keys, so variable lookup falls back to the lowercase name.
Docs
documentation/Configuration.md now leads with the recommendation, a full settings reference (JSON key ⇄ editorconfig key, values, defaults), and migration tables for stylecop.json and rulesets.
Tests
New tests in SettingsCSharp8UnitTests (keys, precedence, invalid values) and SettingsCSharp11UnitTests (variables, needs Roslyn 4.4 Keys). Settings tests pass on net6.0 and net472.
Performance
Settings are cached per syntax tree; added lookups are a few TryGetValue calls plus one key enumeration per tree on first load.
❌ Patch coverage is 95.47739% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.58%. Comparing base (d51e0fd) to head (73cec6a). ⚠️ Report is 5 commits behind head on master.
Link to the rule-status page included in the DocFX content instead of the excluded repository README.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Enum.TryParse also accepts signed numeric strings and comma-separated combinations. Because only a leading digit is rejected and IsDefined checks the resulting value, inputs such as +1 or insideNamespace,outsideNamespace can select a defined member even though they are outside the documented values. Require the input to match the parsed member name.
Translate remaining English comments in Russian example
documentation/ru-ru/Configuration.md:26
This Russian-localized example still contains English user-facing comments (or ... without ..., Rule severities, and Settings), leaving the example mixed-language. Translate the prose comments while preserving the literal configuration names and values.
This issue also appears on line 107 of the same file.
Claude had some concerns, which I have not dug into further:
Must fix
GetKeys() can crash every analyzer on some hosts. In Roslyn 4.4+, the base AnalyzerConfigOptions.Keys getter just
throws. I checked the IL in 4.4.0 and 5.0.0: it creates an exception object and throws it, which appears to be
NotImplementedException.
Any host whose AnalyzerConfigOptions subclass doesn't override Keys will throw. The compiler's own options class
does override it, but third-party hosts and test harnesses may not.
SettingsReader.GetStringMap (SettingsReader.cs:~178) calls GetKeys() whenever stylecop.json has no variables, which
is nearly every run. It runs from the DocumentationSettings constructor.
Nothing in SettingsHelper.GetSettings/CreateSettingsObjectFromFile catches this exception, so the user would see
AD0001 from every StyleCop analyzer.
The branch's own tests show the problem. SettingsCSharp11UnitTests has to swap in a
KeysAwareAnalyzerConfigOptionsProvider for all inherited tests. Without it, the existing TestAnalyzerConfigOptions
(which doesn't override Keys) would hit exactly this throw.
Suggested fix: catch NotImplementedException in AnalyzerConfigOptionsWrapper.GetKeys() and return empty. Add a C#11+
test that uses options without a Keys override.
Performance (per the analyzer-performance skill). Settings are built once per syntax tree per analyzer. Every build
now walks every editorconfig key for the file (all dotnet_diagnostic.* and IDE keys too) and runs a case-insensitive
prefix check on each. Before, this path only did a few direct lookups. It's probably small, but maintainers don't
accept perf risk, so it needs a justification or a cheaper approach.
Behaviour changes worth calling out
Variable lookup is now case-insensitive for stylecop.json too. The fallback
Variables.TryGetValue(key.ToLowerInvariant(), …) (DocumentationSettings.cs:~320) also applies to JSON variables. A
JSON variable licensename now matches {LicenseName}, which it didn't before. It's harmless but undocumented. It
could be limited to editorconfig-sourced names.
excludeFromPunctuationCheck in JSON is now stricter. The old code used value.AsString; the new code uses
ToStringValue(jsonKey), which throws InvalidSettingsException on a non-string entry. Because of how invalid
settings are handled, the whole settings object then quietly falls back to defaults, so company name, header and so
on are lost.
Inconsistent case handling for editorconfig values.
The new GetEnum/GetEnumList ignore case: Preserve and preserve both work.
fileNamingConvention, tupleElementNameCasing and indent_style still match exact strings.
Separately, Enum.TryParse accepts comma-joined names, so a value like allow, require can combine flags. That
combined value can be a different valid member, so it isn't always rejected.
variables is all-or-nothing. If stylecop.json has any variables, all editorconfig variables are ignored rather than
merged. This fits the "same setting, JSON wins" rule, but the docs should say so.
Documentation
The template's warning about trailing comments is wrong. Roslyn's property regex is
^\s*([\w.-_]+)\s*[=:]\s*(.?)\s([#;].*)?$ (taken from the 4.4.0 binary), so # … and ; … at the end of a line are
stripped. The real limitation goes the other way: a value can't contain # or ;. That matters for copyrightText,
headerDecoration (such as #####) and variable values. Since the docs now say "every setting can be set there" and
recommend editorconfig first, this limitation should be documented.
The rest of the reference table looks right against the code: defaults, the generic-key mappings
(dotnet_separate_import_directive_groups false→allow, true→require; insert_final_newline) and the precedence notes.
Documentation
The template's warning about trailing comments is wrong. Roslyn's property regex is
^\s*([\w.-_]+)\s*[=:]\s*(.?)\s([#;].*)?$ (taken from the 4.4.0 binary), so # … and ; … at the end of a line are
stripped. The real limitation goes the other way: a value can't contain # or ;. That matters for copyrightText,
headerDecoration (such as #####) and variable values. Since the docs now say "every setting can be set there" and
recommend editorconfig first, this limitation should be documented.
The rest of the reference table looks right against the code: defaults, the generic-key mappings
(dotnet_separate_import_directive_groups false→allow, true→require; insert_final_newline) and the precedence notes.
Tests
VerifyStyleCopJsonTakesPrecedenceOverEditorConfigAsync sets file_header_template but never checks CopyrightText, so
the fallback-key path isn't verified there.
The AGENTS.md changes are out of scope. A repo-wide file-scoped-namespace rule is a policy change unrelated to
this PR, and maintainers may want it separately.
The new rule contradicts the code. The new SettingsReader rule says "Don't read AnalyzerConfigOptions … directly",
yet LayoutSettings (insert_final_newline) and OrderingSettings (csharp_using_directive_placement,
dotnet_separate_import_directive_groups) still call AnalyzerConfigHelper directly for the generic fallbacks.
Either soften the rule or add a secondary-key overload to SettingsReader.
Minor:
KeysAccessor uses CreateSyntaxPropertyAccessor on a type that isn't syntax. It works, but the name is
misleading.
The wrapper writes System.Collections.Generic.IEnumerable in full instead of adding a using.
Verdict: the refactor is clean and the docs are a clear improvement. I'd block on #1, and ask for #2, #7 and #11/#12
to be addressed before merge.
Thanks for passing this along. I checked each claim against the code and, where useful, against a running compiler. Fixes are in 73cec6a.
Confirmed and fixed
1 / 10 (Keys throws): Correct. The base AnalyzerConfigOptions.Keys throws NotImplementedException. GetKeys() now catches it and returns an empty list. A new CSharp11 test (VerifyHostWithoutKeysSupportDoesNotThrowAsync) uses a host with no Keys override.
2 (performance): Reasonable concern. Variables are only needed by the file-header rules, so the .editorconfig key walk is now lazy and happens on first Variables access, not for every settings object. stylecop.json variables are still read eagerly, so invalid JSON is still reported at the same time.
3 (case-insensitive JSON variables): Correct. That was an unintended behavior change. I removed the lowercase fallback lookup. Only .editorconfig-sourced variables (EditorConfig lowercases keys) use a case-insensitive dictionary. JSON lookups are as before.
5 (case handling): Partly true. indent_style, tupleElementNameCasing and fileNamingConvention were exact-match, so they are now case-insensitive like the other enums. The Enum.TryParse comma-join point is also real, so values containing , are now rejected. A test covers both.
6 (variables not merged): True and by design. It is now documented in the migration steps.
7 (trailing comments): Correct. I confirmed with a test that value # comment is stripped, and that the real limitation is that values can't contain # or ;. I replaced the wrong warning in the English and Russian docs with that limitation, and with the advice to use stylecop.json for such values.
9 (test gap): The precedence test now also asserts the file_header_template fallback.
12 (rule vs. code): Fair. Rather than soften the rule, I added a fallback-key overload to SettingsReader.GetEnum. insert_final_newline, csharp_using_directive_placement and dotnet_separate_import_directive_groups now go through the reader, so no settings class reads AnalyzerConfigHelper directly.
13: Added the using System.Collections.Generic;. The CreateSyntaxPropertyAccessor name is the existing light-up helper for any property getter, so I kept it.
Not changed
4 (excludeFromPunctuationCheck): True, it is stricter now. The old AsString silently yielded null entries for non-strings. Every other string-list setting already throws InvalidSettingsException for non-strings, so this brings it in line. If you'd rather keep the old leniency, tell me.
11 (AGENTS.md): The file-scoped namespace rule was added in response to an earlier review request on this PR. It's a separate commit, so it's easy to drop if the maintainers want it elsewhere.
8: Agreed, no action needed.
Settings tests pass in CSharp8 (net6.0 and net472) and CSharp11, with zero warnings. The documentation localization test also passes.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The configuration reference contains a schema-incompatible value spelling and untranslated Russian guidance.
0 open findings
Previously missed (3)
In code that hasn't changed since last review
Use schema-compliant PascalCase spelling
documentation/Configuration.md:66
This row advertises pascalCase for stylecop.json, but Settings/stylecop.schema.json:145-152 only permits camelCase and PascalCase, and the detailed reference below also names the default PascalCase. Schema-aware editors will reject the documented lowercase spelling even though the runtime parser is lenient, so use the schema spelling here.
Translate remaining English guidance into Russian
documentation/ru-ru/Configuration.md:26
This explanatory sentence remains in English in the Russian-localized document. Translate it so readers do not encounter mixed-language guidance.
Использовать написание PascalCase из схемы
documentation/ru-ru/Configuration.md:74
В этой строке для stylecop.json указано pascalCase, однако схема Settings/stylecop.schema.json:145-152 разрешает только camelCase и PascalCase. Редакторы с проверкой схемы отклонят документированный вариант в нижнем регистре, поэтому здесь следует использовать написание из схемы.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
.editorconfig/.globalconfiga complete location for all StyleCop settings (stylecop.json and rulesets keep working), and rewrites the configuration docs around it. This supersedes the intent of #3911 and #3197 (no template file; docs instead).Fixes #3534
Fixes #2551
Fixes #3650
Fixes #3226
Part of #3092 (documents the SA0001 limitation and
dotnet_diagnosticusage)Closes #3911
Closes #3197
Product changes
New
.editorconfigkeys (stylecop.json still takes precedence):stylecop.ordering.elementOrder(was JSON-only)stylecop.maintainability.topLevelTypes(was JSON-only)stylecop.documentation.variables.<name>(was JSON-only)stylecop.ordering.usingDirectivesPlacement(addspreserve, which the generic key can't express)stylecop.ordering.blankLinesBetweenUsingGroups(addsomit)stylecop.layout.newlineAtEndOfFile(adds explicitallow)⚑ Reviewer decisions: key names;
variablesneeds key enumeration, soAnalyzerConfigOptionsWrapper.GetKeys()light-up readsAnalyzerConfigOptions.Keysand returns empty on older compilers (variables then stay JSON-only there). EditorConfig lowercases keys, so variable lookup falls back to the lowercase name.Docs
documentation/Configuration.mdnow leads with the recommendation, a full settings reference (JSON key ⇄ editorconfig key, values, defaults), and migration tables for stylecop.json and rulesets.Tests
New tests in
SettingsCSharp8UnitTests(keys, precedence, invalid values) andSettingsCSharp11UnitTests(variables, needs Roslyn 4.4Keys). Settings tests pass on net6.0 and net472.Performance
Settings are cached per syntax tree; added lookups are a few
TryGetValuecalls plus one key enumeration per tree on first load.