LoginSignup
0
0

More than 1 year has passed since last update.

EditorConfigの設定とGitHub Actionsでのチェック

Last updated at Posted at 2023-01-10

概要

もう何回書いているか、書かれているかわからない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

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0