概要
もう何回書いているか、書かれているかわからないeditorconfigの導入の話
ローカルだけでなく、GitHub Actionsでもチェックする
とりあえずの設定ファイル
プロジェクト直下に .editorconfig
ファイルを作成する
.editorconfig
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
VS Codeで設定をする
拡張機能のインストール
https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
これを入れるだけでOK
GitHub Actionsでチェックする
エディタによってはeditorconfigが効かない事もあるのでサーバ側でもチェックする
git diff --name-only だと削除されたファイルとかも出てくるようでうまくいかなかったので加工する
ローカルでnpm install eclint
しているのでpackage,json
には情報がある状態
.github/workflows/main.yaml
name: main
on:
pull_request:
types: [ opened, synchronize ]
jobs:
main:
runs-on: ubuntu-22.04
permissions:
contents: read
timeout-minutes: 5
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Fetch base branch
run: git fetch origin main
- uses: actions/setup-node@v3
with:
node-version: 14
cache: npm
- run: npm install
- name: eclint
run: git diff origin/main HEAD |grep '^+++'|awk '{print $2}'|sed "s|b/||"| xargs npx eclint check
参考