Skip to content

Commit

Permalink
feature: add rules for line linting and file names (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
thispath98 authored Dec 29, 2024
1 parent b628693 commit 9f04bbb
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] 커밋 컨벤션을 확인하셨나요?
- [ ] black formatter를 통한 line inting을 확인 하셨나요?
- **Tag**: Select the appropriate tag for this PR:
- [ ] `feature`
- [ ] `fix`
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/check-lint-names.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Check Line Linting and File Names

on:
pull_request:

jobs:
linelint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

# PR 라벨 확인
- name: Get PR labels
id: pr-labels
run: |
pr_number="${{ github.event.pull_request.number }}"
labels_json=$(gh pr view $pr_number --json labels -q '.labels[].name')
if [ -n "$labels_json" ]; then
echo "has_maintenance=$(echo $labels_json | grep -q 'maintenance' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
else
echo "has_maintenance=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ github.token }}

# 줄바꿈 체크
- name: Check for missing end line breaks
run: |
# 따옴표를 제거하고 파일 목록 가져오기
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr -d '"')
success=true
echo "변경된 파일 목록:"
echo "$files"
echo "## 줄바꿈 누락 파일" >> $GITHUB_STEP_SUMMARY
for file in $files; do
if [ -s "$file" ] && [ "$(tail -c 1 $file | wc -l)" -eq 0 ]; then
echo "발견된 줄바꿈 누락: $file"
echo "- $file" >> $GITHUB_STEP_SUMMARY
success=false
fi
done
if [ "$success" = false ]; then
echo -e "\n:warning: 파일 끝의 누락된 줄바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY
exit 1
fi
# 제어문자 체크
- name: Check for control characters in filenames
run: |
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr -d '"')
success=true
echo "## 제어문자가 포함된 파일명" >> $GITHUB_STEP_SUMMARY
for file in $files; do
# basename으로 파일명만 추출하고 따옴표 제거
filename=$(basename "$file" | tr -d '"')
# 백슬래시로 시작하는 제어문자들 체크 (\b, \n, \r, \t 등)
if printf '%q' "$filename" | grep -q '\\[bnrtfv]' || \
# 일반적인 제어문자들 체크 (0x00-0x1F, 0x7F)
echo -n "$filename" | LC_ALL=C grep -q '[[:cntrl:]]' || \
# 특수 제어문자들 체크
echo -n "$filename" | grep -q $'[\x00-\x1F\x7F]' || \
# 이스케이프 시퀀스 체크
[[ "$filename" =~ (\\[0-7]{1,3}|\\x[0-9a-fA-F]{1,2}) ]]; then
echo "- $file (제어문자 포함)" >> $GITHUB_STEP_SUMMARY
success=false
fi
done
if [ "$success" = false ]; then
echo -e "\n:warning: 파일명에서 제어문자를 제거해 주세요." >> $GITHUB_STEP_SUMMARY
exit 1
fi

0 comments on commit 9f04bbb

Please sign in to comment.