Skip to content

Commit 6a2714c

Browse files
committed
refactor: improve code style and formatting alignment
1 parent be0cafe commit 6a2714c

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

Assets/Scripts/StyleTestScript.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public sealed class StyleTestScript
1212
static readonly string s_staticField = "This is a static field";
1313

1414
string stringField;
15-
int _intField;
15+
int _intField;
1616
double doubleField;
17-
float _floatField;
17+
float _floatField;
1818

1919
public void improperlyStyledMethod()
2020
{

Assets/Scripts/StyleTestScript2.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
using UnityEngine;
23

34
namespace Tests
@@ -6,7 +7,8 @@ public class RuleChecker
67
{
78
private int _incorrect_field;
89
private string stringField;
9-
int _intField;
10+
int _intField;
11+
1012
public int CorrectProperty { get; set; }
1113

1214
public void CheckRules()

Assets/Scripts/StyleTestScript3.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
using UnityEngine;
3+
using System.Collections.Generic;
4+
5+
namespace Tests
6+
{
7+
public sealed class StyleTestScript3
8+
{
9+
private static int _s_static_Field = 10; // 静的メンバーへのアンダースコアは許可されない (SA1311)
10+
private int m_nonStaticField; // フィールド名が "m_" で始まっている (SA1307)
11+
12+
private List<int> testCollection = new List<int>(); // フィールド名が小文字始まり (SA1300)
13+
14+
// プロパティ名が PascalCase に一致しない
15+
public int property_value { get; set; } // プロパティ名が小文字始まり (SA1300)
16+
17+
public void test_Method() { // メソッド名が PascalCase に一致していない (SA1300)
18+
int testVariable = 42 ; // 余分なスペースで整列が崩れている (スペースルール反則)
19+
if(testVariable> 40) // 演算子周辺のスペースが不適切
20+
Debug.Log("Hello "); // スペースの不足や、不要なトレイリングスペース(SA1028)
21+
22+
var result = "some result"; // 型が明確でない場所で var を使用 (dotnet_style_var_elsewhere)
23+
this.runAdditionalLogic (); // メソッド名が PascalCase に沿っていない
24+
}
25+
26+
// 長く複雑なメソッド構造
27+
private void runAdditionalLogic () { // PascalCase に一致していない (SA1300)
28+
for (int i=0; i <50;i++) // 行の適切なスペースを欠く (スペース関連違反)
29+
testCollection.Add(i); // ループで波括弧が欠如 (SA1503)
30+
31+
if(m_nonStaticField < 10) Debug.Log("Direct Action") ; // 単一行の制御構文で波括弧が欠如 (SA1503)
32+
33+
foreach ( var x in testCollection) // インデント、スペースが正しく装飾されていない
34+
Debug.Log ( string.Format ( "Item : {0}",x) ); // スペースが不足、メソッド呼び出しの形式違反
35+
}
36+
37+
private void Very_Long_Method_With_No_Clear_Structure ()
38+
{
39+
int a=0; // インデント、スペースの欠如
40+
while (a<5) a++; // 見づらいコード、波括弧省略
41+
42+
if(a>=5)
43+
{ // 不要な開業
44+
Debug.Log(a); // 不適切なインデント (タブ vs スペース違反)
45+
46+
}
47+
48+
// コレクションと演算で波括弧を使用せず、冗長
49+
var myList= new List<int>{1,2,3};
50+
51+
foreach(int item in myList) {
52+
if ( item%2 == 0) Debug.Log("偶数 アイテム") ; else Debug.Log ("奇数 アイテム") ; }
53+
}
54+
55+
}
56+
}

Assets/Scripts/StyleTestScript3.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)