Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
public-apis
Commits
6bfe2841
"src/main/webapp/WEB-INF/git@ustchcs.com:gujinli1118/MCMS.git" did not exist on "09c59d7705cc18c3e91537a5a8d8fe4d157cc95d"
Unverified
Commit
6bfe2841
authored
Jan 16, 2022
by
Matheus Felipe
Browse files
Get categories content and check alphabetical order
parent
2501df6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/validate/format.py
View file @
6bfe2841
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
re
import
re
from
typing
import
List
,
Tuple
,
Dict
anchor
=
'###'
anchor
=
'###'
...
@@ -24,7 +25,53 @@ anchor_re = re.compile(anchor + '\s(.+)')
...
@@ -24,7 +25,53 @@ anchor_re = re.compile(anchor + '\s(.+)')
section_title_re
=
re
.
compile
(
'\*\s\[(.*)\]'
)
section_title_re
=
re
.
compile
(
'\*\s\[(.*)\]'
)
link_re
=
re
.
compile
(
'\[(.+)\]\((http.*)\)'
)
link_re
=
re
.
compile
(
'\[(.+)\]\((http.*)\)'
)
# Type aliases
APIList
=
List
[
str
]
Categories
=
Dict
[
str
,
APIList
]
CategoriesLineNumber
=
Dict
[
str
,
int
]
def
error_message
(
line_number
:
int
,
message
:
str
)
->
str
:
def
error_message
(
line_number
:
int
,
message
:
str
)
->
str
:
line
=
line_number
+
1
line
=
line_number
+
1
return
f
'(L
{
line
:
03
d
}
)
{
message
}
'
return
f
'(L
{
line
:
03
d
}
)
{
message
}
'
def
get_categories_content
(
contents
:
List
[
str
])
->
Tuple
[
Categories
,
CategoriesLineNumber
]:
categories
=
{}
category_line_num
=
{}
for
line_num
,
line_content
in
enumerate
(
contents
):
if
line_content
.
startswith
(
anchor
):
category
=
line_content
.
split
(
anchor
)[
1
].
strip
()
categories
[
category
]
=
[]
category_line_num
[
category
]
=
line_num
continue
if
not
line_content
.
startswith
(
'|'
)
or
line_content
.
startswith
(
'|---'
):
continue
raw_title
=
[
raw_content
.
strip
()
for
raw_content
in
line_content
.
split
(
'|'
)[
1
:
-
1
]
][
0
]
title_match
=
link_re
.
match
(
raw_title
)
if
title_match
:
title
=
title_match
.
group
(
1
).
upper
()
categories
[
category
].
append
(
title
)
return
(
categories
,
category_line_num
)
def
check_alphabetical_order
(
lines
:
List
[
str
])
->
None
:
categories
,
category_line_num
=
get_categories_content
(
contents
=
lines
)
for
category
,
api_list
in
categories
.
items
():
if
sorted
(
api_list
)
!=
api_list
:
message
=
error_message
(
category_line_num
[
category
],
f
'
{
category
}
category is not alphabetical order'
)
errors
.
append
(
message
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment