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
7f71a9cf
Commit
7f71a9cf
authored
Aug 18, 2017
by
davemachado
Browse files
Add alphabetical order check logic
parent
61c6cd19
Changes
1
Show whitespace changes
Inline
Side-by-side
build/validate_format.rb
View file @
7f71a9cf
...
...
@@ -25,10 +25,36 @@ def add_error(line_num, val_index, message)
when
INDEX_LINK
segment
=
"Link"
end
$errors
.
push
(
"(L%03d) %-14.14s
#{
message
}
"
%
[
line_num
,
segment
])
end
section
=
''
sections
=
[]
section_to_line_num
=
{}
section_to_entries
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
Array
.
new
}
File
.
foreach
(
filename
).
with_index
do
|
line
,
line_num
|
if
line
.
start_with?
(
'###'
)
section
=
line
.
sub
(
'###'
,
''
).
lstrip
.
chop
sections
.
push
(
section
)
section_to_line_num
[
section
]
=
line_num
+
1
end
# Skip non-markdown table lines and table schema lines
if
!
line
.
start_with?
(
'|'
)
||
line
.
eql?
(
"|---|---|---|---|---|
\n
"
)
next
end
# char to check is the first char in the first column
check_char
=
line
.
split
(
"|"
)[
1
].
strip
[
0
]
section_to_entries
[
section
].
push
(
check_char
)
end
sections
.
each
do
|
sect
|
if
section_to_entries
[
sect
]
!=
section_to_entries
[
sect
].
sort
add_error
(
section_to_line_num
[
sect
],
INDEX_TITLE
,
"
#{
sect
}
section is not in alphabetical order"
)
end
end
File
.
foreach
(
filename
).
with_index
do
|
line
,
line_num
|
line_num
+=
1
...
...
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