Skip to content

Commit 9d2242f

Browse files
authored
Merge pull request #493 from V-Sekai/lint
Add code lint sample
2 parents 4e2addd + bf38aa2 commit 9d2242f

File tree

2 files changed

+58
-63
lines changed

2 files changed

+58
-63
lines changed

.pre-commit-config.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
repos:
22
- repo: local
33
hooks:
4+
- id: gdlint
5+
name: gdlint
6+
entry: gdlint
7+
language: python
8+
additional_dependencies: [gdtoolkit==4.3.3]
9+
files: ^addons/godot_uro/godot_uro_helper\.gd$
10+
types: [gdscript]
11+
412
# vsk_importer_exporter is ignored due to broken code.
513
# VRM and godot_state_charts are ignored because upstream changes are complicated
614
- id: gdformat

addons/godot_uro/godot_uro_helper.gd

+50-63
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,36 @@
77
extends RefCounted
88

99
enum UroUserContentType { UNKNOWN, AVATAR, MAP, PROP }
10+
enum RequesterCode {
11+
OK = 0,
12+
CANCELLED,
13+
TERMINATED,
14+
CANT_CONNECT,
15+
CANT_RESOLVE,
16+
SSL_HANDSHAKE_ERROR,
17+
DISCONNECTED,
18+
CONNECTION_ERROR,
19+
UNKNOWN_STATUS_ERROR,
20+
FILE_ERROR,
21+
HTTP_RESPONSE_NOT_OK,
22+
NO_TOKEN,
23+
MALFORMED_RESPONSE_DATA,
24+
JSON_PARSE_ERROR,
25+
JSON_VALIDATE_ERROR,
26+
NO_RESPONSE_BODY,
27+
FAILED_TO_CONNECT,
28+
POLL_ERROR,
29+
}
1030

1131
const LOCALHOST_HOST = "127.0.0.1"
1232
const LOCALHOST_PORT = 4000
13-
1433
const DEFAULT_URO_HOST = LOCALHOST_HOST
1534
const DEFAULT_URO_PORT = LOCALHOST_PORT
16-
1735
const API_PATH = "/api"
1836
const API_VERSION = "/v1"
19-
2037
const SHOW_PATH = "/show"
2138
const NEW_PATH = "/new"
2239
const RENEW_PATH = "/renew"
23-
2440
const PROFILE_PATH = "/profile"
2541
const SESSION_PATH = "/session"
2642
const REGISTRATION_PATH = "/registration"
@@ -29,35 +45,12 @@ const AVATARS_PATH = "/avatars"
2945
const MAPS_PATH = "/maps"
3046
const SHARDS_PATH = "/shards"
3147
const DASHBOARD_PATH = "/dashboard"
32-
3348
const DEFAULT_ACCOUNT_ID = "UNKNOWN_ID"
3449
const DEFAULT_ACCOUNT_USERNAME = "UNKNOWN_USERNAME"
3550
const DEFAULT_ACCOUNT_DISPLAY_NAME = "UNKNOWN_DISPLAY_NAME"
36-
3751
const UNTITLED_SHARD = "UNTITLED_SHARD"
3852
const UNKNOWN_MAP = "UNKNOWN_MAP"
3953

40-
enum RequesterCode {
41-
OK = 0,
42-
CANCELLED,
43-
TERMINATED,
44-
CANT_CONNECT,
45-
CANT_RESOLVE,
46-
SSL_HANDSHAKE_ERROR,
47-
DISCONNECTED,
48-
CONNECTION_ERROR,
49-
UNKNOWN_STATUS_ERROR,
50-
FILE_ERROR,
51-
HTTP_RESPONSE_NOT_OK,
52-
NO_TOKEN,
53-
MALFORMED_RESPONSE_DATA,
54-
JSON_PARSE_ERROR,
55-
JSON_VALIDATE_ERROR,
56-
NO_RESPONSE_BODY,
57-
FAILED_TO_CONNECT,
58-
POLL_ERROR,
59-
}
60-
6154

6255
static func get_string_for_requester_code(p_requester_code: int) -> String:
6356
match p_requester_code:
@@ -108,41 +101,37 @@ static func get_full_requester_error_string(p_requester: Dictionary) -> String:
108101
p_requester["generic_code"]
109102
]
110103
)
111-
elif p_requester["requester_code"] == RequesterCode.HTTP_RESPONSE_NOT_OK:
104+
105+
if p_requester["requester_code"] == RequesterCode.HTTP_RESPONSE_NOT_OK:
112106
return (
113107
"%s (error code: %s)"
114108
% [
115109
get_string_for_requester_code(p_requester["requester_code"]),
116110
p_requester["response_code"]
117111
]
118112
)
119-
elif p_requester["requester_code"] == RequesterCode.POLL_ERROR:
113+
114+
if p_requester["requester_code"] == RequesterCode.POLL_ERROR:
120115
return (
121116
"%s (error code: %s)"
122117
% [
123118
get_string_for_requester_code(p_requester["requester_code"]),
124119
p_requester["generic_code"]
125120
]
126121
)
127-
else:
128-
return get_string_for_requester_code(p_requester["requester_code"])
122+
123+
return get_string_for_requester_code(p_requester["requester_code"])
129124

130125

131126
static func requester_result_is_ok(p_result) -> bool:
132-
if p_result["requester_code"] == RequesterCode.OK:
133-
return true
134-
else:
135-
return false
127+
return p_result["requester_code"] == RequesterCode.OK
136128

137129

138130
static func requester_result_has_response(p_result) -> bool:
139-
if (
131+
return (
140132
p_result["requester_code"] == RequesterCode.OK
141133
or p_result["requester_code"] == RequesterCode.HTTP_RESPONSE_NOT_OK
142-
):
143-
return true
144-
else:
145-
return false
134+
)
146135

147136

148137
static func populate_query(p_query_name: String, p_query_dictionary: Dictionary) -> Dictionary:
@@ -162,8 +151,7 @@ static func get_value_of_type(p_data: Dictionary, p_key: String, p_type: int, p_
162151
var value = p_data.get(p_key, p_default_value)
163152
if typeof(value) == p_type:
164153
return value
165-
else:
166-
return p_default_value
154+
return p_default_value
167155

168156

169157
static func process_user_privilege_ruleset(p_data) -> Dictionary:
@@ -236,34 +224,33 @@ static func process_session_json(p_input: Dictionary) -> Dictionary:
236224
"message": "Malformed response data!",
237225
}
238226

239-
else:
240-
var output = p_input.get("output")
241-
if output is Dictionary:
242-
var error = output.get("error")
243-
if error is Dictionary:
244-
var message = error.get("message")
245-
if message is String:
246-
return {
247-
"requester_code": p_input["requester_code"],
248-
"generic_code": p_input["generic_code"],
249-
"response_code": p_input["response_code"],
250-
"message": message
251-
}
227+
var output = p_input.get("output")
228+
if output is Dictionary:
229+
var error = output.get("error")
230+
if error is Dictionary:
231+
var message = error.get("message")
232+
if message is String:
233+
return {
234+
"requester_code": p_input["requester_code"],
235+
"generic_code": p_input["generic_code"],
236+
"response_code": p_input["response_code"],
237+
"message": message
238+
}
252239

253-
return {
254-
"requester_code": RequesterCode.MALFORMED_RESPONSE_DATA,
255-
"generic_code": p_input["generic_code"],
256-
"response_code": p_input["response_code"],
257-
"message": get_full_requester_error_string(p_input)
258-
}
259-
else:
260240
return {
261-
"requester_code": p_input["requester_code"],
241+
"requester_code": RequesterCode.MALFORMED_RESPONSE_DATA,
262242
"generic_code": p_input["generic_code"],
263243
"response_code": p_input["response_code"],
264244
"message": get_full_requester_error_string(p_input)
265245
}
266246

247+
return {
248+
"requester_code": p_input["requester_code"],
249+
"generic_code": p_input["generic_code"],
250+
"response_code": p_input["response_code"],
251+
"message": get_full_requester_error_string(p_input)
252+
}
253+
267254

268255
static func process_shards_json(p_input: Dictionary) -> Dictionary:
269256
var result_dict: Dictionary = {}

0 commit comments

Comments
 (0)