Skip to content

Commit 1feb8ee

Browse files
committed
定義された用語の意図しない使用方法を検出するスクリプトを追加 #1347
1 parent 4e4c416 commit 1feb8ee

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: defined word check
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Set up Python
10+
uses: actions/setup-python@v5
11+
with:
12+
python-version: '3.x'
13+
- name: Install dependencies
14+
run: |
15+
python -m pip install --upgrade pip
16+
pip install requests
17+
- uses: actions/checkout@v4
18+
- name: check
19+
run: python3 .github/workflows/script/defined_word_check.py
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# 定義された用語の意図しない使用を検出する
2+
3+
import glob
4+
import os
5+
import sys
6+
import re
7+
8+
DEFINED_WORD_LIST = [
9+
# 先頭はターゲット用語、それ以外はその用語の許可された使用方法
10+
["未定義", "未定義動作", "未定義の動作", "動作は未定義", "挙動は未定義", "振る舞いは未定義"],
11+
]
12+
13+
def check_defined_word(text: str, filename: str) -> bool:
14+
found_error: bool = False
15+
16+
for words in DEFINED_WORD_LIST:
17+
word = words[0]
18+
allow_list = words[1:]
19+
20+
match_list = [m.start() for m in re.finditer(word, text)]
21+
if len(match_list) == 0:
22+
continue
23+
24+
for i in match_list:
25+
ok_count = 0
26+
for allow_word in allow_list:
27+
index = allow_word.find(word)
28+
n = len(allow_word)
29+
30+
if i - index < 0:
31+
continue
32+
33+
j = i - index
34+
sliced = text[j:j+n]
35+
if sliced == allow_word:
36+
ok_count += 1
37+
38+
if ok_count == 0:
39+
start = text.rfind('\n', 0, i)
40+
if start < 0:
41+
start = 0
42+
else:
43+
start = start + 1
44+
45+
end = text.find('\n', i)
46+
if end < 0:
47+
end = start + 20
48+
49+
around_word = text[start:end]
50+
print("{}: the file includes unintended word use \"{}\". Around the word:\"{}\"".format(filename, word, around_word))
51+
found_error = True
52+
53+
return not found_error
54+
55+
if __name__ == '__main__':
56+
found_error = False
57+
for p in sorted(list(glob.glob("**/*.md", recursive=True))):
58+
if p.startswith("start_editing/"):
59+
continue
60+
61+
with open(p) as f:
62+
text = f.read()
63+
64+
if not check_defined_word(text, p):
65+
found_error = True
66+
67+
if found_error:
68+
sys.exit(1)

0 commit comments

Comments
 (0)