15
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

super-linterを試してみる

Last updated at Posted at 2020-06-25

最近発表されたGithubチームが開発しているsuperlinter

ちょっと記事だけでわかりにくかったので試してみました

TL;DR

  • Github Actionsで実行するよ
  • 実行したいlinterだけ選ぶこともできるよ
  • 設定ファイルをリポジトリに置けば、linterがそのルールで実行するよ

super linterとは

Githubチームが開発した、複数linterを実行してくれます:santa:

リポジトリはこちら↓
https://github.com/github/super-linter

方法

  1. Github Actions
  2. dockerのimageが用意されているので、そのイメージをプルしてローカルで試す

今回はGithub Actionsで試しました:santa:

実行するには

Github Actionsにファイルを置いてプッシュするだけ

テンプレを置いてくれてます↓

.github/workflows/linter.yml
###########################
###########################
## Linter GitHub Actions ##
###########################
###########################
name: Lint Code Base

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on:
  push:
    branches-ignore:
      - 'master'

###############
# Set the Job #
###############
jobs:
  build:
    # Name the Job
    name: Lint Code Base
    # Set the agent to run on
    runs-on: ubuntu-latest

    ##################
    # Load all steps #
    ##################
    steps:
      ##########################
      # Checkout the code base #
      ##########################
      - name: Checkout Code
        uses: actions/checkout@v2

      ################################
      # Run Linter against code base #
      ################################
      - name: Lint Code Base
        uses: docker://github/super-linter:v2.2.0
        env:
          VALIDATE_ALL_CODEBASE: false 
          VALIDATE_ANSIBLE: false

とりあえず実行させてみよう

基本的に、実行させる・させたくないは、環境変数で選択するようですね:santa:

今回実行させたファイルは下記です。

.github/workflows/linter.yml
name: Super Lint Code Base

# Documentation:
# https://github.com/github/super-linter

on:
  push:
    branches-ignore:
      - 'master'
      - 'production' #やる必要のないブランチがあれば追記しましょう

jobs:
  build:
    name: Lint Code Base
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v2

      - name: Lint Code Base
        uses: docker://github/super-linter:v2.2.0
        env:
          VALIDATE_ALL_CODEBASE: true

VALIDATE_ALL_CODEBASEの環境変数ですべてのファイルがlint対象にしました:santa:

VALIDATE_ALL_CODEBASE: true => 全ファイルがlint対象
VALIDATE_ALL_CODEBASE: false => 変更・新規作成ファイルのみがlint対象

すべてlintにかける必要なければ、falseにしましょう:santa:

すべて実行された結果、

スクリーンショット 2020-06-25 16.40.08.png

Typescript200個弱、mdファイルなど合わせて300個ぐらいで、38分かかってました:santa:

2回目以降は新規・変更対象のみ&linterを絞って実行してみると、19秒ぐらいで終わっていて、
そのブランチの変更したファイルだけが、linterにかけられてました:santa:

.github/workflows/linter.yml
~(省略)

      - name: Lint Code Base
        uses: docker://github/super-linter:v2.2.0
        env:
          VALIDATE_ALL_CODEBASE: false
          VALIDATE_YAML: true
          VALIDATE_JSON: true
          VALIDATE_MD: true
          VALIDATE_TYPESCRIPT_ES: true
          VALIDATE_DOCKER: true
          ACTIONS_RUNNER_DEBUG: true

カスタムしたいときはどうするか

各linterの設定ファイルを読み取って実行してくれているようです:santa:
eslintであれば、.eslintrc.ymlとか。
linterのconfigファイルのテンプレも置いてくれてます↓
https://github.com/github/super-linter/tree/master/TEMPLATES

感想

ただdockerで複数のlintを実行しているだけですが、これは自分にとって新しい視座を与えてくれました:santa:

今まで、なにかプロジェクトを始める時、ハンズオンを行う時、コードを書き始める前、prettierだったり、eslint、dockerをこしらえる時間もだんだんと多くなってきました:santa:

しかし、この考え方・実行方法にのっとれば、設定ファイルだけあれば、node_modulesなどローカルにインストールされていなくても、CIで実行できますね:santa:

linterやfomatterは即時性が大事ですが、最悪pushをされないようにするには
CIの実装だけでまずはいいはずで、Github Actionsのファイルとlintの設定ファイルあれば、スモールスタートを切れるような世界がくるのかな・・・
ローカルの開発はVSCodeのみで、開発を補助するコンテナが立ち上がり、Gitのライフサイクルにのっとって、コンテナが立ち上がり、実行されるとか。そして、今やlintにかけるべきものがたくさんあるってことなんですね〜:santa:

15
5
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
15
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?