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
82231641
Unverified
Commit
82231641
authored
Jan 27, 2018
by
Dave Machado
Browse files
add checks for category minimums and anchor format
parent
f94ca2b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
build/validate_format.py
View file @
82231641
#!/usr/bin/env python3
import
json
import
re
import
string
import
sys
anchor
=
'###'
min_entries_per_section
=
3
auth_keys
=
[
'apiKey'
,
'OAuth'
,
'X-Mashape-Key'
,
'No'
]
punctuation
=
[
'.'
,
'?'
,
'!'
]
https_keys
=
[
'Yes'
,
'No'
]
...
...
@@ -55,9 +57,23 @@ def check_format(filename):
# END Alphabetical Order
# START Check Entries
num_in_category
=
min_entries_per_section
+
1
anchor_re
=
re
.
compile
(
'###\s\S+'
)
for
line_num
,
line
in
enumerate
(
lines
):
# check each section for the minimum number of entries
if
line
.
startswith
(
anchor
):
if
not
anchor_re
.
match
(
line
):
add_error
(
line_num
,
"section header is not formatted correctly"
)
if
num_in_category
<
min_entries_per_section
:
add_error
(
category_line
,
"{} section does not have the minimum {} entries (only has {})"
.
format
(
category
,
min_entries_per_section
,
num_in_category
))
category
=
line
.
split
(
' '
)[
1
]
category_line
=
line_num
num_in_category
=
0
continue
if
not
line
.
startswith
(
'|'
)
or
line
.
startswith
(
'|---'
):
continue
num_in_category
+=
1
segments
=
line
.
split
(
'|'
)[
1
:
-
1
]
# START Global
for
segment
in
segments
:
...
...
@@ -75,7 +91,7 @@ def check_format(filename):
# first character should be capitalized
char
=
segments
[
index_desc
][
0
]
if
char
.
upper
()
!=
char
:
add_error
(
line_num
,
"first char of
D
escription is not capitalized"
)
add_error
(
line_num
,
"first char
acter
of
d
escription is not capitalized"
)
# last character should not punctuation
char
=
segments
[
index_desc
][
-
1
]
if
char
in
punctuation
:
...
...
@@ -103,7 +119,7 @@ def check_format(filename):
# url should be wrapped in '[Go!]()' Markdown syntax
link
=
segments
[
index_link
]
if
not
link
.
startswith
(
'[Go!](http'
)
or
not
link
.
endswith
(
')'
):
add_error
(
line_num
,
'link
format
should be "[Go!](LINK)"'
)
add_error
(
line_num
,
'link
syntax
should be "[Go!](LINK)"'
)
# END Link
# END Check Entries
...
...
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