@@ -19,7 +19,7 @@ class CodeStyleConfigInitError(Exception):
19
19
class CodeStyleConfig :
20
20
21
21
def __init__ (self ,
22
- indent_type : str = INDENT_TYPE_SPACE ,
22
+ indent_type : str = None ,
23
23
indent_width : Optional [int ] = None ,
24
24
code_generator_file : Optional [str ] = None ,
25
25
template_file : Optional [str ] = None ,
@@ -37,7 +37,7 @@ def __init__(self,
37
37
raise CodeStyleConfigInitError (
38
38
"language must be one of {}" .format (ALL_LANGUAGE_NAMES ))
39
39
40
- if indent_type not in [INDENT_TYPE_SPACE , INDENT_TYPE_TAB ]:
40
+ if indent_type is not None and indent_type not in [INDENT_TYPE_SPACE , INDENT_TYPE_TAB ]:
41
41
raise CodeStyleConfigInitError (
42
42
"indent_type must be 'space' or 'tab'" )
43
43
@@ -54,15 +54,25 @@ def __init__(self,
54
54
"The specified template file '{}' is not found" .format (
55
55
template_file )
56
56
)
57
-
58
- self .indent_type = indent_type
57
+ if indent_type is not None :
58
+ self .indent_type = indent_type
59
+ elif lang .default_code_style is not None and lang .default_code_style .indent_type is not None :
60
+ self .indent_type = lang .default_code_style .indent_type
61
+ else :
62
+ self .indent_type = INDENT_TYPE_SPACE
59
63
60
64
if indent_width is not None :
61
65
self .indent_width = indent_width
62
66
elif lang .default_code_style is not None and lang .default_code_style .indent_width is not None :
63
67
self .indent_width = lang .default_code_style .indent_width
64
68
else :
65
- self .indent_width = 4
69
+ if self .indent_type == INDENT_TYPE_SPACE :
70
+ self .indent_width = 4
71
+ elif self .indent_type == INDENT_TYPE_TAB :
72
+ self .indent_width = 1
73
+ else :
74
+ raise CodeStyleConfigInitError (
75
+ "indent_type must be 'space' or 'tab'" )
66
76
67
77
if code_generator_file is not None :
68
78
try :
@@ -84,4 +94,8 @@ def __init__(self,
84
94
def indent (self , depth ):
85
95
if self .indent_type == INDENT_TYPE_SPACE :
86
96
return " " * self .indent_width * depth
87
- return "\t " * self .indent_width * depth
97
+ elif self .indent_type == INDENT_TYPE_TAB :
98
+ return "\t " * self .indent_width * depth
99
+ else :
100
+ raise CodeStyleConfigInitError (
101
+ "indent_type must be 'space' or 'tab'" )
0 commit comments