mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Update Ale.
This commit is contained in:
145
sources_non_forked/ale/test/script/block-padding-checker
Executable file
145
sources_non_forked/ale/test/script/block-padding-checker
Executable file
@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
This script checks for missing or forbidden blank lines before or after
|
||||
particular Vim commands. This script ensures that VimL scripts are padded
|
||||
correctly, so they are easier to read.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
INDENTATION_RE = re.compile(r'^ *')
|
||||
COMMENT_LINE_RE = re.compile(r'^ *"')
|
||||
COMMAND_RE = re.compile(r'^ *([a-zA-Z\\]+)')
|
||||
OPERATOR_END_RE = re.compile(r'(&&|\|\||\+|-|\*\| /)$')
|
||||
|
||||
START_BLOCKS = set(['if', 'for', 'while', 'try', 'function'])
|
||||
END_BLOCKS = set(['endif', 'endfor', 'endwhile', 'endtry', 'endfunction'])
|
||||
MIDDLE_BLOCKS = set(['else', 'elseif', 'catch', 'finally'])
|
||||
TERMINATORS = set(['return', 'throw'])
|
||||
|
||||
WHITESPACE_BEFORE_SET = START_BLOCKS | TERMINATORS
|
||||
WHITESPACE_FORBIDDEN_BEFORE_SET = END_BLOCKS | MIDDLE_BLOCKS
|
||||
WHITESPACE_AFTER_SET = END_BLOCKS
|
||||
WHITESPACE_FORBIDDEN_AFTER_SET = START_BLOCKS | MIDDLE_BLOCKS
|
||||
SAME_INDENTATION_SET = set(['\\'])
|
||||
|
||||
|
||||
def remove_comment_lines(line_iter):
|
||||
for line_number, line in enumerate(line_iter, 1):
|
||||
if not COMMENT_LINE_RE.match(line):
|
||||
yield (line_number, line)
|
||||
|
||||
|
||||
def check_lines(line_iter):
|
||||
previous_indentation_level = None
|
||||
previous_command = None
|
||||
previous_line_blank = False
|
||||
|
||||
for line_number, line in remove_comment_lines(line_iter):
|
||||
if len(line) == 0:
|
||||
# Check for commands where we shouldn't have blank lines after
|
||||
# them, like `else` or the start of blocks like `function`.
|
||||
if (
|
||||
previous_command is not None
|
||||
and previous_command in WHITESPACE_FORBIDDEN_AFTER_SET
|
||||
):
|
||||
yield (
|
||||
line_number,
|
||||
'Blank line forbidden after `%s`' % (previous_command,)
|
||||
)
|
||||
|
||||
previous_line_blank = True
|
||||
previous_command = None
|
||||
else:
|
||||
indentation_level = INDENTATION_RE.match(line).end()
|
||||
command_match = COMMAND_RE.match(line)
|
||||
|
||||
if command_match:
|
||||
command = command_match.group(1)
|
||||
|
||||
if (
|
||||
command in SAME_INDENTATION_SET
|
||||
and previous_indentation_level is not None
|
||||
and indentation_level != previous_indentation_level
|
||||
):
|
||||
yield (
|
||||
line_number,
|
||||
'Line continuation should match previous indentation'
|
||||
)
|
||||
|
||||
if (
|
||||
previous_indentation_level is not None
|
||||
and indentation_level != previous_indentation_level
|
||||
and abs(indentation_level - previous_indentation_level) != 4 # noqa
|
||||
):
|
||||
yield (
|
||||
line_number,
|
||||
'Indentation should be 4 spaces'
|
||||
)
|
||||
|
||||
# Check for commands requiring blank lines before them, if they
|
||||
# aren't at the start of a block.
|
||||
if (
|
||||
command in WHITESPACE_BEFORE_SET
|
||||
and previous_indentation_level is not None
|
||||
and indentation_level == previous_indentation_level
|
||||
and previous_line_blank is False
|
||||
):
|
||||
yield (
|
||||
line_number,
|
||||
'Blank line required before `%s`' % (command,)
|
||||
)
|
||||
|
||||
# Check for commands where we shouldn't have blank lines before
|
||||
# them, like `else` or the end of blocks like `endfunction`.
|
||||
if (
|
||||
command in WHITESPACE_FORBIDDEN_BEFORE_SET
|
||||
and previous_line_blank is True
|
||||
):
|
||||
yield (
|
||||
line_number - 1,
|
||||
'Blank line forbidden before `%s`' % (command,)
|
||||
)
|
||||
|
||||
# Check for commands requiring blank lines after them, if they
|
||||
# aren't at the end of a block.
|
||||
if (
|
||||
previous_command is not None
|
||||
and previous_command in WHITESPACE_AFTER_SET
|
||||
and previous_indentation_level is not None
|
||||
and indentation_level == previous_indentation_level
|
||||
and previous_line_blank is False
|
||||
):
|
||||
yield (
|
||||
line_number - 1,
|
||||
'Blank line required after `%s`' % (command,)
|
||||
)
|
||||
|
||||
previous_command = command
|
||||
previous_line_blank = False
|
||||
previous_indentation_level = indentation_level
|
||||
|
||||
if OPERATOR_END_RE.search(line):
|
||||
yield (
|
||||
line_number,
|
||||
'Put operators at the start of lines instead'
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
status = 0
|
||||
|
||||
for filename in sys.argv[1:]:
|
||||
with open(filename) as vim_file:
|
||||
line_iter = (line.rstrip() for line in vim_file)
|
||||
|
||||
for line_number, message in check_lines(line_iter):
|
||||
print('%s:%d %s' % (filename, line_number, message))
|
||||
status = 1
|
||||
|
||||
sys.exit(status)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
5
sources_non_forked/ale/test/script/check-duplicate-tags
Executable file
5
sources_non_forked/ale/test/script/check-duplicate-tags
Executable file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
grep --exclude=tags -roh '\*.*\*$' doc | sort | uniq -d
|
60
sources_non_forked/ale/test/script/check-supported-tools-tables
Executable file
60
sources_non_forked/ale/test/script/check-supported-tools-tables
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
# This script compares the table of supported tools in both supported-tools.md
|
||||
# (for GitHub) and doc/ale-supported-languages-and-tools.txt (for vim), so we
|
||||
# can complain if they don't match up.
|
||||
|
||||
doc_file="$(mktemp -t doc.XXXXXXXX)"
|
||||
doc_sorted_file="$(mktemp -t doc-sorted.XXXXXXXX)"
|
||||
readme_file="$(mktemp -t readme.XXXXXXXX)"
|
||||
|
||||
while read -r; do
|
||||
if [[ "$REPLY" =~ ^! ]]; then
|
||||
language="${REPLY/!/}"
|
||||
else
|
||||
echo "$language - $REPLY"
|
||||
fi
|
||||
done < <(
|
||||
grep '^\*\|^ *\*' doc/ale-supported-languages-and-tools.txt \
|
||||
| sed -e '1,2d' \
|
||||
| sed 's/^\* */!/' \
|
||||
| sed -E 's/^ *\* *|!!|\^|\(.*\)|`//g' \
|
||||
| sed 's/ *$//'
|
||||
) > "$doc_file"
|
||||
|
||||
while read -r; do
|
||||
if [[ "$REPLY" =~ ^! ]]; then
|
||||
language="${REPLY/!/}"
|
||||
else
|
||||
echo "$language - $REPLY"
|
||||
fi
|
||||
done < <(
|
||||
grep '^\*\|^ *\*' supported-tools.md \
|
||||
| sed 's/^\* */!/' \
|
||||
| sed -E 's/^ *\* *|:floppy_disk:|:warning:|\(.*\)|\[|\].*|-n flag//g' \
|
||||
| sed 's/ *$//'
|
||||
) > "$readme_file"
|
||||
|
||||
exit_code=0
|
||||
|
||||
# Sort the tools ignoring case, and complain when things are out of order.
|
||||
LC_ALL=en_US.UTF-8 sort -f -k1,2 "$doc_file" -o "$doc_sorted_file"
|
||||
|
||||
diff -U0 "$doc_sorted_file" "$doc_file" || exit_code=$?
|
||||
|
||||
if ((exit_code)); then
|
||||
echo
|
||||
echo "The supported tools list isn't sorted properly"
|
||||
echo
|
||||
fi
|
||||
|
||||
diff -U0 "$readme_file" "$doc_file" || exit_code=$?
|
||||
|
||||
rm "$doc_file"
|
||||
rm "$doc_sorted_file"
|
||||
rm "$readme_file"
|
||||
|
||||
exit "$exit_code"
|
11
sources_non_forked/ale/test/script/check-tag-alignment
Executable file
11
sources_non_forked/ale/test/script/check-tag-alignment
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
exit_code=0
|
||||
|
||||
# Documentation tags need to be aligned to the right margin, so look for
|
||||
# tags which aren't at the right margin.
|
||||
grep ' \*[^*]\+\*$' doc/ -r \
|
||||
| awk '{ sep = index($0, ":"); if (length(substr($0, sep + 1 )) < 79) { print } }' \
|
||||
| grep . && exit_code=1
|
||||
|
||||
exit $exit_code
|
22
sources_non_forked/ale/test/script/check-tag-references
Executable file
22
sources_non_forked/ale/test/script/check-tag-references
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
exit_code=0
|
||||
tag_regex='[gb]\?:\?\(ale\|ALE\)[a-zA-Z_\-]\+'
|
||||
|
||||
tags="$(mktemp -t tags.XXXXXXXX)"
|
||||
refs="$(mktemp -t refs.XXXXXXXX)"
|
||||
# Grep for tags and references, and complain if we find a reference without
|
||||
# a tag for the reference. Only our tags will be included.
|
||||
grep --exclude=tags -roh "\\*$tag_regex\\*" doc | sed 's/*//g' | sort -u > "$tags"
|
||||
grep --exclude=tags -roh "|$tag_regex|" doc | sed 's/|//g' | sort -u > "$refs"
|
||||
|
||||
exit_code=0
|
||||
|
||||
if ! [[ $(comm -23 $refs $tags | wc -l) -eq 0 ]]; then
|
||||
exit_code=1
|
||||
fi
|
||||
|
||||
rm "$tags"
|
||||
rm "$refs"
|
90
sources_non_forked/ale/test/script/check-toc
Executable file
90
sources_non_forked/ale/test/script/check-toc
Executable file
@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
# This script checks that the table of contents for the supported tools is
|
||||
# sorted, and that the table matches the files.
|
||||
|
||||
toc_section_start_line="$(
|
||||
grep -m1 -n '^7\..*\*ale-other-integration-options\*' doc/ale.txt \
|
||||
| sed 's/\([0-9]*\).*/\1/' \
|
||||
)"
|
||||
toc_start_offset="$( \
|
||||
tail -n +"$toc_section_start_line" doc/ale.txt \
|
||||
| grep -m1 -n '^ .*\.\.\.' \
|
||||
| sed 's/\([0-9]*\).*/\1/' \
|
||||
)"
|
||||
# shellcheck disable=SC2003
|
||||
toc_start_line="$(expr "$toc_section_start_line" + "$toc_start_offset" - 1)"
|
||||
toc_section_size="$( \
|
||||
tail -n +"$toc_start_line" doc/ale.txt \
|
||||
| grep -m1 -n '^===*$' \
|
||||
| sed 's/\([0-9]*\).*/\1/' \
|
||||
)"
|
||||
# shellcheck disable=SC2003
|
||||
toc_end_line="$(expr "$toc_start_line" + "$toc_section_size" - 4)"
|
||||
|
||||
toc_file="$(mktemp -t table-of-contents.XXXXXXXX)"
|
||||
heading_file="$(mktemp -t headings.XXXXXXXX)"
|
||||
tagged_toc_file="$(mktemp -t ale.txt.XXXXXXXX)"
|
||||
sorted_toc_file="$(mktemp -t sorted-ale.txt.XXXXXXXX)"
|
||||
|
||||
sed -n "$toc_start_line,$toc_end_line"p doc/ale.txt \
|
||||
| sed 's/^ \( *[^.][^.]*\)\.\.*|\(..*\)|/\1, \2/' \
|
||||
> "$toc_file"
|
||||
|
||||
# Get all of the doc files in a natural sorted order.
|
||||
doc_files="$(/usr/bin/env ls -1v doc | grep '^ale-' | sed 's/^/doc\//' | paste -sd ' ' -)"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
grep -h '\*ale-.*-options\|^[a-z].*\*ale-.*\*$' $doc_files \
|
||||
| sed 's/^/ /' \
|
||||
| sed 's/ALE Shell Integration/ALE sh Integration/' \
|
||||
| sed 's/ALE BibTeX Integration/ALE bib Integration/' \
|
||||
| sed 's/ ALE \(.*\) Integration/\1/' \
|
||||
| sed 's/ *\*\(..*\)\*$/, \1/' \
|
||||
| tr '[:upper:]' '[:lower:]' \
|
||||
| sed 's/objective-c/objc/' \
|
||||
| sed 's/c++/cpp/' \
|
||||
> "$heading_file"
|
||||
|
||||
exit_code=0
|
||||
in_section=0
|
||||
section_index=0
|
||||
|
||||
# Prefix numbers to table of contents entries so that sections aren't mixed up
|
||||
# with sub-sections when they are sorted.
|
||||
while read -r; do
|
||||
if [[ "$REPLY" =~ ^\ ]]; then
|
||||
if ! ((in_section)); then
|
||||
let section_index='section_index + 1'
|
||||
in_section=1
|
||||
fi
|
||||
else
|
||||
if ((in_section)); then
|
||||
let section_index='section_index + 1'
|
||||
in_section=0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$section_index $REPLY" >> "$tagged_toc_file"
|
||||
done < "$toc_file"
|
||||
|
||||
# Sort the sections and sub-sections and remove the tags.
|
||||
sort -sn "$tagged_toc_file" | sed 's/[0-9][0-9]* //' > "$sorted_toc_file"
|
||||
|
||||
echo 'Check for bad ToC sorting:'
|
||||
echo
|
||||
diff -U2 "$sorted_toc_file" "$toc_file" || exit_code=$?
|
||||
|
||||
echo 'Check for mismatched ToC and headings:'
|
||||
echo
|
||||
diff -U3 "$toc_file" "$heading_file" || exit_code=$?
|
||||
|
||||
rm "$toc_file"
|
||||
rm "$heading_file"
|
||||
rm "$tagged_toc_file"
|
||||
rm "$sorted_toc_file"
|
||||
|
||||
exit "$exit_code"
|
80
sources_non_forked/ale/test/script/custom-checks
Executable file
80
sources_non_forked/ale/test/script/custom-checks
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
exit_code=0
|
||||
docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$DOCKER_RUN_IMAGE")
|
||||
|
||||
echo '========================================'
|
||||
echo 'Running custom linting rules'
|
||||
echo '========================================'
|
||||
echo 'Custom warnings/errors follow:'
|
||||
echo
|
||||
|
||||
set -o pipefail
|
||||
docker run "${docker_flags[@]}" test/script/custom-linting-rules . || exit_code=$?
|
||||
set +o pipefail
|
||||
echo
|
||||
|
||||
echo '========================================'
|
||||
echo 'Checking for duplicate tags'
|
||||
echo '========================================'
|
||||
echo 'Duplicate tags follow:'
|
||||
echo
|
||||
|
||||
set -o pipefail
|
||||
docker run "${docker_flags[@]}" test/script/check-duplicate-tags . || exit_code=$?
|
||||
set +o pipefail
|
||||
echo
|
||||
|
||||
echo '========================================'
|
||||
echo 'Checking for invalid tag references'
|
||||
echo '========================================'
|
||||
echo 'Invalid tag references tags follow:'
|
||||
echo
|
||||
|
||||
set -o pipefail
|
||||
docker run "${docker_flags[@]}" test/script/check-tag-references || exit_code=$?
|
||||
set +o pipefail
|
||||
|
||||
echo '========================================'
|
||||
echo 'diff supported-tools.md and doc/ale-supported-languages-and-tools.txt tables'
|
||||
echo '========================================'
|
||||
echo 'Differences follow:'
|
||||
echo
|
||||
|
||||
set -o pipefail
|
||||
docker run "${docker_flags[@]}" test/script/check-supported-tools-tables || exit_code=$?
|
||||
set +o pipefail
|
||||
|
||||
echo '========================================'
|
||||
echo 'Look for badly aligned doc tags'
|
||||
echo '========================================'
|
||||
echo 'Badly aligned tags follow:'
|
||||
echo
|
||||
|
||||
set -o pipefail
|
||||
docker run "${docker_flags[@]}" test/script/check-tag-alignment || exit_code=$?
|
||||
set +o pipefail
|
||||
|
||||
echo '========================================'
|
||||
echo 'Look for table of contents issues'
|
||||
echo '========================================'
|
||||
echo
|
||||
|
||||
set -o pipefail
|
||||
docker run "${docker_flags[@]}" test/script/check-toc || exit_code=$?
|
||||
set +o pipefail
|
||||
|
||||
echo '========================================'
|
||||
echo 'Check Python code'
|
||||
echo '========================================'
|
||||
echo
|
||||
|
||||
docker run --rm -v "$PWD:/testplugin" "$DOCKER_RUN_IMAGE" \
|
||||
python -W ignore -m unittest discover /testplugin/test/python \
|
||||
|| exit_code=$?
|
||||
echo
|
||||
|
||||
exit $exit_code
|
166
sources_non_forked/ale/test/script/custom-linting-rules
Executable file
166
sources_non_forked/ale/test/script/custom-linting-rules
Executable file
@ -0,0 +1,166 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
# This Bash script implements custom sanity checks for scripts beyond what
|
||||
# Vint covers, which are easy to check with regex.
|
||||
|
||||
# A flag for automatically fixing some errors.
|
||||
FIX_ERRORS=0
|
||||
RETURN_CODE=0
|
||||
|
||||
function print_help() {
|
||||
echo "Usage: test/script/custom-linting-rules [--fix] [DIRECTORY]" 1>&2
|
||||
echo 1>&2
|
||||
echo " -h, --help Print this help text" 1>&2
|
||||
echo " --fix Automatically fix some errors" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [ $# -ne 0 ]; do
|
||||
case $1 in
|
||||
-h) ;& --help)
|
||||
print_help
|
||||
;;
|
||||
--fix)
|
||||
FIX_ERRORS=1
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-?*)
|
||||
echo "Invalid argument: $1" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $# -eq 0 ] || [ -z "$1" ]; then
|
||||
print_help
|
||||
fi
|
||||
|
||||
shopt -s globstar
|
||||
|
||||
directories=("$@")
|
||||
|
||||
check_errors() {
|
||||
regex="$1"
|
||||
message="$2"
|
||||
include_arg=''
|
||||
exclude_arg=''
|
||||
|
||||
if [ $# -gt 2 ]; then
|
||||
include_arg="--include $3"
|
||||
fi
|
||||
|
||||
if [ $# -gt 3 ]; then
|
||||
shift
|
||||
shift
|
||||
shift
|
||||
|
||||
while (( "$#" )); do
|
||||
exclude_arg="$exclude_arg --exclude $1"
|
||||
shift
|
||||
done
|
||||
fi
|
||||
|
||||
for directory in "${directories[@]}"; do
|
||||
# shellcheck disable=SC2086
|
||||
while read -r; do
|
||||
line=$(cut -d ":" -f2 <<< "$REPLY")
|
||||
|
||||
if ((line > 1)); then
|
||||
line=$((line - 1))
|
||||
file=$(cut -d ":" -f1 <<< "$REPLY")
|
||||
|
||||
if sed -n "${line},${line}p" $file | grep -q '^ *" *no-custom-checks$'; then
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
RETURN_CODE=1
|
||||
echo "$REPLY $message"
|
||||
done < <(grep -H -n "$regex" $include_arg $exclude_arg "$directory"/**/*.vim \
|
||||
| grep -v 'no-custom-checks' \
|
||||
| grep -o '^[^:]\+:[0-9]\+' \
|
||||
| sed 's:^\./::')
|
||||
done
|
||||
}
|
||||
|
||||
if (( FIX_ERRORS )); then
|
||||
for directory in "${directories[@]}"; do
|
||||
sed -i "s/^\(function.*)\) *$/\1 abort/" "$directory"/**/*.vim
|
||||
sed -i "s/shellescape(/ale#Escape(/" "$directory"/**/*.vim
|
||||
sed -i 's/==#/is#/g' "$directory"/**/*.vim
|
||||
sed -i 's/==?/is?/g' "$directory"/**/*.vim
|
||||
sed -i 's/!=#/isnot#/g' "$directory"/**/*.vim
|
||||
sed -i 's/!=?/isnot?/g' "$directory"/**/*.vim
|
||||
# Improving type checks.
|
||||
sed -i $'s/\\(==.\\?\\|is\\) type([\'"]\+)/is v:t_string/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(==.\?\|is\) type([0-9]\+)/is v:t_number/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(==.\?\|is\) type(\[\])/is v:t_list/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(==.\?\|is\) type({})/is v:t_dict/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(==.\?\|is\) type(function([^)]\+))/is v:t_func/g' "$directory"/**/*.vim
|
||||
sed -i $'s/\\(!=.\\?\\|isnot\\) type([\'"]\+)/isnot v:t_string/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(!=.\?\|isnot\) type([0-9]\+)/isnot v:t_number/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(!=.\?\|isnot\) type(\[\])/isnot v:t_list/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(!=.\?\|isnot\) type({})/isnot v:t_dict/g' "$directory"/**/*.vim
|
||||
sed -i 's/\(!=.\?\|isnot\) type(function([^)]\+))/isnot v:t_func/g' "$directory"/**/*.vim
|
||||
done
|
||||
fi
|
||||
|
||||
# The arguments are: regex, explanation, [filename_filter], [list, of, exclusions]
|
||||
check_errors \
|
||||
'^function.*) *$' \
|
||||
'Function without abort keyword (See :help except-compat)'
|
||||
check_errors '^function[^!]' 'function without !'
|
||||
check_errors ' \+$' 'Trailing whitespace'
|
||||
check_errors '^ * end\?i\? *$' 'Write endif, not en, end, or endi'
|
||||
check_errors '^ [^ ]' 'Use four spaces, not two spaces'
|
||||
check_errors $'\t' 'Use four spaces, not tabs'
|
||||
# This check should prevent people from using a particular inconsistent name.
|
||||
check_errors 'let g:ale_\w\+_\w\+_args =' 'Name your option g:ale_<filetype>_<lintername>_options instead'
|
||||
check_errors 'shellescape(' 'Use ale#Escape instead of shellescape'
|
||||
check_errors 'simplify(' 'Use ale#path#Simplify instead of simplify'
|
||||
check_errors 'tempname(' 'Use ale#util#Tempname instead of tempname'
|
||||
check_errors 'getcurpos(' "Use getpos('.') instead of getcurpos() if you don't need curswant, to avoid a bug that changes curswant"
|
||||
check_errors "expand(['\"]%" "Use expand('#' . a:buffer . '...') instead. You might get a filename for the wrong buffer."
|
||||
check_errors 'getcwd()' "Do not use getcwd(), as it could run from the wrong buffer. Use expand('#' . a:buffer . ':p:h') instead."
|
||||
check_errors '==#' "Use 'is#' instead of '==#'. 0 ==# 'foobar' is true"
|
||||
check_errors '==?' "Use 'is?' instead of '==?'. 0 ==? 'foobar' is true"
|
||||
check_errors '!=#' "Use 'isnot#' instead of '!=#'. 0 !=# 'foobar' is false"
|
||||
check_errors '!=?' "Use 'isnot?' instead of '!=?'. 0 !=? 'foobar' is false"
|
||||
check_errors '^ *:\?echo' "Stray echo line. Ignore with \" no-custom-checks if needed"
|
||||
check_errors '^ *:\?redir' 'User execute() instead of redir'
|
||||
# Exclusions for grandfathered-in exceptions
|
||||
exclusions="clojure/clj_kondo.vim elixir/elixir_ls.vim go/golangci_lint.vim swift/swiftformat.vim"
|
||||
# shellcheck disable=SC2086
|
||||
check_errors $'name.:.*\'[a-z_]*[^a-z_0-9][a-z_0-9]*\',$' 'Use snake_case names for linters' '*/ale_linters/*' $exclusions
|
||||
# Checks for improving type checks.
|
||||
check_errors $'\\(==.\\?\\|is\\) type([\'"]\+)' "Use 'is v:t_string' instead"
|
||||
check_errors '\(==.\?\|is\) type([0-9]\+)' "Use 'is v:t_number' instead"
|
||||
check_errors '\(==.\?\|is\) type(\[\])' "Use 'is v:t_list' instead"
|
||||
check_errors '\(==.\?\|is\) type({})' "Use 'is v:t_dict' instead"
|
||||
check_errors '\(==.\?\|is\) type(function([^)]\+))' "Use 'is v:t_func' instead"
|
||||
check_errors $'\\(!=.\\?\\|isnot\\) type([\'"]\+)' "Use 'isnot v:t_string' instead"
|
||||
check_errors '\(!=.\?\|isnot\) type([0-9]\+)' "Use 'isnot v:t_number' instead"
|
||||
check_errors '\(!=.\?\|isnot\) type(\[\])' "Use 'isnot v:t_list' instead"
|
||||
check_errors '\(!=.\?\|isnot\) type({})' "Use 'isnot v:t_dict' instead"
|
||||
check_errors '\(!=.\?\|isnot\) type(function([^)]\+))' "Use 'isnot v:t_func' instead"
|
||||
|
||||
# Run a Python script to find lines that require padding around them. For
|
||||
# users without Python installed, we'll skip these checks. GitHub Actions will
|
||||
# run the script.
|
||||
if command -v python > /dev/null; then
|
||||
if ! test/script/block-padding-checker "$directory"/**/*.vim; then
|
||||
RETURN_CODE=1
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $RETURN_CODE
|
42
sources_non_forked/ale/test/script/dumb_named_pipe_server.py
Normal file
42
sources_non_forked/ale/test/script/dumb_named_pipe_server.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""
|
||||
This Python script creates a named pipe server that does nothing but send its input
|
||||
back to the client that connects to it. Only one argument must be given, the path
|
||||
of a named pipe to bind to.
|
||||
"""
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit('You must specify a filepath')
|
||||
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
if os.path.exists(sys.argv[1]):
|
||||
os.remove(sys.argv[1])
|
||||
sock.bind(sys.argv[1])
|
||||
sock.listen(0)
|
||||
|
||||
pid = os.fork()
|
||||
|
||||
if pid:
|
||||
print(pid)
|
||||
sys.exit()
|
||||
|
||||
while True:
|
||||
connection = sock.accept()[0]
|
||||
connection.settimeout(5)
|
||||
|
||||
while True:
|
||||
try:
|
||||
connection.send(connection.recv(1024))
|
||||
except socket.timeout:
|
||||
break
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
33
sources_non_forked/ale/test/script/dumb_tcp_client.py
Normal file
33
sources_non_forked/ale/test/script/dumb_tcp_client.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""
|
||||
This is just a script for testing that the dumb TCP server actually works
|
||||
correctly, for verifying that problems with tests are in Vim. Pass the
|
||||
same port number given to the test server to check that it's working.
|
||||
"""
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
result = sock.connect_ex(('127.0.0.1', int(sys.argv[1])))
|
||||
|
||||
if result:
|
||||
sock.close()
|
||||
sys.exit("Couldn't connect to the socket!")
|
||||
|
||||
data_sent = 'x' * 1024
|
||||
|
||||
sock.send(data_sent)
|
||||
data_received = sock.recv(1024)
|
||||
|
||||
if data_sent != data_received:
|
||||
sock.close()
|
||||
sys.exit("Data sent didn't match data received.")
|
||||
|
||||
sock.close()
|
||||
|
||||
print("Everything was just fine.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
40
sources_non_forked/ale/test/script/dumb_tcp_server.py
Normal file
40
sources_non_forked/ale/test/script/dumb_tcp_server.py
Normal file
@ -0,0 +1,40 @@
|
||||
"""
|
||||
This Python script creates a TCP server that does nothing but send its input
|
||||
back to the client that connects to it. Only one argument must be given, a port
|
||||
to bind to.
|
||||
"""
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2 or not sys.argv[1].isdigit():
|
||||
sys.exit('You must specify a port number')
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(('127.0.0.1', int(sys.argv[1])))
|
||||
sock.listen(0)
|
||||
|
||||
pid = os.fork()
|
||||
|
||||
if pid:
|
||||
print(pid)
|
||||
sys.exit()
|
||||
|
||||
while True:
|
||||
connection = sock.accept()[0]
|
||||
connection.settimeout(5)
|
||||
|
||||
while True:
|
||||
try:
|
||||
connection.send(connection.recv(1024))
|
||||
except socket.timeout:
|
||||
break
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
167
sources_non_forked/ale/test/script/run-vader-tests
Executable file
167
sources_non_forked/ale/test/script/run-vader-tests
Executable file
@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$DOCKER_RUN_IMAGE")
|
||||
red='\033[0;31m'
|
||||
green='\033[0;32m'
|
||||
nc='\033[0m'
|
||||
verbose=0
|
||||
quiet=0
|
||||
|
||||
while [ $# -ne 0 ]; do
|
||||
case $1 in
|
||||
-v)
|
||||
verbose=1
|
||||
shift
|
||||
;;
|
||||
-q)
|
||||
quiet=1
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-?*)
|
||||
echo "Invalid argument: $1" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
vim="$1"
|
||||
tests="$2"
|
||||
|
||||
echo "$vim"
|
||||
|
||||
case $vim in
|
||||
neovim-v0.2*)
|
||||
headless=''
|
||||
;;
|
||||
# Neovim 0.6+ requires headless argument to load Vader tests.
|
||||
neovim*)
|
||||
headless='--headless'
|
||||
;;
|
||||
*)
|
||||
headless=''
|
||||
;;
|
||||
esac
|
||||
|
||||
# This file will be used to track if tests ran or not.
|
||||
# We can't use a variable, because we need to set a value in a sub-shell.
|
||||
run_file="$(mktemp -t tests_ran.XXXXXXXX)"
|
||||
|
||||
function filter-vader-output() {
|
||||
local hit_first_vader_line=0
|
||||
# When verbose mode is off, suppress output until Vader starts.
|
||||
local start_output="$verbose"
|
||||
local filtered_data=''
|
||||
|
||||
while read -r; do
|
||||
# Search for the first Vader output line.
|
||||
# We can try starting tests again if they don't start.
|
||||
if ((!hit_first_vader_line)); then
|
||||
if [[ "$REPLY" = *'Starting Vader:'* ]]; then
|
||||
hit_first_vader_line=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ((!start_output)); then
|
||||
if ((hit_first_vader_line)); then
|
||||
start_output=1
|
||||
else
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
if ((quiet)); then
|
||||
if [[ "$REPLY" = *'Starting Vader:'* ]]; then
|
||||
filtered_data="$REPLY"
|
||||
elif [[ "$REPLY" = *'Success/Total'* ]]; then
|
||||
success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)"
|
||||
total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)"
|
||||
|
||||
if [ "$success" -lt "$total" ]; then
|
||||
echo "$filtered_data"
|
||||
echo "$REPLY"
|
||||
fi
|
||||
|
||||
filtered_data=''
|
||||
else
|
||||
filtered_data="$filtered_data"$'\n'"$REPLY"
|
||||
fi
|
||||
else
|
||||
echo "$REPLY"
|
||||
fi
|
||||
done
|
||||
|
||||
# Note that we managed to get the Vader tests started if we did.
|
||||
if ((hit_first_vader_line)); then
|
||||
echo 1 > "$run_file"
|
||||
fi
|
||||
}
|
||||
|
||||
function color-vader-output() {
|
||||
while read -r; do
|
||||
if [[ "$REPLY" = *'[EXECUTE] (X)'* ]]; then
|
||||
echo -en "$red"
|
||||
elif [[ "$REPLY" = *'[EXECUTE]'* ]] || [[ "$REPLY" = *'[ GIVEN]'* ]]; then
|
||||
echo -en "$nc"
|
||||
fi
|
||||
|
||||
if [[ "$REPLY" = *'Success/Total'* ]]; then
|
||||
success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)"
|
||||
total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)"
|
||||
|
||||
if [ "$success" -lt "$total" ]; then
|
||||
echo -en "$red"
|
||||
else
|
||||
echo -en "$green"
|
||||
fi
|
||||
|
||||
echo "$REPLY"
|
||||
echo -en "$nc"
|
||||
else
|
||||
echo "$REPLY"
|
||||
fi
|
||||
done
|
||||
|
||||
echo -en "$nc"
|
||||
}
|
||||
|
||||
echo
|
||||
echo '========================================'
|
||||
echo "Running tests for $vim"
|
||||
echo '========================================'
|
||||
echo
|
||||
|
||||
tries=0
|
||||
|
||||
while [ "$tries" -lt 5 ]; do
|
||||
tries=$((tries + 1))
|
||||
|
||||
exit_code=0
|
||||
set -o pipefail
|
||||
docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${docker_flags[@]}" \
|
||||
"/vim-build/bin/$vim" -u test/vimrc ${headless} \
|
||||
"+Vader! $tests" 2>&1 | filter-vader-output | color-vader-output || exit_code=$?
|
||||
set +o pipefail
|
||||
|
||||
if [ -s "$run_file" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$tries" -gt 1 ]; then
|
||||
echo
|
||||
echo "Tried to run tests $tries times"
|
||||
fi
|
||||
|
||||
rm "$run_file"
|
||||
|
||||
exit "$exit_code"
|
20
sources_non_forked/ale/test/script/run-vint
Executable file
20
sources_non_forked/ale/test/script/run-vint
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
exit_code=0
|
||||
docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$DOCKER_RUN_IMAGE")
|
||||
|
||||
echo '========================================'
|
||||
echo 'Running Vint to lint our code'
|
||||
echo '========================================'
|
||||
echo 'Vint warnings/errors follow:'
|
||||
echo
|
||||
|
||||
set -o pipefail
|
||||
docker run -a stdout "${docker_flags[@]}" vint -s . || exit_code=$?
|
||||
set +o pipefail
|
||||
echo
|
||||
|
||||
exit $exit_code
|
Reference in New Issue
Block a user