Skip to content

Commit

Permalink
Add GitHub Actions workflow for code style check
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed May 16, 2024
1 parent d8ea630 commit 198718d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{pl,pm}]
indent_style = space
indent_size = 2
40 changes: 40 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Check code

on:
pull_request:
paths:
- '**/*.pl'
- '**/*.pm'

jobs:
perl-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Perl
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.28'

- name: Install perltidy
run: cpanm Perl::Tidy

- name: Install reviewdog
run: wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b /usr/local/bin/ 2>&1

- name: Run perltidy
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
result=0
for file in $(git ls-files '*.pl' '*.pm'); do
check="$(perltidy -st "$file" | git diff --no-index -- "$file" - | reviewdog -f=diff -name="perltidy" -reporter=local -filter-mode=nofilter)"
if [ -n "$check" ]; then
echo -e "\033[1;31mError:\033[0m [perltidy] $file:"
echo "$check"
result=1
fi
done
exit $result
13 changes: 13 additions & 0 deletions .perltidyrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
-b
-bext=/
-i=2
--cuddled-blocks
--cuddled-paren-brace
--cuddled-break-option=2
-nsbl
--nospace-for-semicolon
Expand All @@ -10,6 +13,8 @@
--square-bracket-tightness=2
--block-brace-tightness=1
-novalign
--valign-side-comments
--valign-block-comments
--opening-token-right
--add-newlines
--delete-old-newlines
Expand All @@ -22,3 +27,11 @@
--comma-arrow-breakpoints=0
--keep-old-blank-lines=1
--keyword-group-blanks
--extended-continuation-indentation
--want-trailing-commas=m
--add-trailing-commas
--delete-trailing-commas
--delete-weld-interfering-commas
--one-line-block-nesting=0
--output-line-ending=unix
--add-terminal-newline
8 changes: 8 additions & 0 deletions perltidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

set -e

for file in $(find . -name '*.pl' -o -name '*.pm' | sort); do
echo "$file"
perltidy "$file"
done

0 comments on commit 198718d

Please sign in to comment.