Skip to content

Commit 6c64c5e

Browse files
committed
Fix code cleanup options. (flattened)
1 parent 82190a1 commit 6c64c5e

File tree

3 files changed

+149
-124
lines changed

3 files changed

+149
-124
lines changed

src/StyleCop.ReSharper/CodeCleanup/StyleCopCodeCleanupModule.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class StyleCopCodeCleanupModule : ICodeCleanupModule
4747
/// <summary>
4848
/// StyleCop descriptor.
4949
/// </summary>
50-
public static readonly StyleCopDescriptor Descriptor = new StyleCopDescriptor();
50+
public static readonly FixViolationsDescriptor FIX_VIOLATIONS = new FixViolationsDescriptor();
51+
public static readonly CreateXmlDocStubsDescriptor CREATE_XML_DOC_STUB = new CreateXmlDocStubsDescriptor ();
5152

5253
/// <summary>
5354
/// Gets the collection of option descriptors.
@@ -59,7 +60,7 @@ public ICollection<CodeCleanupOptionDescriptor> Descriptors
5960
{
6061
get
6162
{
62-
return new CodeCleanupOptionDescriptor[] { Descriptor };
63+
return new CodeCleanupOptionDescriptor[] { FIX_VIOLATIONS, CREATE_XML_DOC_STUB };
6364
}
6465
}
6566

@@ -138,15 +139,14 @@ public void Process(
138139
return;
139140
}
140141

141-
StyleCopCodeCleanupOptions options = profile.GetSetting(Descriptor);
142142

143-
if (!options.FixViolations)
143+
if (!profile.GetSetting (FIX_VIOLATIONS))
144144
{
145145
return;
146146
}
147147

148148
var services = solution.GetPsiServices();
149-
services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, options.CreateXmlDocStubs));
149+
services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, profile.GetSetting(CREATE_XML_DOC_STUB)));
150150

151151
StyleCopTrace.Out();
152152
}
@@ -162,7 +162,8 @@ public void Process(
162162
/// </param>
163163
public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType)
164164
{
165-
profile.SetSetting(Descriptor, new StyleCopCodeCleanupOptions());
165+
profile.SetSetting(FIX_VIOLATIONS, value: true);
166+
profile.SetSetting(CREATE_XML_DOC_STUB, value: false);
166167
}
167168

168169
/// <summary>

src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs

+137-115
Original file line numberDiff line numberDiff line change
@@ -19,133 +19,155 @@ namespace StyleCop.ReSharper.CodeCleanup
1919
using JetBrains.ReSharper.Feature.Services.CodeCleanup;
2020
using JetBrains.Util;
2121

22-
/// <summary>
23-
/// The style cop descriptor.
24-
/// </summary>
25-
[DisplayName("Fix StyleCop violations")]
26-
[Category(CSharpCategory)]
27-
[TypeConverter(typeof(ExpandableObjectConverter))]
28-
public class StyleCopDescriptor : CodeCleanupOptionDescriptor<StyleCopCodeCleanupOptions>
22+
[Category (CSharpCategory)]
23+
[DisplayName ("Fix StyleCop violations")]
24+
[DefaultValue (true)]
25+
public class FixViolationsDescriptor : CodeCleanupBoolOptionDescriptor
2926
{
30-
/// <summary>
31-
/// Initializes a new instance of the <see cref="StyleCopDescriptor"/> class.
32-
/// </summary>
33-
public StyleCopDescriptor()
34-
: base("StyleCop")
27+
public FixViolationsDescriptor ()
28+
: base ("FixViolations")
3529
{
3630
}
31+
}
3732

38-
/// <summary>
39-
/// Summarize the options for the Code Cleanup dialog
40-
/// </summary>
41-
/// <param name="profile">
42-
/// The selected profile
43-
/// </param>
44-
/// <returns>
45-
/// A string that summarizes the options
46-
/// </returns>
47-
public override string Present(CodeCleanupProfile profile)
33+
[Category (CSharpCategory)]
34+
[DisplayName ("Create XML doc stubs")]
35+
[DefaultValue (false)]
36+
public class CreateXmlDocStubsDescriptor : CodeCleanupBoolOptionDescriptor
37+
{
38+
public CreateXmlDocStubsDescriptor ()
39+
: base ("CreateXmlDocStubs")
4840
{
49-
return profile.GetSetting(this).ToString();
5041
}
42+
}
5143

52-
/// <summary>
53-
/// Save the options
54-
/// </summary>
55-
/// <param name="element">
56-
/// The parent XML element to add the options to
57-
/// </param>
58-
/// <param name="value">
59-
/// The options to save
60-
/// </param>
61-
public override void Save(XmlElement element, StyleCopCodeCleanupOptions value)
62-
{
63-
element.CreateLeafElementWithValue(
64-
"FixViolations",
65-
value.FixViolations.ToString(CultureInfo.InvariantCulture));
66-
element.CreateLeafElementWithValue(
67-
"CreateXmlDocStubs",
68-
value.CreateXmlDocStubs.ToString(CultureInfo.InvariantCulture));
69-
}
44+
///// <summary>
45+
///// The style cop descriptor.
46+
///// </summary>
47+
//[DisplayName("Fix StyleCop violations")]
48+
//[Category(CSharpCategory)]
49+
//[TypeConverter(typeof(ExpandableObjectConverter))]
50+
//public class StyleCopDescriptor : CodeCleanupOptionDescriptor<StyleCopCodeCleanupOptions>
51+
//{
52+
// /// <summary>
53+
// /// Initializes a new instance of the <see cref="StyleCopDescriptor"/> class.
54+
// /// </summary>
55+
// public StyleCopDescriptor()
56+
// : base("StyleCop")
57+
// {
58+
// }
7059

71-
/// <summary>
72-
/// Load the options
73-
/// </summary>
74-
/// <param name="element">
75-
/// The parent XML element
76-
/// </param>
77-
/// <returns>
78-
/// A loaded instance of the options
79-
/// </returns>
80-
public override StyleCopCodeCleanupOptions Load(XmlElement element)
81-
{
82-
return new StyleCopCodeCleanupOptions
83-
{
84-
FixViolations = bool.Parse(XmlUtil.ReadLeafElementValue(element, "FixViolations")),
85-
CreateXmlDocStubs = bool.Parse(XmlUtil.ReadLeafElementValue(element, "CreateXmlDocStubs"))
86-
};
87-
}
88-
}
60+
// /// <summary>
61+
// /// Summarize the options for the Code Cleanup dialog
62+
// /// </summary>
63+
// /// <param name="profile">
64+
// /// The selected profile
65+
// /// </param>
66+
// /// <returns>
67+
// /// A string that summarizes the options
68+
// /// </returns>
69+
// public override string Present(CodeCleanupProfile profile)
70+
// {
71+
// return profile.GetSetting(this).ToString();
72+
// }
8973

90-
/// <summary>
91-
/// Options for code cleanup
92-
/// </summary>
93-
public class StyleCopCodeCleanupOptions : ObservableObject
94-
{
95-
private bool fixViolations;
96-
private bool createXmlDocStubs;
74+
// /// <summary>
75+
// /// Save the options
76+
// /// </summary>
77+
// /// <param name="element">
78+
// /// The parent XML element to add the options to
79+
// /// </param>
80+
// /// <param name="value">
81+
// /// The options to save
82+
// /// </param>
83+
// public override void Save(XmlElement element, StyleCopCodeCleanupOptions value)
84+
// {
85+
// element.CreateLeafElementWithValue(
86+
// "FixViolations",
87+
// value.FixViolations.ToString(CultureInfo.InvariantCulture));
88+
// element.CreateLeafElementWithValue(
89+
// "CreateXmlDocStubs",
90+
// value.CreateXmlDocStubs.ToString(CultureInfo.InvariantCulture));
91+
// }
9792

98-
/// <summary>
99-
/// Option to fix StyleCop violations
100-
/// </summary>
101-
[DisplayName("Fix StyleCop violations")]
102-
public bool FixViolations
103-
{
104-
get
105-
{
106-
return this.fixViolations;
107-
}
108-
set
109-
{
110-
this.SetField(ref this.fixViolations, value);
111-
}
112-
}
93+
// /// <summary>
94+
// /// Load the options
95+
// /// </summary>
96+
// /// <param name="element">
97+
// /// The parent XML element
98+
// /// </param>
99+
// /// <returns>
100+
// /// A loaded instance of the options
101+
// /// </returns>
102+
// public override StyleCopCodeCleanupOptions Load(XmlElement element)
103+
// {
104+
// return new StyleCopCodeCleanupOptions
105+
// {
106+
// FixViolations = bool.Parse(XmlUtil.ReadLeafElementValue(element, "FixViolations")),
107+
// CreateXmlDocStubs = bool.Parse(XmlUtil.ReadLeafElementValue(element, "CreateXmlDocStubs"))
108+
// };
109+
// }
110+
//}
113111

114-
/// <summary>
115-
/// Options to generate XML doc stubs
116-
/// </summary>
117-
[DisplayName("Create XML doc stubs")]
118-
public bool CreateXmlDocStubs
119-
{
120-
get
121-
{
122-
return this.createXmlDocStubs;
123-
}
124-
set
125-
{
126-
this.SetField(ref this.createXmlDocStubs, value);
127-
}
128-
}
112+
///// <summary>
113+
///// Options for code cleanup
114+
///// </summary>
115+
//public class StyleCopCodeCleanupOptions : ObservableObject
116+
//{
117+
// private bool fixViolations;
118+
// private bool createXmlDocStubs;
129119

130-
/// <summary>
131-
/// Initializes a new instance of the <see cref="StyleCopCodeCleanupOptions"/> class.
132-
/// </summary>
133-
public StyleCopCodeCleanupOptions()
134-
{
135-
this.FixViolations = true;
120+
// /// <summary>
121+
// /// Option to fix StyleCop violations
122+
// /// </summary>
123+
// [DisplayName("Fix StyleCop violations")]
124+
// public bool FixViolations
125+
// {
126+
// get
127+
// {
128+
// return this.fixViolations;
129+
// }
130+
// set
131+
// {
132+
// this.SetField(ref this.fixViolations, value);
133+
// }
134+
// }
136135

137-
// TODO: What's the best default?
138-
// I like the argument that we shouldn't blindly create XML docs, but set
139-
// them properly, but it's nice to be able to fix up everything we can...
140-
this.CreateXmlDocStubs = false;
141-
}
136+
// /// <summary>
137+
// /// Options to generate XML doc stubs
138+
// /// </summary>
139+
// [DisplayName("Create XML doc stubs")]
140+
// public bool CreateXmlDocStubs
141+
// {
142+
// get
143+
// {
144+
// return this.createXmlDocStubs;
145+
// }
146+
// set
147+
// {
148+
// this.SetField(ref this.createXmlDocStubs, value);
149+
// }
150+
// }
142151

143-
public override string ToString()
144-
{
145-
StringBuilder stringBuilder = new StringBuilder();
146-
stringBuilder.Append(this.FixViolations ? "Yes" : "No");
147-
stringBuilder.Append(this.CreateXmlDocStubs ? " (create XML doc stubs)" : " (do not create XML doc stubs)");
148-
return stringBuilder.ToString();
149-
}
150-
}
152+
// /// <summary>
153+
// /// Initializes a new instance of the <see cref="StyleCopCodeCleanupOptions"/> class.
154+
// /// </summary>
155+
// public StyleCopCodeCleanupOptions()
156+
// {
157+
// this.FixViolations = true;
158+
159+
// // TODO: What's the best default?
160+
// // I like the argument that we shouldn't blindly create XML docs, but set
161+
// // them properly, but it's nice to be able to fix up everything we can...
162+
// this.CreateXmlDocStubs = false;
163+
// }
164+
165+
// public override string ToString()
166+
// {
167+
// StringBuilder stringBuilder = new StringBuilder();
168+
// stringBuilder.Append(this.FixViolations ? "Yes" : "No");
169+
// stringBuilder.Append(this.CreateXmlDocStubs ? " (create XML doc stubs)" : " (do not create XML doc stubs)");
170+
// return stringBuilder.ToString();
171+
// }
172+
//}
151173
}

src/StyleCop.ReSharper/Options/CodeStyleOptions.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ public static void CodeStyleOptionsReset(IContextBoundSettingsStore settingsStor
341341

342342
SetCodeCleanupProfileSetting(styleCopProfile, "CSReorderTypeMembers", null, true);
343343

344-
styleCopProfile.SetSetting(StyleCopCodeCleanupModule.Descriptor, new StyleCopCodeCleanupOptions());
344+
styleCopProfile.SetSetting(StyleCopCodeCleanupModule.FIX_VIOLATIONS, value: true);
345+
styleCopProfile.SetSetting(StyleCopCodeCleanupModule.CREATE_XML_DOC_STUB, value: false);
345346

346347
codeCleanupSettings.SetProfiles(profiles, settingsStore);
347348
codeCleanupSettings.SetSilentCleanupProfileName(settingsStore, styleCopProfile.Name);
@@ -1406,8 +1407,9 @@ public static bool CodeStyleOptionsValid(IContextBoundSettingsStore settingsStor
14061407
return false;
14071408
}
14081409

1409-
StyleCopCodeCleanupOptions options = styleCopProfile.GetSetting(StyleCopCodeCleanupModule.Descriptor);
1410-
if (!options.FixViolations || options.CreateXmlDocStubs)
1410+
var fixViolations = styleCopProfile.GetSetting(StyleCopCodeCleanupModule.FIX_VIOLATIONS);
1411+
var createXmlDocStubs = styleCopProfile.GetSetting (StyleCopCodeCleanupModule.CREATE_XML_DOC_STUB);
1412+
if (!fixViolations || createXmlDocStubs)
14111413
{
14121414
return false;
14131415
}

0 commit comments

Comments
 (0)