diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2022-09-18 19:20:25 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-09-18 18:45:25 -0700 |
commit | 88c8ad840db6b88022dc93a30f14be2b31d20856 (patch) | |
tree | 3cb69c746f1fea402f842657e41ee0a347b06869 | |
parent | c4895b7d9513d18c81b69c1c1704ec470bd3d3aa (diff) | |
download | serenity-88c8ad840db6b88022dc93a30f14be2b31d20856.zip |
Meta: Rewrite pre-commit script check-emoji in python
This reduces the scripts execution time from 0.57 seconds to 0.01
seconds, while also making the check a bit tighter, leaving fewer
possible problems.
-rwxr-xr-x | Meta/check-emoji.py | 61 | ||||
-rwxr-xr-x | Meta/check-emoji.sh | 34 | ||||
-rwxr-xr-x | Meta/lint-ci.sh | 2 |
3 files changed, 62 insertions, 35 deletions
diff --git a/Meta/check-emoji.py b/Meta/check-emoji.py new file mode 100755 index 0000000000..e01bbbf38d --- /dev/null +++ b/Meta/check-emoji.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import os +import re +import sys + +RE_INVALID_CHAR = re.compile('[^A-FU0-9+_]') +RE_MISSING_UNDERSCORE = re.compile('[^_]U') +RE_MISSING_LETTER_U = re.compile('_(?!U)') +RE_MISSING_SIGN_PLUS = re.compile('U(?!\\+)') + + +def any_problems_here(): + found_invalid_filenames = False + for filename in os.listdir(): + if not filename.endswith('.png'): + print(f'Non-png file {filename} does not belong in the emoji directory') + found_invalid_filenames = True + break + filename = filename[:-len('.png')] + if RE_INVALID_CHAR.search(filename): + print(f'Filename {filename}.png contains invalid characters in its filename. Only uppercase letters' + ' A-F and U, numbers, +, and _ should be used.') + found_invalid_filenames = True + break + if 'U+0' in filename: + print(f'Filename {filename}.png contains codepoint(s) with leading zeros. Leading zeros should be' + ' removed from codepoint(s).') + found_invalid_filenames = True + break + if '+U' in filename: + print(f'Filename {filename}.png is incorrectly named. "_" should be used as a separator between' + ' codepoints, not "+".') + found_invalid_filenames = True + break + if RE_MISSING_UNDERSCORE.search(filename): + print(f'Filename {filename}.png is missing an underscore "_" between codepoints.') + found_invalid_filenames = True + break + if RE_MISSING_LETTER_U.search(filename): + print(f'Filename {filename}.png is either missing a "U" to indicate the start of a codepoint,' + ' or has a spurious underscore ("_").') + found_invalid_filenames = True + break + if RE_MISSING_SIGN_PLUS.search(filename): + print(f'Filename {filename}.png is either missing a "+" after a "U", or has a spurious "U".') + found_invalid_filenames = True + break + if 'U+FE0F' in filename: + print(f'Filename {filename}.png should not include any emoji presentation selectors. U+FE0F codepoints' + ' should be removed from the filename.') + found_invalid_filenames = True + break + + return found_invalid_filenames + + +if __name__ == '__main__': + os.chdir(os.path.dirname(__file__) + "/../Base/res/emoji/") + if any_problems_here(): + sys.exit(1) diff --git a/Meta/check-emoji.sh b/Meta/check-emoji.sh deleted file mode 100755 index 5d71c501c4..0000000000 --- a/Meta/check-emoji.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P) -cd "${script_path}/.." - -files=() -for file in Base/res/emoji/*.png; do - files+=("${file}") -done - -found_invalid_filenames=0 -for fn in "${files[@]}"; do - basename=$(basename "$fn" .png) - if [[ $basename =~ [^A-Z0-9+_] ]] ; then - echo "$fn contains invalid characters in its filename. Only uppercase letters, numbers, +, and _ should be used." - found_invalid_filenames=1 - fi - if [[ $basename == *U+0* ]] ; then - echo "$fn contains codepoint(s) with leading zeros. Leading zeros should be removed from codepoint(s)." - found_invalid_filenames=1 - fi - if [[ $basename == *+U* ]] ; then - echo "$fn is incorrectly named. _ should be used as a separator between codepoints, not +." - found_invalid_filenames=1 - fi - if [[ $basename == *_U+FE0F* ]] ; then - echo "$fn should not include any emoji presentation selectors. U+FE0F codepoints should be removed from the filename." - found_invalid_filenames=1 - fi -done - -exit $found_invalid_filenames diff --git a/Meta/lint-ci.sh b/Meta/lint-ci.sh index d4bd1de5a4..24be842c0f 100755 --- a/Meta/lint-ci.sh +++ b/Meta/lint-ci.sh @@ -22,7 +22,7 @@ set +e for cmd in \ Meta/check-ak-test-files.sh \ Meta/check-debug-flags.sh \ - Meta/check-emoji.sh \ + Meta/check-emoji.py \ Meta/check-markdown.sh \ Meta/check-newlines-at-eof.py \ Meta/check-png-sizes.sh \ |