Skip to content

Commit 9e185f9

Browse files
committedMar 20, 2019
Added .editorconfig and editor
1 parent 00861db commit 9e185f9

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
 

‎.editorconfig

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
2+
3+
###############################
4+
# Core EditorConfig Options #
5+
###############################
6+
root = true
7+
8+
###############################
9+
# File Formatting Options #
10+
###############################
11+
[*.cs]
12+
indent_style = tab
13+
indent_size = 4
14+
charset = utf-8
15+
end_of_line = crlf
16+
insert_final_newline = true
17+
trim_trailing_whitespace = true
18+
19+
###############################
20+
# C# Formatting Rules #
21+
###############################
22+
csharp_new_line_before_open_brace = all
23+
csharp_space_between_method_declaration_parameter_list_parentheses = false
24+
csharp_space_between_method_call_parameter_list_parentheses = true
25+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
26+
csharp_space_after_keywords_in_control_flow_statements = true
27+
csharp_space_between_parentheses = control_flow_statements
28+
csharp_indent_case_contents = true
29+
csharp_indent_switch_labels = true
30+
31+
###############################
32+
# .NET Naming Conventions #
33+
###############################

‎EditorConfigSolutionFileGenerator.cs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#if ENABLE_VSTU
2+
using UnityEditor;
3+
using SyntaxTree.VisualStudio.Unity.Bridge;
4+
5+
/// <summary>
6+
/// This class hooks into the Visual Studio .sln generation step and modifies the file
7+
/// to include .editorconfig, which enforces consistent formatting standards and naming
8+
/// conventions.
9+
/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
10+
/// </summary>
11+
[InitializeOnLoad]
12+
public class EditorConfigSolutionFileGenerator
13+
{
14+
public static string kEditorConfigProjectFindStr = "EndProject\r\nGlobal";
15+
public static string kEditorConfigProjectReplaceStr =
16+
"EndProject\r\n" +
17+
"Project(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"Solution Items\", \"Solution Items\", \"{B24FE069-BB5F-4F16-BCDA-61C28EABC46B}\"\r\n" +
18+
" ProjectSection(SolutionItems) = preProject\r\n" +
19+
" .editorconfig = .editorconfig\r\n" +
20+
" EndProjectSection\r\n" +
21+
"EndProject\r\n" +
22+
"Global";
23+
24+
public static string kGlobalSectionFindStr = "EndGlobalSection\r\nEndGlobal";
25+
public static string kGlobalSectionReplaceStr =
26+
"EndGlobalSection\r\n" +
27+
" GlobalSection(ExtensibilityGlobals) = postSolution\r\n" +
28+
" SolutionGuid = {FD87994B-C032-4821-BD72-E057C33083EF}\r\n" +
29+
" EndGlobalSection\r\n" +
30+
"EndGlobal";
31+
32+
static EditorConfigSolutionFileGenerator()
33+
{
34+
ProjectFilesGenerator.SolutionFileGeneration += AppendEditorConfig;
35+
}
36+
37+
protected static string AppendEditorConfig(string fileName, string fileContent)
38+
{
39+
fileContent = fileContent.Replace( kEditorConfigProjectFindStr, kEditorConfigProjectReplaceStr );
40+
fileContent = fileContent.Replace( kGlobalSectionFindStr, kGlobalSectionReplaceStr );
41+
42+
return fileContent;
43+
}
44+
}
45+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.